Hi everyone,
I am trying to generate one sine wave using PCPWM of PIC18F4331. I have set the frequency of PWM to 20KHz (PTPER 249) and I am using 20MHz crystal. I have calculated the resolution which is equal to 10 bits. Hence, a value of 0 is equal to 0% duty cycle and a value of 1023 is equal to 100%.

I generated a sine table of 19 values from 0 to 90 degrees in steps of 5 with a scaling factor of 128. I have set TMR0 to 8 bits and it always starts counting from 200 to 255 then overflows. Once it overflows, it updates the pointer to the table. I believe that to complete 1 cycle, 36 samples of the sine wave are required. The TMR0 interrupt is generated every 55*1.6 us (instruction cycle) which is equal to 88 us. Hence, one cycle is generated every 36*88 us = 3.2 ms (315 Hz).

The sine table I used is below
//0-90 sine wave 128 scaling in step of 5
const char sineTable[19]={0x80,0x8B,0x96,0xA1,0xAC,0xB6,0xC0,0xC9,0xD2,0xD B,0xE2,0xE9,0xEF,0xF4,0xF8,0xFC,0xFE,0xFF,0xFF };

One more thing, the sine value once it is selected it gets multiplied by 200 then limited and sent to PDC0H and PDC0L to increase the ON time of the signal. The way I did is the max value in sine table is 255*200 = 51000 then I shift this value to the right 6 times (10bits) then send it PDC0. I am not sure if what I did is right or wrong.

I am using ISIS to simulate my program. at the moment, My sine signal is at 20 Hz and the amplitude is 1.5V P-P. What I am doing wrong? How can I increase the amplitude of the sine wave? Also can I improve the sine wave shape?