signal that we're expecting pinB to signal the transition to detent from free rotation check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edgeĮncoderPos - //decrement the encoder's position countīFlag = 0 //reset flags for the next turnĪFlag = 0 //reset flags for the next turn read all eight pin values then strip away all but pinA and pinB's values stop interrupts happening before we read pin values looking for a rising edge signal and executing the "PinB" Interrupt Service Routine (below) looking for a rising edge signal and executing the "PinA" Interrupt Service Routine (below) set pinA as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases) stores the last encoder position value so we can compare to the current reading and see if it has changed (so we know when to print to the serial monitor) Change to int or uin16_t instead of byte if you want to record a larger range than 0-255 this variable stores our current value of encoder position. let us know when we're expecting a rising edge on pinB to signal that the encoder has arrived at a detent (opposite direction to when aFlag is set) let us know when we're expecting a rising edge on pinA to signal that the encoder has arrived at a detent Our second hardware interrupt pin is digital pin 3 Our first hardware interrupt pin is digital pin 2 Here is part of my code with one of the interrupts. Do I have my ports wrong? I've tried reading up on this and I'm not fully understanding the Bxxxxxxxx part. I think on the Mega they are PORTH3 and PORTH4 respectively. I found code for a Uno, so the port call for pins 2 and 3 are different. I am trying to use port manipulation in interrupts to read a rotary encoder.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |