On Thu, May 31, 2012 at 8:51 PM, wrote: >> Slightly confused; I need to drive a transformer in a push pull mode wit= h >> 2 FET's from the PIC. I wonder whether the ECCP mode is much suitable to= do that >> (since I will get CCP2 free in this case), or whether it is better to us= e >> CCP1 and CCP2 to drive the FET's. > > I think you may find this is one of the reasons why they introduced the E= CCP module. I think you will find it has methods for setting dead time and = other such requirements. I haven't used the ECCP module in this way, so am = not qualified to talk 'with knowledge' but seem to remember these were area= s it improved over the CCP. I found the dead time a good feature, so I decided to give it a try. I did some quick testing with a sine table taken from Roman Black's 1kHz sinewave generator http://www.romanblack.com/onesec/Sine1kHz.htm using the following code. #include #include #include #include #include "stdint.h" #pragma config WDT =3D OFF #pragma config PLLDIV =3D 5 /* 20MHz / 5 =3D 4 MHz, 96MHz PLL i/p */ #pragma config CPUDIV =3D OSC1_PLL2 /* CPU CLK =3D 96 MHz/2 =3D 48MHz */ #pragma config USBDIV =3D 2 /* 96MHz PLL/2 =3D 48MHz USB clock */ #pragma config FOSC =3D HSPLL_HS /* Osc type: HS Crystal, PLL enabled */ #pragma config VREGEN =3D ON /* USB Internal Voltage Regulator enabled */ #pragma config PWRT =3D ON #pragma config MCLRE =3D OFF #pragma config LVP =3D OFF #pragma config BOR =3D OFF /* * this is the 50 entry "harmonic compensated" * sine table (updated 20th Jun 2011) */ const rom char sine[50] =3D { 52, 57, 62, 66, 70, 74, 77, 80, 82, 84, 85, 86, 86, 86, 85, 83, 81, 78, 75, 72, 69, 65, 61, 56, 52, 48, 44, 39, 35, 31, 28, 25, 22, 19, 17, 15, 14, 14, 14, 15, 16, 18, 20, 23, 26, 30, 34, 38, 43, 48 }; void main (void) { char dc =3D 0; char step =3D 0; TRISCbits.TRISC2 =3D 0; /* P1A output */ TRISDbits.TRISD5 =3D 0; /* P1B output */ /* * Half bridge mode * P1A & P1B used, Active HIGH */ SetOutputPWM1(HALF_OUT, PWM_MODE_1); /* * start PWM * 1PWM cycle/period =3D 100ticks */ OpenPWM1(100 - 1); /* * CPU CLK =3D 48MHz * Tcy =3D 4/48MHz =3D 1/12uS =3D 83.3nS * ie, Nop() =3D 84nS * 1tick =3D 16*84nS =3D 1344nS =3D 1.344uS; * 100ticks =3D 134.4uS * PWM freq =3D 1/134.4uS =3D 7.4404kHz * * PWM freq =3D 50Hz */ T2CON =3D 0b00000100; /* TMR2 ON, 1:1 post, 1:16 pre */ while (1) { while (!PIR1bits.TMR2IF); dc =3D sine[step]; SetDCPWM1(dc); /* setup new duty cycle */ PIR1bits.TMR2IF =3D 0; step++; if (step >=3D 50) step =3D 0; } } However the output waveform doesn't seem to be as expected ? I find that the P1B is high most of the time, while P1A low. At least the duty cycle should vary a bit more consistently ? Feeling even more confused by now, whether it is the implementation what I did, or is it due to the ECCP, or in fact whether this what's to be expected... P1B http://www.flickr.com/photos/79743192@N07/7308947670/in/photostream P1A http://www.flickr.com/photos/79743192@N07/7308947960/in/photostream Any ideas ? Best Regards, Manu --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .