I'm using TimerA in up/down count mode to create a PWM signal on I/O pin P1-2. The timer uses an external 32K clock and I use CCR0 and CCR1 to vary the pulse width (Output Mode 6). For the most part this works fine and as expected but occasionally I see a "glitch" and get an unexpected result. I start and stop the timer before each pulse train sent out the port as follows:
------
Output signal driven low
Timer is cleared and started at 0
Timer counts up to CCR1 threshold and Output toggles high
Timer counts up to CCR0 threshold but Output is already high so no change expected.
Timer counts down to CCR1 threshold and Output toggles low
Timer counts down to 0 and an overflow interrupt (TAIFG) is generated.
The interrupt reloads the CCR0/CCR1 regs with new values.
The timer interrupt occurs about 50 times then stops the timer (producing 50 sequential PWM signals). At some point later the entire sequence will begin again triggered by an external event.
-----
As I mentioned above, everything works as described but once in a while I see that as the timer first starts for the very first of the 50 PWM cycles, the output pin toggles high immediately, toggles low at CCR1 count and toggles high at CCR0. My supposition is that if the timer starts at the low portion of the incoming 32KHz clock it will count up at the first low to high transition and every thing is hunky-dory but if the timer starts at the high portion of the incoming 32KHz clock it will still have TAR=0 after the first high to low transition and this will cause the timer to set the output pin high. To test this supposition I modified the initial timer startup such that I set TAR=1 after setting the CLR bit and before starting. This seems to have cured the occasional "high start" symptom described above.
I've not seen where this behavior is described in the documentation so I'm coming the forum to see if my supposition is a known function of the timer...... or perhaps I'm masking a different problem by changing the start count to TAR=1 before starting.
--Mike