In this illustration we will going to test and wire the rotary encoder. Rotary encoder can be counted in the positive direction and the reverse direction during the rotation of the output pulse frequency and the rotation is continuous. Compare to rotary potentiometer this device has a limited rotation. The rotary encoder has its own push button built-in into the device itself, with the press of the button the encoder can be reset to its initial state, that start counting from 0 (ZERO).
The incremental encoder is a displacement of the rotary pulse signal when it’s converted to series of digital rotating sensor. These pulse are used to control angular displacement. The angular displacement encoder conversion using photoelectric scanning principle. Reading the system of alternating light transmission window and the windows is not consisting of radial indexing plate rotating basis, when the infrared light source vertical irradiation light to the code disk image into the receiving.
At the surface the receiver is covered with diffraction grating, which has the same code disk window width. The receiver task is to feel the rotation of the disk creating a changes into the corresponding light electrical change and the low level signal up to a high level, along with the generation of square pulse, which must be processed by electric circuit. Reading the system typically employ a differential manner, and which the same but the phase is different of the two waveform by 180 degree compare to the signal in order to improve the stability of the output signal, reading should be formed on the basis to eliminate the interference.
The incremental encoders produce a series of pulses. These pulse are used to measure the rotation, position of the shaft, and velocity. There are two channel of rotary encoder output (A and B in US terminology). The encoder signals are offset from one another by ½ of a pulse. Sometimes this is also referred to a 90 degree phase separation. This term comes from discussing one entire encoder pulse cycle, from when the signal first rises up, to where it rises up again as 360 degrees. Then you can see that the distance of ½ of encoder pulse would be considered 90 degrees.
As you can see the illustration above there are two quadrature channel, and separated by 90 degrees, the user of the rotary encoder often wants to know the direction of rotation. Encoder manufacturers publish their specification for which signal comes first by specifying the direction of rotation.
The incremental encoders has two phase the square wave the phase difference between 90 degree, often referred as A and B channel. One of the channel is providing a speed related information at the same time by sequentially comparing two channel signals, the direction of rotation and the information obtained. There is also special signal called Z or ZERO channel, which gives the absolute zero rotary position, the signal shows a square wave with the center line of channel A square wave coincide. Incremental encoder accuracy depends on the mechanical electrical two factors, these factors are (RASTER INDEXING ERROR), (DISC ECCENTRICITY), (BEARING ECCENTRICITY), To know how much electrical equivalent of the mechanical angle of 360 degrees can be calculated with the following formula below.
A & B Commutation Signals
Encoder indexing error is the electrical angle of the unit of two successive pulse maximum offset. Error exist in encoding which is caused by the aforementioned factors. The maximum error will be ± 25 electrical degrees (declared in any condition), equivalent to the rated offset value ± 7%, as the phase 90 degree electrical of two channels and the maximum deviation ± 35 electrical degrees is equal to ± 10% deviation left Ratings Right.
Required Components
- Arduino Board
- Rotary Encoder Module Board / Rotary Encoder
- 1x Red Led
- 1x Green Led
- 1x Yellow Led
- 3x 220k Ohms Resistor
- Solder Less Bread Board
- Jumper / DuPont Wires
Wiring Diagram Pinout
Sketch Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
/* 14CORE - TEST CODE ROTARY ENCODER MODULE */ //***************************************************** int RedLed = 2; int YellowLed = 3; int GreenLed = 4; //***************************************************** int aPin = 6; int bPin = 7; int buttonPin = 5; int state = 0; int longPeriod = 5000; // Time at green or red int shortPeriod = 700; // Time period when changing int targetCount = shortPeriod; int count = 0; void setup () { pinMode (aPin, INPUT); pinMode (bPin, INPUT); pinMode (buttonPin, INPUT); pinMode (RedLed, OUTPUT); pinMode (YellowLed, OUTPUT); pinMode (GreenLed, OUTPUT); } void loop () { count++; if (digitalRead (buttonPin)) { setLights (HIGH, HIGH, HIGH); } else { int change = getEncoderTurn (); int newPeriod = longPeriod + (change * 1000); if (newPeriod >= 1000 && newPeriod <= 10000) { longPeriod = newPeriod; } if (count> targetCount) { setState (); count = 0; } } delay (1); } int getEncoderTurn () { // Return -1, 0, or +1 static int oldA = LOW; static int oldB = LOW; int result = 0; int newA = digitalRead (aPin); int newB = digitalRead (bPin); if (newA != oldA || newB != oldB) { //Something has changed if (oldA == LOW && newA == HIGH) { result = - (oldB * 2 - 1); } } oldA = newA; oldB = newB; return result; } int setState () { if (state == 0) { setLights (HIGH, LOW, LOW); targetCount = longPeriod; state = 1; } else if (state == 1) { setLights (HIGH, HIGH, LOW); targetCount = shortPeriod; state = 2; } else if (state == 2) { setLights (LOW, LOW, HIGH); targetCount = longPeriod; state = 3; } else if (state == 3) { setLights (LOW, HIGH, LOW); targetCount = shortPeriod; state = 0; } } void setLights (int red, int yellow, int green) { digitalWrite (RedLed, red); digitalWrite (YellowLed, yellow); digitalWrite (GreenLed, green); } |
i want to use a pwm motor controller to run a 2 volt motor, if i put 2 pots in line. one pot would rotate 100% the second would be set at 70% no matter what the motor will run at 70% if i turned the first pot 0 to 100% i want to be able to cut back on the out put voltage or set for what ever voltage i want and it would stay at lets say 11 volts or 11.2 volts until i moved the second pot to another possition.