Answered step by step
Verified Expert Solution
Question
1 Approved Answer
write the code below please, same Structure and same steps please C It should be noted that inputs, especially those driven by devices, can change
write the code below please, same Structure and same steps please C
It should be noted that inputs, especially those driven by devices, can change very quickly and therefore need to be serviced quickly. Microprocessor systems have developed hardware known as interrupts for handling such inputs. From our standpoint an interrupt is actually a function that runs anytime an input or signal changes or is in a given state. The application that we will be employing interrupts for is the input from the knob of our encoder. A shaft encoder uses two signals, also known as channels, to indicate the motion of a shaft as well as its direction. The signals from an encoder are shown in Figure 6-1. In this graph it can be seen that only one of the signals changes at a time. Also when moving in a ClockWise (CW) or CounterClockWise (CCW) direction, the order in which the signals change is different. Note we will arbitrarily think of CW as the positive direction and CCW as the negative direction. CW Input B Change Input A Change Figure 6-1. Encoder Signal with Transitions Marked. The encoder signals A and B are connected to pins 2 and 3 of the Arduino Nano, respectively. Pins 2 and 3 were chosen since they are attached to interrupts 0 and 1 respectively. In this way a function known as an Interrupt Service Routine (ISR) can be established that will be run cach time one of the signals changes. The question is, What should the routine do in order to keep track of the motion of the shaft? Note that if we move CW and examine the transition events only on channel A, channel A always transitions into the opposite value of channel B. However, if we move CCW channel A transitions into the same value as channel B. Examining the transitions of B, we see that the opposite is true. Thus once a transition occurs in one of the signals, an interrupt routine will run, and depending upon the state of the two inputs (immediately after the transition), it will increments or decrements a variable indicating the shafts positionStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started