You cannot implement software timer without help from hardware timer. So you shall get familiar with hardware timer first, build code that calls timer interrupt service routine (ISR) 100 or 1000 times per second. Then next step would be implementing software timer(s) code in the hardware timer ISR. Example of supersimple implementation of two software period timers: volatile counter1 = 0; volatile counter2 = 0; hw_timer_isr() { // running 100 times/sec if (++counter1 >= 10) { do_something_each_100msec(); counter1 = 0; } if (++counter2 >= 100) { do_something_each_1sec(); counter2 = 0; } }
↧