PWM: motor speed control(AVR)

Pulse width modulation is a great method of controlling the amount of power delivered to a dc motor without dissipating any wasted power.this tutorial demonstrates signal control through atmega32 using timer0 in fast pwm mode.voltage applied(Vout) on  dc motor depends on duty cycle so by increasing(from 1 to 255) or dexreasing(255 to 1) duty cycle control over motor speed can be acheived.drived relation between Vout and duty cycle gives the followimg result.to have better understanding of code readers are advised first to go though AVR PWM tutorial

PROTEUS DESIGN

CODE

/*
 * PWMfast_motor.c
 *
 * Created: 10/4/2014 11:02:55 AM
 *  Author: rohit
 */ 

// demonstration of PWM motor speed control

#include <avr/io.h>
#include <util/delay.h>
void pwm_init()
{
    
    TCCR0 |= (1<<WGM00)|(1<<COM01)|(1<<WGM01)|(1<<CS00);// initialize timer0 in PWM mode
    DDRB |= (1<<PB3);// OC0 pin (pin PB3 for atmega32) as output pin
}

int main()
{
    unsigned int i;
    pwm_init();
    while(1)
    {
for (i= 0; i < 255; i++)// increasing motor speed
        {
            OCR0 = i; //fed analog value to OCR
            
            _delay_ms(20);
        }
        _delay_ms(4000);    
 for (i= 255; i> 0; i--)// decreasing motor speed
        {
            OCR0 = i;
            _delay_ms(20);
        }
        
        _delay_ms(2000);  
    }
}

VIDEO

Category: 

Share

Who's new

  • ravirajpatil871...
  • shubhambajoria
  • yassir
  • demiholyman890954
  • scottgillum51169040

Get Notified

 

Share

We are Social

Syndicate

Subscribe to Syndicate