PDA

View Full Version : Timed pulses on 2 pins



Danie Joubert
- 10th March 2004, 21:05
Hallo group
As a new comer to the PBP family I first like to say thanks to all for the tons of info available.
I have a problem in writing code to check two input pins for changing pulses. The pulses from a shaft arive at the two pins at varying speed and is are alway 90 degrees apart. I want to use the pulses to determine whether the shaft is turning forward or backword.
Is there anyone who has done something like this?
If so will you please be so kind in helping.
I have just cross-graded from the first edition of Pb to PBP, great exitment !!
Thanks group

Melanie
- 15th March 2004, 07:38
Let’s call our inputs SensorA and SensorB. SensorB is 90 degrees away from SensorA.

Rotating in one direction, SensorA pulses first, followed by SensorB 90 degrees later, then followed by SensorA again 270 degrees after that.

Rotating in the other direction, SensorA pulses, followed by SensorB 270 degrees later, then followed by SensorA again 90 degrees after that.

You will see from this that there are two distinct Timing periods, a short 90 degree period, and a long 270 degree period. Let’s call this TimeShort and TimeLong.

If SensorB pulse is followed by TimeLong, the we are rotating in one direction. If SensorB pulse is followed by TimeShort you are rotating in the other direction (you can just as easily use SensorA rather than SensorB here).

Simply start a Timer on one Pulse, save the value on the next pulse, restarting the count. After two Timed counts you can then determine the direction of rotation (and as a bonus, the timed counts themselves will give you the rotational speed). It is probably best to junk the first Pulse from start-up/power-on since you don't know where your shaft is at rest.

Melanie