We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
hi,everyone i'm actually try to counting velocity by using timer to count the time travel by an object and divide it by the distance but the time calculated seems to be wrongs can anyone help me with taht?
#include <AT898252.H> #include <stdio.h> unsigned char pulse_low=0,pulse_high=0; unsigned int overflow_count=0,int_count=1,pulse=0,time=0,velocity=0; long int pulse_width=0; sbit START=P1^1; sbit STOP=P1^0; void main(){ TMOD=0x90; TF1=0; IT1=1; IE=0x8c; while(1){ unsigned char a; unsigned char x; if(START==0&&STOP==0){ a=3; } else if(START==0&&STOP==1){ a=2; } else if(START==1&&STOP==0){ a=0; } else if (START==1&&STOP==1){ a=1; } switch(a){ case 0:{ TR1=1; break; } case 1:{ pulse_low=TL1; pulse_high=TH1; pulse=(TH1<<8)+TL1; pulse_width= (overflow_count)*65536+pulse; time=pulse_width/13921583.00; x=time; velocity=0.004/time; break; } case 2:{ TR1=0; TH1=0x00; TL1=0x00; overflow_count=0; break; } case 3:{ TR1=0; break; } default:{ break; } } } } void timer1_int()interrupt 3 { overflow_count++; }
"time ... divide it by the distance"