Unexpected PWM Module Behavior
Hi, I'm attempting to use a PIC12F1572 to make four strings of red and orange LED light strings flicker independently and in pseudo-random fashion to look like glowing embers. Please see my attached code.
The approach is one commonly found on the Internet in which an A.C. line is fed into a step down transformer. That low-voltage output is fed into a full-wave bridge rectifier and into an optoisolator to generate a 120 Hz sync pulse. This pulse interrupts the PIC to turn all light strings off and initiate timers with pseudo-random values. When each of those timers time out they interrupt the PIC to turn on their respective light string at the currently-specified time within each 120 Hz half cycle. The earlier in the cycle it's turned on, the brighter the lights appear. Four counters in the main program are used to keep track of how long each string has been on. As each counts down to zero the program calculates a new pseudorandom brightness count and interval time for its associated light string.
I'm using the Timer0 module to generate a periodic 100 mS interrupt for the main program, and I'm using Timer1 for the first light string. That much finally seems to be working fine.
However, I'm now attempting to set up PWM3 as the first of three PWM modules to function as 16-bit timers to control brighness for the other three light strings. I'm attempting to use PWM3 in Standard Mode to generate an interrupt when its Period Register is matched.
Not only am I having trouble figuring out how to get PWM3 to work as a simple timer, the opto-isolator signal (on RA4) for the first string's triac (controlled by Timer1) is inexplicably replicated on RA5 which is the source of the signal for the fourth string's triac driver(!). My first suspicion was a short, but I measure 4 Mohms between these two pins. Replacing the PIC with a new one yielded the same results.
So... I'd really appreciate some help understanding how to set up PWM3, PWM2, and PWM1 to function like Timer1 (e.g. do I need to use the LDA bit to load the PWM registers? What order should I change the PWM registers & control bits? Can I stop/start each timer by clearing/setting its enable bit?). For my sanity's sake, I'd also appreciate knowing how my RA4 signal is being replicated on RA5 - which seems to completely ignore changes I make to PWM3's timer load values... probably because I don't know what the heck I'm doing with these PWM modules.
Thanks!