??? 06/23/10 13:06 Read: times |
#176859 - State Machine Responding to: ???'s previous message |
I do have a timer that is overflowing every 50ms for a software RTC. I guess I could use it:
/*------------------------------------------------------------------- Timer 1 is implemented as a software RTC. overflows every 50 ms with 11.0592 MHz increments global soft_RTC_ticks which gives relative time in seconds since the system was booted. accurate enough for now. --------------------------------------------------------------------*/ void timer_1_interr(void) interrupt 3// using 2 { static unsigned char data multiplier = 0; //this many times slower TR1 = 0; TF1 = 0; //present_keypress = 0; if(++multiplier == 20) { multiplier = 0; soft_RTC_ticks++; } TH1 = SOFT_RTC_TH1_RELAOD; //relaod timer 1 TL1 = SOFT_RTC_TL1_RELAOD; //decided from hit-n-trial TR1 = 1; } This concept of state machine in embedded system is new to me since I haven't studied this in our courses. So loops were all I could think of though I know it's bad programming practice. Anyways what I comprehend from this concept is that the states of the keyboard be updated in related variables e.g. key_down etc whenever timer ISR fires, so the program has access to the state of the keyboard which is no older than 50ms. Kindly correct me if I get this wrong. This is new to me. And wouldn't my software RTC's accuracy be affected if I include the code to update the keyboard state in timer ISR? I had to fine tune it with hit & trial to get an acceptable error before. It was quite a pain to find the values for SOFT_RTC_TL1_RELAOD & SOFT_RTC_TH1_RELAOD that make the soft_RTC_ticks increment exactly after 1 second, considering other overheads in ISR. -Regards, Munish |
Topic | Author | Date |
Ideas for Multi-tap keyboard routine | 01/01/70 00:00 | |
just follow | 01/01/70 00:00 | |
Multi-tap is not too difficult | 01/01/70 00:00 | |
Two-step operation. Keyboard input + post-processing | 01/01/70 00:00 | |
State Machine! | 01/01/70 00:00 | |
Agree 100% | 01/01/70 00:00 | |
Time to code | 01/01/70 00:00 | |
Software Timers! | 01/01/70 00:00 | |
Practical Limits | 01/01/70 00:00 | |
Don't lock up in infinite loops everywhere | 01/01/70 00:00 | |
In the pseudo code... | 01/01/70 00:00 | |
State Machine | 01/01/70 00:00 | |
Divide by 5 | 01/01/70 00:00 | |
Timer resolution | 01/01/70 00:00 | |
State Machine | 01/01/70 00:00 | |
Looks not bad programming practice | 01/01/70 00:00 | |
Using Timer May Still be Possible | 01/01/70 00:00 | |
Done ! | 01/01/70 00:00 | |
Very Cool!!! | 01/01/70 00:00 | |
Compare with zero is better | 01/01/70 00:00 | |
Avoid ISR jitter using timer T1 | 01/01/70 00:00 | |
Code! | 01/01/70 00:00 | |
Thanks Munish...![]() | 01/01/70 00:00 |