N04 page 1 of 11 Rotary Encoders Incremental optical encoders Arduino +5V D + 1K Arduino digital input external GND + external +5V E 5K Arduino GND uni-directional single track encoder count pulses to measure distance count pulses per time (or time per pulse) to measure speed cannot ascertain direction of rotation = photo pickup =0 =1 Q t N04 page 2 of 11 bi-directional incremental encoders require quadrature and an up/down counter quadrature - determine direction of rotation with two pickups can use 4X extended counting CCW A B A leads B A A D B B Q CLK CCW / CW positive edge D flip-flop (Q captures value of A when positive edge appears on B) CW B leads A A B single track - two pickups offset by ¼, ¾, 1 ¼ … pitch A B A B incremental encoders often have a home mark must start counting from an internal or external home position to get absolute position can be a problem if power goes down N04 Incremental magnetic encoder using Hall effect sensor page 3 of 11 N04 page 4 of 11 Absolute optical encoder 8 bit absolute encoder requires 8 pickups that are precisely aligned on radial line Gray code pattern Binary pattern N04 page 5 of 11 Stepping Motors A B D C Wave Drive Sequence (full steps) Step A B C D 1 ON 2 ON 3 ON 4 ON 5 ON Two-Phase Drive Sequence (full steps) Step A B C D 1 ON ON 2 ON ON 3 ON ON 4 ON ON 5 ON ON Half-Step Drive Sequence (half steps) Step A B C D 1 ON 2 ON ON 3 ON 4 ON ON 5 ON 6 ON ON 7 ON 8 ON ON 9 ON (Allegro Microsystems UCN5804 spec sheet) N04 ULN2803A 1C 18 1 1B Arduino digital outputs Arduino GND 2 2B 2C 3 3B 3C 17 4 4B 16 6 4C 15 5 5B 5C 14 6 6B 6C 13 7 7B 7C 12 8 8B 8C 11 COM 10 9 GND motor coils A C B D external power +5VDC external power GND 6 wire stepper page 6 of 11 5 wire stepper 4 wire stepper N04 page 7 of 11 Permanent Magnet Direct Current (PMDC) Motors output speed nominally proportional to input DC voltage if motored, can be used to generate voltage nominally proportional to driven speed not all motors are neutrally timed + has both internal resistance AND inductance actual theory VIN VIN M BJT collector driven load Unidirectional motor driver linear mode - speed proportional to VIN switched mode - full off, full on pulse width modulation (PWM) VIN speed nominally proportional to duty cycle VS VS M M VIN B ON time OFF 20% duty cycle provides about 20% speed ON time 70% duty cycle provides about 70% speed D C RIN cannot provide reverse rotation OFF FET drain driven load E G S N04 page 8 of 11 Push-pull bidirectional driver +15V usually used in linear mode NPN requires bipolar VIN C B requires bipolar supply need same hFE for NPN and PNP crossover distortion E VIN E RIN B PNP C -15V N04 page 9 of 11 H-bridge bidirectional motor driver unipolar control and supply voltages never A and C never B and D Battery + Battery + A Battery + B DC motor C Battery - Battery + A D B DC motor C Battery - Battery - H-bridge CW rotation D Battery - H-bridge CCW rotation H-bridges must drive high-side base/gate voltages A and B higher than VM R M i M can provide battery charging during regenerative braking Battery + Battery + A Battery + B Base A Battery + A B Base B Gate A DC motor C D Base C Gate B DC motor C D Base D Gate C Battery - Battery - NPN BJT H-bridge Gate D Battery - Battery - N-channel FET H-bridge N04 page 10 of 11 totem-pole H-bridge uses NPN and PNP (or N-channel and P-channel) VA 0V 0V > VM > VM Battery + VA VB 0V > VM 0V > VM i 0 0 → 0 Battery + Battery + VA VB NPN NPN DC motor NPN DC motor VB PNP PNP Battery - Battery - PNP Battery - totem-pole BJT H-bridge SSR H-bridge precludes the need for base/gate high-side bias drivers Battery + Battery + A B Input A Input B C DC motor D Input C Input D Battery - Battery - SSR (solid state relay) H-bridge N04 page 11 of 11 L293D dual H-bridge VCC1 (pin 16) is logic supply voltage = +5V VCC2 (pin 8) is motor supply voltage = +4.5 V to +36 V driver inputs (pins 2, 7, 10 and 15) are TTL compatible ENABLE inputs (pins 1 and 9) are TTL compatible driver outputs (pins 3, 6, 11 and 14) have same STATE (not same voltage) as inputs drivers are capable of 1 A fly-back diodes are included internally in L293D