gauravkothari23
Advanced Member level 2
Hi all
I am trying to control the speed of the DC motor using 89S52 controller using Timer0 Interrupt
my problem is when i am trying to rotate the motor at full speed at PWM=0; it does not. instead when i stop the PWM by writing status_flag=0 and motor=0; the speed increases drastically,
i tried measuring the RPM, when PWM=0, the RPM is approx 2100 RPM and when i stop the PWM and ON the Mosfet the RPM is Approx 2700.
can anybody please let me know where the problem is
I am trying to control the speed of the DC motor using 89S52 controller using Timer0 Interrupt
Code:
void main()
{
while(1)
{
status_flag=1;
PWM=0;
msdelay(5000);
status_flag=0;
motor=0;
msdelay(5000);
}
void pwm_setup()
{
TMOD &= 0xF0; // Clear 4bit field for timer0
TMOD |= 0x01; // Set timer0 in mode 1 = 16bit mode
TH0 = 0x00; // First time value
TL0 = 0x00; // Set arbitrarily zero
ET0 = 1; // Enable Timer0 interrupts
EA = 1; // Global interrupt enable
TR0 = 1; // Start Timer 0
}
void timer0_ISR(void) interrupt 1
{
TR0 = 0; // Stop Timer 0
if((PWM_flag==1) && (status_flag==1))
{
PWM_flag=0;
motor = 0;
temp = (255-PWM) * PWM_Freq_Num;
TH0 = 0xFF - (temp>>8)&0xFF;
TL0 = 0xFF - temp&0xFF;
}
else if((PWM_flag==0) && (status_flag==1))
{
PWM_flag=1;
motor = 1;
temp = PWM * PWM_Freq_Num;
TH0 = 0xFF - (temp>>8)&0xFF;
TL0 = 0xFF - temp&0xFF;
}
TF0 = 0; // Clear the interrupt flag
TR0 = 1; // Start Timer 0
}
my problem is when i am trying to rotate the motor at full speed at PWM=0; it does not. instead when i stop the PWM by writing status_flag=0 and motor=0; the speed increases drastically,
i tried measuring the RPM, when PWM=0, the RPM is approx 2100 RPM and when i stop the PWM and ON the Mosfet the RPM is Approx 2700.
can anybody please let me know where the problem is