Re: dsPIC33CH128MP505 duty cycle not updating
2021/01/23 20:11:00
(permalink)
The pwm module is much more complicate on cH/CK chips than FJ/EP series .When updating PWM duty/frequency ,you have to set UPDREQ
Before you update duty cycle ,make sure the UPDTRG[1:0] in PGxEVTL has been correctly set .
The UPDTRG is default to 0b00 , which means you must set the UPDREQ bit (PGxSTAT[3]) manually, by so ,you have to set UPDREQ =1 after you write to PGxDC.
suggested code :
void hspwm2L_dc(uint16_t dc)
{
PWM2L_DC = dc;
PG2STATbits.UPDREQ = 1;
}
Or set UPDTRG = 0b01 ; // A write of the PGxDC register automatically sets the UPDREQ bit