Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PWM generation with dsPIC33FJ64GS610

Status
Not open for further replies.

yokel

Junior Member level 3
Joined
Nov 13, 2008
Messages
30
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,529
Dear all,
I need to generate PWM signal with dsPIC33FJ64GS610 for generating PWM signal. I am using the following code but failed to get any PWM output. It would be nice if anyone come forward with any advice.

Code:
#include "p33FJ64GS610.h"

/* Configuration Bit Settings */
_FOSCSEL(FNOSC_FRC)
_FOSC(FCKSM_CSECMD & OSCIOFNC_ON)
_FWDT(FWDTEN_OFF)
_FPOR(FPWRT_PWR128)
_FICD(ICS_PGD2 & JTAGEN_OFF)

void init_PWM(void);

int main()
{
/* Configure Oscillator to operate the device at 40Mhz
	   Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
 	   Fosc= 7.37*(43)/(2*2)=80Mhz for Fosc, Fcy = 40Mhz */

	/* Configure PLL prescaler, PLL postscaler, PLL divisor */
	PLLFBD=41; 				/* M = PLLFBD + 2 */
	CLKDIVbits.PLLPOST=0;   /* N1 = 2 */
	CLKDIVbits.PLLPRE=0;    /* N2 = 2 */

    __builtin_write_OSCCONH(0x01);			/* New Oscillator FRC w/ PLL */
    __builtin_write_OSCCONL(0x01);  		/* Enable Switch */
      
	while(OSCCONbits.COSC != 0b001);		/* Wait for new Oscillator to become FRC w/ PLL */  
    while(OSCCONbits.LOCK != 1);			/* Wait for Pll to Lock */

	/* Now setup the ADC and PWM clock for 120MHz
	   ((FRC * 16) / APSTSCLR ) = (7.37 * 16) / 1 = ~ 120MHz*/

	ACLKCONbits.FRCSEL = 1;					/* FRC provides input for Auxiliary PLL (x16) */
	ACLKCONbits.SELACLK = 1;				/* Auxiliary Oscillator provides clock source for PWM & ADC */
	ACLKCONbits.APSTSCLR = 7;				/* Divide Auxiliary clock by 1 */
	ACLKCONbits.ENAPLL = 1;					/* Enable Auxiliary PLL */
	
	while(ACLKCONbits.APLLCK != 1);			/* Wait for Auxiliary PLL to Lock */

    TRISE = 0;       		    /* Set as a digital output */
    LATE = 1;
    
    init_PWM();
    
    while(1);                     			/* Infinite Loop */
}

void init_PWM()
{

    PTPER = 2404;                           /* PTPER = ((1 / 400kHz) / 1.04ns) = 2404, where 400kHz 
											 is the desired switching frequency and 1.04ns is PWM resolution. */

    /*~~~~~~~~~~~~~~~~~~~~~~~ PWM1 Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/    
    IOCON1bits.PENH      = 0;      			/* PWM1H is controlled by GPIO module */ 
    IOCON1bits.PENL      = 1;      			/* PWM1L is controlled by PWM module */
    IOCON1bits.PMOD      = 1;      			/* Select Independent Output PWM mode */

    PDC1 = 640;					   			/* Initial Duty cycle */ 
    DTR1    = 64;                  			/* Deadtime setting */
    ALTDTR1 = 64;                  			/* Deadtime setting */

    PHASE1 = 0;                    			/* No phase shift */

    /*~~~~~~~~~~~~~~~~~~~~~~~ PWM2 Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    IOCON2bits.PENH      = 0;      			/* PWM2H is controlled by GPIO module */
    IOCON2bits.PENL      = 1;      			/* PWM2L is controlled by PWM module */
    IOCON2bits.PMOD      = 1;      			/* Select Independent Output PWM mode */

    PDC2 = 640;					   			/* Initial Duty cycle */ 
    DTR2    = 64;                  			/* Deadtime setting */
    ALTDTR2 = 64;                  			/* Deadtime setting */

    PHASE2 = 240;                  			/* approximately 250ns phase shift */

    PTCONbits.PTEN       = 1;      			/* Enable the PWM Module */
}
 
Last edited:

When i browse through microcip application note, they use PGD1 instead of PGD2 : _FICD(ICS_PGD2 & JTAGEN_OFF). Will that have any effect?
 

no effect...I tried with both options. thanks
 

can anyone help? it's really urgent for me to know
thanks in advance
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top