robotics & automation

4
Robotics & Automation ASSIGNMENT – PWM ON DC MOTOR BY: MUHAMMAD AMMAR 2010-NUST-PNEC-BE-ME-81 (ME-980) VII – ME – B

Upload: muhammadammar

Post on 15-Apr-2016

9 views

Category:

Documents


0 download

DESCRIPTION

Examples

TRANSCRIPT

Page 1: Robotics & Automation

Robotics & Automation

ASSIGNMENT – PWM ON DC MOTOR

BY: MUHAMMAD AMMAR

2010-NUST-PNEC-BE-ME-81 (ME-980) VII – ME – B

Page 2: Robotics & Automation

Pulse-width modulation (PWM), or pulse-duration modulation (PDM), is a modulation technique that conforms the width of the pulse, formally the pulse duration, based on modulator signal information. Although this modulation technique can be used to encode information for transmission, its main use is to allow the control of the power supplied to electrical devices, especially to inertial loads such as motors.

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.

_ __ ____ ____ _

PWM Signal | | | | | | | | | |

| | | | | | | | | |

_________| |____| |___| |________| |_| |___________

A Typical PWM Signal

The PWM switching frequency has to be much faster than what would affect the load, which is to say the device that uses the power.

Example:

f = 50Hz,

Time period for one cycle (T):

𝑇 = 1

𝑓=

1

50= 20𝑚𝑠

It means that if the signal is turned on, the motor will receive full power. Now we can turn on and off the signal by assigning 0 and 1 to output of the motor within 20ms interval to vary the speed of motor

while(1) {

PORTB.0 = 1; // Turns on the motor output delay_ms(10); // Output on for 10ms PORTB.0 = 0; // Turns off the motor output delay_ms(10); // Output off for 10ms

}

Page 3: Robotics & Automation

This will run the motor for half the rated speed because for half of the period, motor is in OFF state and for other half it is ON.

The variable delays can be set up in order to achieve different speeds of the motor.

The term duty cycle describes the proportion of 'on' time to the regular interval or 'period' of time; a low duty cycle corresponds to low power, because the power is off for most of the time. Duty cycle is expressed in percent, 100% being fully on.

Program to run DC motor with half speed #include <mega16.h> #include <delay.h> void main (void) { DDRB.0 = 1; PORTA.0 = 1; PORTA.1 = 1; unsigned char x = 50; while(1) { PORTB.0 = 1; delay_ms(5); PORTB.0 = 0; delay_ms(5); } }

For variable speed with increment/decrement of 1% of rated speed #include <mega16.h> #include <delay.h> #include <ATKv10_1.h> void main (void) { Init_LCD(); DDRB.0 = 1; PORTA.0 = 1; PORTA.1 = 1; unsigned char x = 10000; // Initial speed = Half of Rated Speed while(1) { PORTB.0 = 1; delay_us(x); PORTB.0 = 0; delay_us(20000 - x); if(PINA.0==0) { wrLCDcmd(0x82);

Page 4: Robotics & Automation

x = x + 200; UpdateDigits(x); } if(PINA.1==0) { wrLCDcmd(0x82); x = x - 200; UpdateDigits(x); } }

Drive a DC motor using a PWM Signal through PB0. Increase or decrease speed of motor with steps of 50RPM with the help of two push buttons connected at PA0 and PA1. Take f = 50Hz. Also show the on-time if signal (value of x). Max RPM of motor is 1000RPM.

#include <mega16.h> #include <delay.h> #include <ATKv10_1.h> void main (void) { Init_LCD(); DDRB.0 = 1; PORTA.0 = 1; PORTA.1 = 1; unsigned char x = 10000; wrLCDcmd(0x80); while(1) { PORTB.0 = 1; delay_us(x); PORTB.0 = 0; delay_us(20000 - x); if(PINA.0==0) { wrLCDcmd(0x84); if(x<=20000) { x = x + 1000; // 50RPM = 1000 us } RPM = x/20; UpdateDigits(RPM); } if(PINA.1==0) { wrLCDcmd(0x84); if(x>=1000) { x = x - 1000; } RPM = x/20; UpdateDigits(RPM); } }