Title: dsPIC33 Output Compare help
Post by: tAhm1D on September 24, 2009, 07:50:27 07:50
Hi all, I was programming the dsPIC33 Output compare module when I came across this problem. I am running the output compare module in continuous output pulse mode using timer2 at something above 30khz. The problem is when I use the internal FRC (7.37MHz) there is no problem and the waveforms are all fine, but when I use PLL and post/predivider to set FRCPLL at 80MHz(for 40MIPS), the waveform becomes all distorted. I attached the screenshot of the waveform. What can be the cause for this? Is it problem in programming or simulation problem in Proteus? Here is the code: _FOSCSEL(FNOSC_PRI); _FOSC(FCKSM_CSECMD & OSCIOFNC_ON & POSCMD_NONE); _FWDT(FWDTEN_OFF);
int main (void) { //Configure Oscillator PLLFBD = 41; //43 * 7.37 = x CLKDIVbits.PLLPOST = 0; // x = x/2 CLKDIVbits.PLLPRE = 0; // x = x/2 ... x comes as 80MHz thus 40MIPS __builtin_write_OSCCONH(0x01); __builtin_write_OSCCONL(0x01); while (OSCCONbits.COSC != 1); while (OSCCONbits.LOCK != 1); //Configure I/O TRISA = 0x1F; //all inputs TRISB = 0x0003; //AN2(RB0), AN3(RB1) inputs, rest output RPOR7bits.RP14R = 18; //RP14(RB14) connected to OC1 RPOR7bits.RP15R = 19; //RP15(RB15) connected to OC2 AD1PCFGL = 0xFFF0; //AN0, AN1, AN2, AN3 analog //Configure Timer T2CON = 0; //no prescale PR2 = 1200; //>30 kHz per output //Configure OC OC1R = 1; OC1RS = 480; OC1CON = 0x05; //Continuous Pulse Generation, Timer2 T2CONbits.TON = 1; //Start timer and output compare while (1); }//end.
Title: Re: dsPIC33 Output Compare help
Post by: jestanoff on September 27, 2009, 05:53:12 17:53
Hi tAhm1D, From listed code is seemed that no visible error, except this: OSCCON = 0x46; // OSCCON = 0x57; // unlock writes to the RPINRx and RPORx registers OSCCONbits.IOLOCK = 0; // RPOR7bits.RP14R = 18; //RP14(RB14) connected to OC1 RPOR7bits.RP15R = 19; //RP15(RB15) connected to OC2
OSCCON = 0x46; // OSCCON = 0x57; // lock writes to the RPINRx and RPORx registers OSCCONbits.IOLOCK = 1; //
The problem maybe is in a Proteus, but if you want try to replace the initialization code from one my project with dsPIC33: // Select Internal FRC at POR //_FOSCSEL(FNOSC_FRC); _FOSCSEL(FNOSC_PRI); // Enable Clock Switching and Configure POSC in XT mode _FOSC(FCKSM_CSECMD & OSCIOFNC_OFF & POSCMD_XT); //WD_init //TLPRC=31.125uS //TWTO = (N1=128) * (N2=2048) * (TLPRC)=8.159s _FWDT(FWDTEN_ON & WDTPRE_PR128 & WDTPOST_PS512);
int main(void) { // Configure Oscillator to operate the device at 36.864Mhz // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2 // Fosc= 7.3728M*40(2*2)=73.728Mhz for 7.3728MHz input clock // Configure PLL prescaler, PLL postscaler, PLL divisor PLLFBD=38; // M = 40 for 7.3728MHz CLKDIVbits.PLLPRE=0; // N1 = 2 CLKDIVbits.PLLPOST=0; //0 - N2=2; 1 - N2=4 ; 3 - N2=8 // Initiate Clock Switch to Primary Oscillator with PLL (NOSC = 0b011) __builtin_write_OSCCONH(0x03); __builtin_write_OSCCONL(0x01); // Wait for Clock switch to occur while (OSCCONbits.COSC != 0b011); RCONbits.SWDTEN=1; //Enable Watch Dog Timer // Wait for PLL to lock while(OSCCONbits.LOCK!=1) {}; ClrWdt(); Ports_init(); while(1) { } return 0; }
Title: Re: dsPIC33 Output Compare help
Post by: tAhm1D on October 09, 2009, 10:51:53 10:51
Hi, I kept no stone unturned to solve the problem. Same type of questions are there in different other forums, but could not get satisfactory answer. One member in the Labcenter Forum asked the question and from the reply of Labcenter people,it could be clearly guessed that it is the problem of Proteus. Hope for the next versions. Thanks.
|