Wednesday, March 6, 2013

Controlling DC Motor speed and direction with AVR Atmega

updated library here: http://davidegironi.blogspot.it/2015/02/driving-dc-motor-using-pwm-with-avr.html

A DC motor is a mechanically commutated electric motor powered from direct current (DC). The stator is stationary in space by definition and therefore so is its current. The current in the rotor is switched by the commutator to also be stationary in space. This is how the relative angle between the stator and rotor magnetic flux is maintained near 90 degrees, which generates the maximum torque.



Here you can find three libraries to control DC Motor using Atmega micro.

The first one (lib_dcmotor) allow you to synchronously control motor in direction.

The second one (lib_dcmotorpwm) implements a way to control motor direction and speed asynchronously, using timers, by hardware PWM capabilities of Atmega micro. The average value of voltage (and current) fed to the load is controlled by turning the switch between supply and load on and off at a fast pace. The longer the switch is on compared to the off periods, the higher the power supplied to the load is, and the more the motor spin.

The third one (lib_dcmotorpwmsoft) does exactly the things of the library above, but implements a software PWM, leaving free the hardware PWM resource for other device, or for micro that does not have PWM hardware embedded.

All libraries can control up to 2 motors, more motors can be controlled with the third one libraries using output port expander.




All libraries was developed on Eclipse, built with avr-gcc on Atmega8 @ 1MHz.


Code


Notes
  • read risk disclaimer
  • excuse my bad english