| ??? 05/31/00 04:50 Read: times |
#2948 - A little more detail |
Mohd,
If you had a 12Mhz 8051, not even the 16bit timer can count out 1/2 second: 12Mhz/12/(1/500ms)=500,000 ticks or 07A120h (not the timer value) so you'll need to have your interrupt routine count down the number of interrupts before allowing flow to pass to the LED output toggle. You could used autoreload mode 2 on any timer if you are willing to allow 2000 interrupts to fire for each eventual 1/2 second toggle... it depends on your system loading whether that's a good idea. Another idea depends upon how accurate the 1/2 second toggle time needs to be. If its only for appearances (though this sounds like a class lab assignment) the simplest technique is to choose a timer mode {0,1,2,3} and let it free-run and interrupt on overflow. After all, every timer behaves as an autoreload feature *IF* the value to reload is ZERO. In this case, your significant choice is between an 8bit (Mode 2&3), 13bit (Mode 0) or 16bit (mode 1) sub count. Choose the highest bit value which gives the closest interval accuracy with the fewest interrupts. Evaluate 16 bits first and work down. 16 bit solution =============== 12Mhz/12/(2^16)=15.26 ticks per second. Using a 16bit timer free running, you could count down 8 interrupts before toggling the LED pin for a cycle time of 523 ms per toggle. Slightly longer than 1s LED on/off cycle, but not significant. If you want a closer fit, do the same computations for 13bit and 8 bit. The interrupt routine under this method would not need to relaod the timer - it would continue incremented as the value 0FFFFh overflowed to 0000h. The interrupt routine would merely decrement and jump on not zero to RETI, a value of 8 loaded in a reserved RAM byte. When the DJNZ results in ZERO, the next instructions are executed which would be the LED output pin TOGGLE and then reload of the value 8 into the interrupt DJNZ counter. NTR_T1: ... ;enable next interrupt djnz countdown,adios cpl px.y ;toggle LED output pin mov countdown,#8 ;reload passcount adios: reti 12Mhz/12/(2^13)=122.07=07Ah ticks 12Mhz/12/(2^8) =3906.25 0F42h ticks While a 16bit solution is best if you dont' require accuracy, the 13bit solution requires only a single byte countdown value but consumes about 15 times the number of interrupt before a toggle occurs. The 8bit solution requires a two byte decrement and its getting ugly. Unless you have other tasker requirements, Mode 1 (16bits) or Mode 0 (13bits) would be the easiest. There is another technique that can be used on some of the derivative 8051s but I won't mention it. A 13bit solution: ================= 12Mhz/12/2^13/(122/2)=2 per second or toggle every 0.4997 seconds. This is much tighter. The tick count is 122/2 or 61 decimal = 3Dh. The value loaded into countdown would be 03Dh because it is using a DJNZ command, while the timer is free-running through all possible 13bit combinations. -Jay C. Box |
| Topic | Author | Date |
| Need to falsh LED using interupts | 01/01/70 00:00 | |
| RE: Need to falsh LED using interupts | 01/01/70 00:00 | |
| RE: Need to falsh LED using interupts | 01/01/70 00:00 | |
| A little more detail | 01/01/70 00:00 | |
A little more detail | 01/01/70 00:00 |



