Beruflich Dokumente
Kultur Dokumente
__
____
____
| |
| | |
| |
| | |
_________| |____|
|___|
|________|
|_| |___________
1
1
=
= 20
50
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;
delay_ms(10);
PORTB.0 = 0;
delay_ms(10);
//
//
//
//
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.
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;
}
RPM = x/20;
UpdateDigits(RPM);
}
if(PINA.1==0)
{
wrLCDcmd(0x84);
if(x>=1000)
{
x = x - 1000;
}
RPM = x/20;
UpdateDigits(RPM);
}
}
// 50RPM = 1000 us