BlazK Posted July 5, 2023 Report Posted July 5, 2023 Hello to everyone, I am trying to get the encoder input working properly, but after some banging with the head to the table i think i found something strange. First let me describe what i want to do and what hardware i have... V430-J-TA24 Quadrature encoder on HSC inputs I0 and I1 (A and B tracks od encoder) Measuring of the speed in both directions Pulse frequency is quite low as the encoder resolution is poor (existing encoder on the machine), so the function to measure frequency in the HW config is not OK, as it is only accurate to 1Hz i am testing on bench with the function generator instead of encoder, so i can observe nice and even counts I had high hopes for the Freq <- HSC function (Frequency measurement based on HSC), but it does not work into negative counting. In positive direction everything is OK, but in reverse it gives out status 16. I have now noticed that the HSC counter acts a bit strange. In the positive direction it resets it selfs when it is above the "Counter target value". (reset of counter = when "counter value" > "target value") In the negative direction it resets when it is equal to the "Counter target value". (reset of counter = when "counter value" = "target value") I made a simple program so you can see what i mean. In the middle i change the direction of encoder. A and B are encoder tracks. I also tried a completelly new, blank project and i can replicate the problem with manual changing of the HSC preset value while reversing the encoder signal. If anyone will try this, keep in mind that the HSC target value is taken into account only after the "enable reload" bit is reset and set again. My guess is that the "Freq <- HSC" function does not work correct because of this problem. In the negative direction the function gives out a negative value for the HSC preset on the output "I" (HSC Freq. Measurement: function’s Reload Value), but that value is never reached, because the HSC resets itself one value before that. Did anyone else had such problems and what was the solution? V430_testHSC_1.vlp
MVP 2023 kratmel Posted July 5, 2023 MVP 2023 Report Posted July 5, 2023 As far as I know, for the x2 encoder, hardware frequency will be twice as high. For encoder x4 is four times higher. I measured the speed of the wheel with an encoder and checked the results by measuring the resulting meters of material per minute. Then in the program I divided the measurements by 4 (encoder x4). Maybe I'm wrong, please correct me if someone has a different experience. Regarding signal frequency measurements, there are principles: - count the number of exact time pulses placed between encoder pulses (use interrupts) - the disadvantage is that it is difficult to determine the zero frequency for slow processes. - count encoder pulses over a period of time for fast processes. When building a program to analyze the speed of a conveyor, I had to use both methods and switch between the calculation results when the speed changes a lot.
BlazK Posted July 5, 2023 Author Report Posted July 5, 2023 39 minutes ago, kratmel said: As far as I know, for the x2 encoder, hardware frequency will be twice as high. For encoder x4 is four times higher. Yes, i know that, on x2 encoder setting, the HSC counts on: rising edge of A falling edge of A On x4 setting it counts on: rising edge of A rising edge of B falling edge of A falling edge of B What bothers me, is that the HSC acts differently when counting positive vs. when counting negative. I figured that out after almost two days of trying to get that frequency measurement function to work. That function seems to have everything that i need. It has dynamic HSC preset to adopt for low and high frequencies, status output...
MVP 2023 kratmel Posted July 5, 2023 MVP 2023 Report Posted July 5, 2023 Then I have a question. Why do you need a quadrature encoder if you only need speed in two directions? Use a simple HSC counter. It does not take into account the direction. And hardware frequency meter will probably count correctly. If you need position and speed, then it is better to take a controller with three encoder inputs and use one of them for the encoder and the second one in parallel for speed measurement.
BlazK Posted July 6, 2023 Author Report Posted July 6, 2023 I need speed and direction. Speed of the line in m/min, but i need to detect when the material reverses. Also wanted to use x4 encoder, so i get more pulses out per rotation, because as i said that encoder has a poor resolution and i can see some incoming problems at low speeds and start ups
MVP 2023 kratmel Posted July 6, 2023 MVP 2023 Report Posted July 6, 2023 About direction You can use my code idea for try to evaluate Stop, Up, Down direction state via encoder readout. Please note - i use this code for positive numbers (not reloaded DW used) but maybe with reload point some experiment needed.
BlazK Posted July 6, 2023 Author Report Posted July 6, 2023 Yes, this is OK for determing the direction. But seems that i will have to do the speed measurement manually. Probably the best is to do it in the interrupt routine: " _Interrupt HSC 0,1", which is triggered when the HSC (reload) is reloaded (when the "reload event" bit is triggered). In the meantime i made a timing diagram to show you, where is the main problem in the HSC behaviour (.pdf attachment) V430_HSC_encoderX2_timingdiagram.pdf
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now