Very simple PWM DC motor control

ajaymills@gmail.com asked about a simple way to control a DC motor using PWM from an ATMega32. The following is the simplest circuit and program I have tried:

SimplePWM.asm.txt Remove '.txt' to use. I use the following script to build under OS X 10.4:

#!/bin/tcsh
avra -W NoRegDef $1.asm \
	&& avrdude -p m32 -c stk500v1 -P /dev/tty.KeySerial1 -e -U flash:w:$1.hex < y.txt \
	&& rm *.hex *.obj *.cof

Here's the system in operation (motor spinning at lower right):

The ATMega32 is seated in an STK500 development board, which powers the motor as well. The motor is a cheap 3V DC hobby motor (about $3). Usually I prefer to use a separate circuit and power source for the motor, with the PWM signal going through an optoisolator. However, for this small demonstration, everything seemed to work OK. Pressing the buttons on the STK500 toggles the LEDS and sets the PWM duty cycle. I had to give it a value of at least 16 to start the motor. The CPU clock is at 3686400 Hz, and the PWM signal is at 112.5 Hz.

Give this a try and see if it works for you!

İSky Coyote 2008