Rotary encoder software
The rotary encoder module, including 5 pins, is the most common rotating encoder. Some of the features of this module are: The ability of Rotate to infinity 20 pulse resolution 5V supply voltage. How to Use a Rotary Encoder? Rotary Encoder Module Pinout. Required Materials. Hardware Components.
Software Apps. Arduino IDE. Determining the Position of the Rotary Encoder Shaft. Since the PWM has some value between 0 to , we set the shaft position in this range in the code too. Then, upload the following code on your Arduino Board. The motor breaks by pushing the encoder key or setting the encoder in position 0. Rotary encoder has a circular plate with some holes and two channels A and B. By rotating the circular plate, when A and B channels pass the holes, a connection between that channel and a common base is established.
These interruptions cause a square wave in the output channel. By counting these pulses, we can find the amount of rotation. On the other hand, channels A and B have 90 degrees of the phase difference, so you can also find the rotation direction depending on which channel pulse is ahead. An encoder can be installed directly on the motor shaft or made as a module. The rotary encoder module, including 5 pins, is the most common rotating encoder. To use a rotary encoder, we should count the pulses of channels A and B.
To do this, we used Arduino UNO and performed three projects for positioning the encoder, controlling the LED light and controlling the speed and direction of the DC motor. For the device used here there are 20 detents. Unlike a potentiometer the rotary encoder has no end stops so you can use one to continually increase or decrease a parameter once decoded by the microcontroller and there is no need to set the control position back to a start point there is none.
They also often have a push button switch built into the shaft which is useful for menu selection etc. Since the outputs are digital signals you can process them using a microcontroller and use the result in any way you want i.
As you turn the control knob you can feel the each of the 'detent' position stops, so you know when you have turned the device by exactly one position. This provides fine grained physical feedback allowing exact parameter changing. This is very different to using a potentiometer to set the volume level etc.
This rather technical sounding encoding method is in fact very simple. It also falls out in the wash that the signals generated are grey coded which just means that no two signals edges are aligned i. Gray coding is useful for electro-mechanical devices to generate signals that are unambiguous. For example if the output was binary coded then at the point of transition due to small delays in signal paths you might decode a completely erroneous value i.
This could be a problem especially if only combinatorial logic is used as the decoder. Gray code stops that from happening although it does not stop switch bounce. The following diagram shows the inner workings of the rotary encoder. Each of the three connections 8A, 8B and 8C is formed of a spring arm that pushes down on the substrate. There are three signals, one connected to the metal substrate Ground and two others that move over the alternating substrate pattern.
So the outputs are shorted to ground as the device is rotated and then are left floating unconnected when the contact is in the substrate gap. Note how the spring arm contacts are physically offset by a quarter of the period defined by the physical substrate - contacts 8B and 8C in the diagram below - this is how the quadrature encoded outputs are generated. This is the type of device used in the demonstration on this page. At each detent position two quadrature signals are generated indicating a single position change and showing the direction of rotation.
This particular device has quite a high rotational life - k rotations see datasheet - but since there is physical contact, the device will eventually wear out.
In the Bourns catalogue other physical devices range from 15k to k maximum rotations. The PEC11Lhas a maximum RPM of 60RPM whereas optical encoders, in that catalogue, have a 10 million revolution life and can operate at rpm - these are the types you could use for measurements in high speed machinery but see magnetic encoder below which has an even higher life and of course a higher cost! For even higher rotational life, a magnetic encoder offers the best choice since there is no physical contact within the device the only part that will wear out is the shaft bearings.
These offer a rotational life of million revolutions! You might want to measure velocity to use as a parameter in your code e. This is a parameter adjustment that measures the rotation speed and if found to be constant periodically increases the parameter. This is very useful for devices that have a large range of control e. You really don't want to sit there turning the knob by 1Hz periods to get to 10MHz! However this ignores the fact that the signals bounce all over the place.
If you use the CLK signal as an interrupt you will get into deep trouble as the random bouncing of the input will trigger interrupts all the time and not at the time when you want to read the data signal so you will get incorrect data. There are polling methods to decode the grey coded signals using a state machine so that bouncing signals are ignored i. Students complete activities to build the interface circuit and use myRIO and LabVIEW to translate quadrature waveforms to rotational position and direction.
Through these activities, students follow steps to demonstrate correct operation of the rotary encoder, watch videos involving theory, and participate in a short activity after each video.
Download Lab Bookmark. Related Resources.
0コメント