Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/06/08 14:07
Read: times


 
#159838 - speed control of motor
in my friend's project speed control of motor through pwm generation he is using the following code

#include<AT89x52.h>
int i=0; int t_on=0; t_off=100;
int k[]=(63,06,91,79,102,109,125,07,127,111,128);
bit t_val=0;
unsigned int count1, count2, TH0_on, TH0_off, TL0_on, TL0_off;

void increase (void) interrupt 0
{
t_on = t_on + 10;
if(t_on>100) (t_on=100);
t_off=100 - t_on;
count1=t_on*10;
count2=t_off*10;
TH0_on=(65535-count1)/256;
TL0_on=(65535-count1)%256;
TH0_off=(65535-count2)/256;
TL0_off=(65535-count2)%256;
}

void pwm (void) interrupt 1
{
TR0=0;
P1_1= ~P1_1;
if(t_val==1)
{TH0 = TH0_off; TL0=TL0_off;}
else
{TH0 = TH0_on; TL0=TL0_on;}
t_val=~t_val;
TR0=1;
}


void decrease (void) interrupt 2
{
t_on = t_on - 10;
if(t_on<0) (t_on=0);
t_off=100 - t_on;
count1=t_on*10;
count2=t_off*10;
TH0_on=(65535-count1)/256;
TL0_on=(65535-count1)%256;
TH0_off=(65535-count2)/256;
TL0_off=(65535-count2)%256;
}

void main()
{
P1=1;
IE=135;
IP=5;
TCON=21;
TMOD=1;
count1=t_on*10;
count2=t_off*10;
TH0_on=(65535-count1)/256;
TL0_on=(65535-count1)%256;
TH0_off=(65535-count2)/256;
TL0_off=(65535-count2)%256;
TH0=TH0_on;
TL0=TL0_on;
TR0=1;
while(1)
{
P2=k[t_on/10];
}
}

now the problem is that the speed control is being done but it is supposed to display on the 7-segment a value (for eg 1 dislayed indicates the motor is running at 10% of its maximum rating and so on) but it showing some garbage value .pls help its really urgent!




List of 6 messages in thread
TopicAuthorDate
speed control of motor            01/01/70 00:00      
   two things to make your code readable            01/01/70 00:00      
   Your friend?            01/01/70 00:00      
      not able            01/01/70 00:00      
   sorry!            01/01/70 00:00      
      two things            01/01/70 00:00      

Back to Subject List