Summary of Driving a DC motor using PWM with AVR ATmega
This library updates a software PWM driver for Atmega8 microcontrollers to control up to four DC motors independently. It enables speed, direction, and progressive start/stop features using hardware timers at a 20kHz frequency to minimize noise. The code was developed in Eclipse with avr-gcc.
Parts used in the DC Motor PWM Control Project:
- Atmega8 microcontroller
- Hardware timer
- DC motor
- Eclipse development environment
- avr-gcc compiler
This library is an update of the software PWM driver you can find here:
http://davidegironi.blogspot.it/2013/03/controlling-dc-motor-speed-and_6.html
For DC motor information please look at the above link.
This update implements also progressive start / stop features using hardware timer.
The PWM frequency have to be selected in the way that the switch frequency is much higher than the dynamics of the motor.
To avoid noise from the motor, the choosen PWM frequency is 20Khz.
So, with this one, you can drive up to 4 motors independently controlling:
- speed
- direction
- slow start / stop
Code https://sourceforge.net/projects/davidegironi/files/avr-lib/avr_lib_dcmotorpwm_02.zip/download
- What features does this library update implement?
The update implements progressive start and stop features using a hardware timer. - How many motors can be driven independently?
You can drive up to four motors independently. - What parameters are selected for each motor?
The library allows independent control of speed, direction, and slow start or stop. - Why is the PWM frequency set to 20Khz?
The 20Khz frequency is chosen to avoid noise from the motor while ensuring the switch frequency is much higher than the motor dynamics. - Where are the setup parameters contained?
Setup parameters are contained in the dcmotorpwm.h file. - Which development environment was used to create this library?
This library was developed on Eclipse. - What compiler was used to build the code?
The code was built with avr-gcc. - What microcontroller clock speed was used during development?
The project was developed on an Atmega8 running at 8MHz.

