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.
hai all, I want a to implement timer concept for 10sec. I want to start timer in one state and want to stop it another state.Is it possible?
//states are INIT,POWERON,GATEOPEN,GATECLOSE. //set active state as INIT while(1) { process(); } void process() { switch(activestate) { case INIT: starttimer(2minutes);//here i want to start the timer and proceed to next state ie parallel timer for 2minutes. change_active_state=poweron; case poweron: if(timernotover) //remain in same state else //proceed. case open: if(gateopentogateclose) { start timer(10sec); //watch the input status if(gate close detected) stoptimer; change state to closed; } case closed: if( close detected) { stoptimer; } . . . . . . } }
my problem is if i start timer then it remains in same state till the timer completes. I want to start timer and proceed to next state and kill the timer there.... in the above scenario the timer waits in INIT state for 2minutes but it should wait in poweron state.
timer routine starttimer(int noofsec) { TMOD=TMOD&0xF0; TMOD=TMOD|00x01; for(i=0;i<noofsec*20;i++) { //50 milli sec timer TH0=0x3C; TL0=0xB0; TF0=0; TR0=1; while(TF0==1); TR0=0; } }
without for loop is there any way to maintain the timer parallely........ with thanks, Ram
do you mind posting the original source code instead of semi pseudo-code that does not compile?
Don't busy-loop your timer.
Use a timer interrupt that updates an "uptime" variable with suitable resolution.
Then in your code remember current uptime.
Do what you need to do until uptime is at least 2 min larger.
If you have a busy-loop function - as you currently do - then it will not return until after two min.
And no pseudo-code when you ask for specific problems.
Pseudo-code should only be used when discussing an algorithm, to give a rough description of the algorithm.