PIC12F1572 Timer 1 Problem
Hi. I can't seem to correctly configure Timer1 as a simple timer in a PIC12F1571 project intended to randomly modulate the brightness of some red Christmas tree lights to make them look like glowing embers.
A low voltage transformer drives an optocoupler to generate a sync pulse (external interrupt) at the zero crossing of each rectified A.C. half cycle (120 Hz). This interrupt simply turns the lights on via a triac optocoupler.
Timer0 is set up as a 100 mS interrupt which decrements a counter. When that counter reaches 0, one new pseudo random number is generated to determine the count of 100 mS interrupts until the next brightness change, and a second pseudo random number is generated to set the brightness level until the next change. Toggling RA5 at each occurrence of this interrupt yields the expected 5 Hz frequency.
Timer1 uses that brightness count to determine how long the lights stay on during the half cycle after the A.C. sync pulse... the greater the time, the brighter.
Using the T1CON register I've attempted to set the clock at Fosc/4 and a 1:8 prescale (500 KHz/4)/8 = 15,625 Hz. The Timer1 interrupt should be occurring at 120 Hz. However, setting the same RA5 toggle at the Timer1 interrupt service routine reveals that it gets there about once every 5 seconds!
I don't understand what I'm doing wrong. At 15,625 Hz my maximum possible interval between interrupts would be 4.2 seconds. I've tried to use the MPLABX simultator, but I can't seem to fully trust it.
I've uploaded my most recent .c file. Any advice would be appreciated.