Frequency counter using parallax P8X32A
Mindaugas
Posts: 15
in Propeller 1
Hello everyone,
I am trying to create a little project with spin. I have an encoder which two outputs A+ and B+ are connected to the propeller chip. A and B outputs produces a 360 pulses per each rotation and depending of the direction of rotation A+ will lead or lag to the B+. I want to be able to get the direction of the rotation and the speed of the rotation using parallax chip i mentioned in title. Max input frequency from the encoder will be around 12 kHz, difference between A+ and B+ is a quarter of the period.
To accomplish this i am trying to use internal counters ctra and ctrb. But i am really stuck on that. I am getting some date from the encoder, but it makes no sense. First i only getting pulses from the encoder when encoder wheel is moving, but i am keep getting values from phsa even though the encoder stopped. Plus if i do the single full rotation on the encoder i expect my value of phsa add up to 360. But the numbers i am getting are way different.
In the examples i found in forum seems that everyone is using gate time and getting the amount of pulses which happens during that time. Is it possible to measure the frequency with these counter without using this wait gate and if the frequency from the encoder isn't constant. Can you point out what i am doing wrong here, and maybe explain a bit how actually these counter works? I have read the parallax article about the counter.
This is my code example, for now i am just trying to read single encoder input and display value.
Thank you for help.
I am trying to create a little project with spin. I have an encoder which two outputs A+ and B+ are connected to the propeller chip. A and B outputs produces a 360 pulses per each rotation and depending of the direction of rotation A+ will lead or lag to the B+. I want to be able to get the direction of the rotation and the speed of the rotation using parallax chip i mentioned in title. Max input frequency from the encoder will be around 12 kHz, difference between A+ and B+ is a quarter of the period.
To accomplish this i am trying to use internal counters ctra and ctrb. But i am really stuck on that. I am getting some date from the encoder, but it makes no sense. First i only getting pulses from the encoder when encoder wheel is moving, but i am keep getting values from phsa even though the encoder stopped. Plus if i do the single full rotation on the encoder i expect my value of phsa add up to 360. But the numbers i am getting are way different.
In the examples i found in forum seems that everyone is using gate time and getting the amount of pulses which happens during that time. Is it possible to measure the frequency with these counter without using this wait gate and if the frequency from the encoder isn't constant. Can you point out what i am doing wrong here, and maybe explain a bit how actually these counter works? I have read the parallax article about the counter.
This is my code example, for now i am just trying to read single encoder input and display value.
Thank you for help.
Comments
transition is needed.
If I understand your question correctly, you are trying to read the speed and direction of a motor. There is an object in Obex by Kwabena W. Agyeman, called “Dual Quadrature Encoder Driver” that may satisfy your needs. Kwabena’s code was always excellent and at least could act as a guide for you in developing your own code.
Jim
See this work, of 2 Frequency counters
http://forums.parallax.com/discussion/123170/propbasic-reciprocal-frequency-counter-0-5hz-to-40mhz-40mhz-now
The reciprocal version, counts both Fi Cycles and time for Whole Fi Cycles, and then does Cycles/Time calculation.
I'd suggest connect that, and test your encoder outputs. The code could also form the basis for what you need to do.
You can derive frequency, by measuring period, but usually there is always some minimum frequency.
ie What do you need to read down to ? 10pps, 1pps, or 10 seconds per pulse ?
Measuring just a single period, also squeezes things at the upper end - you have 12kHz, so that's 83us to measure and calculate, but at those high speeds you do not need reading every 83us, so things can be easier using more periods, and voila, you now have a Reciprocal Counter (above), which nicely auto-scales for you.
Speed is covered above, direction is going to be tricky in Spin and 12kHz....
here is a Quad channel waveform for Up/Down To fully sense dirn, you respond to any pin change, and check new:old. At 12kHz, you have to do this in under ~20us
However, it may be enough to update direction when you take the speed (frequency reading) and there you just need to capture the other channel, on measured channel edge.
eg a falling b edge, has b=a for UP ( a=0 ) and b<>a for down. (a=1)
Can't find a datasheet for that device.
Many encoders have open-collector outputs and require pull-up resistors, others are differential and won't.
Find a PASM encoder object as mentioned above, it will handle direction and speed to as fast as most
encoders and generate.