many common H-bridges — simply has the more traditional
two logic inputs. Driving one of the inputs high and the
other low causes the motor to spin in one direction.
Reversing the logic causes the motor to spin in the other
direction. Varying motor speed requires chopping the inputs
with a pulse width modulation (PWM) scheme. As such, it
takes a little more work to control this type of H-bridge.
The approach I’ve taken here is to drive each of the
H-bridge’s logic inputs with separate PWM channels from
the microcontroller. This method entails applying a PWM
signal to one of the inputs while holding the other low (i.e.,
0% duty cycle PWM signal). Normally, this would be a bit
expensive in terms of microcontroller hardware resources
since it requires using two PWM channels to control each
motor. However, we can afford to be a bit more liberal in
how we deploy the PWM capabilities of our ATtiny2313
since we’re using it as a dedicated motor controller.
Figure 1 shows a high-level system diagram with the
motor controller represented by the components inside
the red rectangle.
An alternative to the above scheme would be to insert
additional logic gates between the ATtiny2313 and the
H-bridges to effectively decode the H-bridge logic inputs
into speed and direction. This approach would provide the
ability to control up to four motors (since the ATtiny2313
has four PWM channels). However, the requirement for an
extra logic gate translates into a penalty in board size and
routing complexity when designing the circuit board layout.
Figure 2 shows the complete schematic for the serial
motor controller. At the heart of this design is the
ATtiny2313 microcontroller. Although the ATtiny2313 is
capable of running at up to 20 MHz, I’ve chosen instead
to operate it at 14.7456 MHz. This is one of the “magic”
frequencies that enables the USART to operate with 0%
error rate — an important part of this project. The timer0
PWM outputs (OC0A and OC0B) from the ATtiny2313 are
used to control the H-bridge logic inputs for motor 1 while
the timer1 PWM outputs (OC1A and OC1B) are used to
control the H-bridge logic inputs for motor 2; 100 kΩ
pull-down resistors are attached to the PWM lines to put
the H-bridges into stop mode when the PWM isn’t active.
FIGURE 2. Schematic layout for the serial motor driver.
SERVO 10.2009 55