I just did a little experimenting with the AVR, ATmega8-based Microrobot (MR) Cruiser. I wanted to get a better handle on motor control and unfortunately their sample programs have some flaws and their documentation is incomplete. Maybe this will help someone else out there.
The goal: accelerate the motors forward, then decelerate and stop. After that I wanted to reprogram to spin the robot counter-clockwise, then clockwise. Seems simple enough. Fortunately Microrobot provided some circuit diagrams so it's not too hard to figure out what needs to be done.
If you look at the diagram to the right, pin 14 of the AVR CPU represents bit 0 of PORT B (PB0) which corresponds to MOTOR_EN (Motor Enable). That's because it's wired to a set of NAND gates that control the motor driver.
One of the inputs to each of the NANDs is this motor enable bit, so turning it off (0) disables the motors. What does the code look like (in C, using WinAVR)? Well in MR's sample code they define some handy macros to enable/disable the motor (I've fixed their typo for ya):
What about direction & speed? As far as speed goes, the PB1/OC1A and PB2/OC1B pins (pins 15 and 16) are used to provide pulse width modulation (PWM) to the motors. But, details will have to wait... until I can decipher exactly how the PWM stuff works on AVR. It involves a combination of Output Compare Registers and Timer Control Registers to create the PWM waveform. More later...
Post a Comment
Note: Only a member of this blog may post a comment.