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.

dsPIC: PWMs in 90 phase using Output Compare Mode

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
Hi All,
I am using dsPIC33FJ256GP710 for PWM generation. As this particular MCU doesn't support any direct PWM mode, I am using the Output Compare PWM mode for generating two PWM signals from OC1 and OC2 pins. The frequency and duty cycle for the two PWM are same.

Here's the code:
Code:
// Initialize Output Compare Module
OC1CONbits.OCM = 0b000; // Disable Output Compare Module
OC1R = 0; // Write the duty cycle for the first PWM pulse
OC1RS = 12; // Write the duty cycle for the second PWM pulse
OC1CONbits.OCTSEL = 0; // Select Timer 2 as output compare time base
OC1R = 0; // Load the Compare Register Value
OC1CONbits.OCM = 0b110; // Select the Output Compare mode

OC2CONbits.OCM = 0b000; // Disable Output Compare Module
OC2R = 0; // Write the duty cycle for the first PWM pulse
OC2RS = 12; // Write the duty cycle for the second PWM pulse
OC2CONbits.OCTSEL = 0; // Select Timer 2 as output compare time base
OC2R = 0; // Load the Compare Register Value
OC2CONbits.OCM = 0b110; // Select the Output Compare mode

// Initialize and enable Timer2
T2CONbits.TON = 0; // Disable Timer
T2CONbits.TCS = 0; // Select internal instruction cycle clock
T2CONbits.TGATE = 0; // Disable Gated Timer mode
T2CONbits.TCKPS = 0b00; // Select 1:1 Prescaler
TMR2 = 0x00; // Clear timer register
PR2 = 24; // Load the period value

IPC1bits.T2IP = 0x01; // Set Timer 2 Interrupt Priority Level
IFS0bits.T2IF = 0; // Clear Timer 2 Interrupt Flag
IEC0bits.T2IE = 1; // Enable Timer 2 interrupt
T2CONbits.TON = 1; // Start Timer

void __attribute__((__interrupt__)) _T2Interrupt( void )
{
    /* Interrupt Service Routine code goes here */
    OC1RS = 12;

    OC2RS = 12;
    IFS0bits.T2IF = 0; // Clear Timer 2 interrupt flag
}

Now I want the two PWM signals to be in 90 degree out of phase. Can anyone please tell me how to do it?


thanks in advance
 

No I am not...please help me to solve this problem

thanks in advance
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top