Hello Sathya,
Your timer setup for unbuffered PWM on channel 0 appears to be correct, and you are also correct in changing the PWM pulse width within the channel 0 interrupt handler (after the PWM output has gone low).
The issue appears to be that, since you are incrementing the width following each interrupt, there will actually be two interrupts per PWM cycle, the first time after timer overflow has occurred and the output is high (after toggle on overlow), and the second time on the increased channel value, prior to the next timer overflow when the output is still low.
The simplest way to handle this situation would be to test the timer overflow flag, and only if the flag is set, to update the channel value. Perhaps your interrupt handler might be modified as follows -
#pragma TRAP_PROC
interrupt void TIMCH0_Interrupt(void)
{
TSC0_CH0F = 0; // Clear channel 0 flag
if (TSC_TOF) { // Test for overflow flag set
TSC_TOF = 0; // Clear overflow flag
TCH0L = sinewave[i];
i++;
if (i > 7)
i = 0;
}
}
It should be unnecessary to make use of a second timer channel.
Regards,
Mac