yokel
Junior Member level 3
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:
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
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