Based on the "time-base interrupt" technique outlined by Stewart in this thread:
http://forum.microchip.com/tm.asp?m=59908&mpage=1&key=interrupt&anchor#60348
I've wrote some code for the 16F877, controlling eight LEDs, which I made it complex enough to see how far I could go:
LED 0 blinks once with a certain on time
LED 1 same as above with different on time
LED 2 blinks for a certain number of times with equal on-off periods
LED 3 blinks for a certain number of times with different on-off periods
LED 4 blinks for a certain number of times with equal on-off periods
LED 5 blinks continuously with equal on-off periods
LED 6 blinks continously with different on-off periods
LED 7 blinks continuously with equal on-off periods
The main loop consists of nine tasks: one for the keyboard and one for each LED. Each LED is activated by pressing a different key in the keyboard. Time base is 2 msec and on/off periods range from 250 msec to 1500 msec.
Basically I can say that it worked from the first try demonstrating his point but after experimenting for a while I've started to wonder about the following points:
a) A keyboard debouncing delay (I use 25 msec) requires just one 8-bit counter to be decremented while a 1500 msec delay demands three 8-bit counters. How to cope with VERY LONG delays and a SMALL time-base?
b) With many of the delays requiring two or three (BTW why not four or five?) 8-bit counters I've found that the time spent by the ISR could ammount up to one tenth of the time base period. Isn't that excessive? What if I have many other tasks to serve?
c) When only TMR0 interrupt is enabled, it's an event that repeats after an exact amount of time. The LEDs' blinking periods, since they affect each other, are essentially not exact. I assume then than whatever other event I want to occurr at an exact moment, could not! Let's say that if I want a pin going high exactly every 25 msec during 6 msec what I could only get is just ABOUT that.
d) What if other interrupts are enabled?. Being unable to assign any priority to TMR0 interrupt (16F877) the 2 msec time base would became not an exact occurrence anymore!
e) I run across an unforeseen difficulty: all LEDs required two flags: one showing they were or not "active" and another telling if they had to be ON or OFF. Probably due to lack of experience I found the handling of those flags complicate and cumbersome and hard to debug. I couldn't follow Stewart's pseudo code very well regarding flags. I work in assembler so whatever comes from C language is hard for me to understand. Sorry about that.
Comments of any kind appreciated.If at all possible, please follow the order of points as stated above. That would help me.
Agustín Tomás
http://forum.microchip.com/tm.asp?m=59908&mpage=1&key=interrupt&anchor#60348
I've wrote some code for the 16F877, controlling eight LEDs, which I made it complex enough to see how far I could go:
LED 0 blinks once with a certain on time
LED 1 same as above with different on time
LED 2 blinks for a certain number of times with equal on-off periods
LED 3 blinks for a certain number of times with different on-off periods
LED 4 blinks for a certain number of times with equal on-off periods
LED 5 blinks continuously with equal on-off periods
LED 6 blinks continously with different on-off periods
LED 7 blinks continuously with equal on-off periods
The main loop consists of nine tasks: one for the keyboard and one for each LED. Each LED is activated by pressing a different key in the keyboard. Time base is 2 msec and on/off periods range from 250 msec to 1500 msec.
Basically I can say that it worked from the first try demonstrating his point but after experimenting for a while I've started to wonder about the following points:
a) A keyboard debouncing delay (I use 25 msec) requires just one 8-bit counter to be decremented while a 1500 msec delay demands three 8-bit counters. How to cope with VERY LONG delays and a SMALL time-base?
b) With many of the delays requiring two or three (BTW why not four or five?) 8-bit counters I've found that the time spent by the ISR could ammount up to one tenth of the time base period. Isn't that excessive? What if I have many other tasks to serve?
c) When only TMR0 interrupt is enabled, it's an event that repeats after an exact amount of time. The LEDs' blinking periods, since they affect each other, are essentially not exact. I assume then than whatever other event I want to occurr at an exact moment, could not! Let's say that if I want a pin going high exactly every 25 msec during 6 msec what I could only get is just ABOUT that.
d) What if other interrupts are enabled?. Being unable to assign any priority to TMR0 interrupt (16F877) the 2 msec time base would became not an exact occurrence anymore!
e) I run across an unforeseen difficulty: all LEDs required two flags: one showing they were or not "active" and another telling if they had to be ON or OFF. Probably due to lack of experience I found the handling of those flags complicate and cumbersome and hard to debug. I couldn't follow Stewart's pseudo code very well regarding flags. I work in assembler so whatever comes from C language is hard for me to understand. Sorry about that.
Comments of any kind appreciated.If at all possible, please follow the order of points as stated above. That would help me.
Agustín Tomás