8. Motor Driver Truth Table

 input   Orangutan LV-168 output   Orangutan SV-xx8 output 
 PD5, PD3   PD6, PB3   M1A, M2A   M1B, M2B   motor effect   M1A, M2A   M1B, M2B   motor effect 
H
H
L
L
brake low
L
L
brake low
L
H
L
H
"forward"*
L
H
"forward"*
H
L
H
L
"reverse"*
H
L
"reverse"*
L
L
H
H
brake high
OFF (high-impedance)
coast

* Note that the concept of “forward” is arbitrary as simply flipping the motor leads results in rotation in the opposite direction.


Please note that we advise against using the fourth state in the above truth table (both motor inputs low). For the Orangutan LV-168, this state results in “brake high”, which is functionally equivalent to “brake low” but less safe (it’s easier to accidentally short power to ground while braking high). For the Orangutan SV-xx8, this state results in coasting; there is no danger involved in using this coast state, but alternating between drive and brake produces a more linear relationship between motor RPM and PWM duty cycle than does alternating between drive and coast. As such, we suggest achieving variable speed by PWMing between drive and brake when using the Orangutan SV-xx8.

Motor 1 is controlled by pins PD5 and PD6 (i.e. OC0B and OC0A), and motor 2 is controlled by PD3 and PB3 (i.e. OC2B and OC2A). These pins are connected to the ATmegaxx8’s four eight-bit hardware PWM outputs (PD5=OC0B, PD6=OC0A, PD3=OC2B, and PB3=OC2A), which allows you to achieve variable motor speeds through hardware timers rather than software. This frees the CPU to perform other tasks while motor speed is automatically maintained by the AVR timer hardware.

If you choose to write your own motor control code (instead of using the Pololu AVR library), the suggested procedure for using hardware PWM outputs to control the motors is as follows:

  1. Make the four motor control pins outputs and drive them high; this drives all four motor outputs low.
  2. Configure Timer0 and Timer2 to use a prescaler of 8, which results in a PWM frequency of 20 MHz/8/256 = 9.8 kHz, which is the upper limit for the Orangutan LV-168; you can configure the timers for a higher-frequency PWM (up to 80 kHz) if you are using the Orangutan SV-xx8. Set these timers for inverted PWM mode output on both OCxA and OCxB, meaning that these PWM pins are set on timer compare match and cleared on timer overflow. This results in negative PWM pulses with duty cycles determined by registers OCR0A, OCR0B, OCR2A, and OCR2B.
  3. You can command motor 1 to drive “forward” at a speed ranging from 0 – 255 by setting OCR0B = speed and holding fixed OCR0A = 0. You can command motor 1 to drive “reverse” at a speed ranging from 0 – 255 by setting OCR0A = speed and OCR0B = 0. During the period where the two input pins have opposite values, the motor drives at full speed. During the period where the two inputs have the same value (high), the motor brakes. Cycling between drive and brake and high frequency results in variable motor speed that changes as a function of PWM duty cycle. Analogous results can be obtained for motor 2 using OCR2A and OCR2B. (Note that the concept of “forward” is arbitrary as simply flipping the motor leads results in rotation in the opposite direction.)

Using these PWM settings, OCR0B = 255 is equivalent to holding PD5 low while OCR0A = 0 is equivalent to holding PD6 high. As you can see from the truth table above, in this state M1B connects to your battery’s positive terminal and M1A connects to ground. Decreasing OCR0B to something less than 255 decreases the percentage of time PD5 is low, causing M1B to alternate between VIN and GND (and hence causing motor 1 to alternate between drive and brake). Similarly, OCR2B = 255 is equivalent to holding PD3 low while OCR2A = 0 is equivalent to holding PB3 high. In this state, M2B connects to your battery’s positive terminal and M2A connects to ground.

Related Products

Orangutan SV-168 Robot Controller
Orangutan LV-168 Robot Controller
Orangutan SV-168 + USB Programmer Combo
Orangutan LV-168 + USB Programmer Combo
Orangutan SV-328 Robot Controller
Orangutan SV-328 + USB Programmer Combo
Orangutan SV-328 + USB Programmer Combo
Orangutan LV-168 + USB Programmer Combo
Log In
Pololu Robotics & Electronics
Shopping cart
(702) 262-6648
Same-day shipping, worldwide
Menu
Shop Blog Forum Support
My account Comments or questions? About Pololu Contact Ordering information Distributors