Monday, February 2, 2015

Driving a DC motor using PWM with AVR ATmega



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
Setup parameters are contained in dcmotorpwm.h

This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 8MHz.

Code

Notes
  • read risk disclaimer
  • excuse my bad english

6 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. I am not able to download the code.could you please check with the problem.

    ReplyDelete
    Replies
    1. Hello, you can find the code file here: https://expirebox.com/download/307d8406b9e1f3d20e17f157857630c6.html link expires in 2 days.

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hi. Davide...does this code work with AVR ATmega 168P? which MCU have you used here?

    ReplyDelete
    Replies
    1. Hello, you have to change a couple of things related to the TIMER register in order to make this works on ATmega168, but it works. This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 8MHz.

      Delete