We noticed that when the motor was rotating clockwise, edge 1 came first and edge 2 was still present. While when the motor was rotating counterclockwise, edge 2 came first and when edge 1 appeared, edge 2 was no longer there. We used this information in our program to get a sense of the motion of the motor. We created a forever loop that detected these different edges. We first checked the state of the first sensor (detect the edge 1) and then checked the state of sensor 2. If the program detected sensor 2 then this meant that the motor was rotating clockwise and if the program didn't detect sensor 2, the motor was rotating counterclockwise. The oscilloscope was extremely helpful in distinguishing these two motions and helped us come up with a pretty clever program.
This is the program that we came up with:
We made the program so that if sensor 2 was detected (motor going clockwise), the count would go up and if sensor 2 was not detected (motor going counterclockwise), the count would go down.
No comments:
Post a Comment