High-Speed PWM Odd Signal When Disabled
I am using the High-Speed PWM module on the dsPIC33EP64GS506. I am using PWM1H/L and PWM3H/L. When enabled and running everything works as expected. However, there are times that I want to disable the module, that is, I want all 4 PWM pins (1L,1H,3L,3H) to output 0V. I can achieve this for PWM1 by disabling the PWM module altogether (i.e. PTCONbits.PTEN = 0). But when I do this, the signal on the output of PWM3 is odd. PWM3H is a very noisy signal that sits at around 2.8V and PWM3L is a signal that sits at around 0.5V.
I currently do a work around to "disable" the PWM signals by writing 0 to PDC1 and PDC3, but this isn't the correct thing to do. Is there a better way to disable the PWM signals? I don't see that I am doing anything different in the software between PWM1 and PWM3.
It is worth noting that the PWM3 signals are currently open and not connected to anything and I still get the same issue. It is also worth noting that before I enable the PWM module (i.e. PTCONbits.PTEN = 1) PWM3H/L are at 0V. They only go to an uncertain state after asserting and then dis-asserting the PTEN bit.
My PWM initialization routine looks like this (where max_pwm_val is an int~=3000):
PTCON2bits.PCLKDIV = 0; //PWM time base prescaller 1:1
PWMCON1bits.CAM = 1; //Center align mode
PWMCON1bits.ITB = 1; //Independent Time base PHASEx/SPHASEx (needed for center)
PWMCON1bits.MDCS = 0; //PDCx/SDCx provide duty
PWMCON1bits.DTC = 0; //Positive Dead-Time
PWMCON3bits.CAM = 1;
PWMCON3bits.ITB = 1;
PWMCON3bits.MDCS = 0;
PWMCON3bits.DTC = 0;
PWMKEY = 0x0;
__builtin_write_PWMSFR(&IOCON1, 0xC000, &PWMKEY);
__builtin_write_PWMSFR(&FCLCON1, 0x408, &PWMKEY);
__builtin_write_PWMSFR(&IOCON2, 0x0000, &PWMKEY); //Disable PWM2H/L
__builtin_write_PWMSFR(&IOCON3, 0xC000, &PWMKEY);
__builtin_write_PWMSFR(&FCLCON3, 0x408, &PWMKEY);
__builtin_write_PWMSFR(&IOCON4, 0x0, &PWMKEY); //Disable PWM4H/L
__builtin_write_PWMSFR(&IOCON5, 0x0, &PWMKEY); //Disable PWM5H/L
PDC1 = max_pwm_val/2;
PHASE1 = max_pwm_val; //Period for PWM1H, 300 kHz; 1592
ALTDTR1 = 100; //Dead-Time is 10 ns
PDC3 = max_pwm_val/2;
PHASE3 = max_pwm_val;
ALTDTR3 = 100;
It may also be worth noting that I am setting the TRIS register so that they are outputs.
TRISA = 0x0007;
TRISB = 0x27CB;
(PWM3H -> RB11, PWM3L -> RB12, PWM1H -> RA4, PWM1L -> RA3).