PWMA 初始化:
PESL(PWM_A, PWM_SET_MODULO, 0x4e20);
PESL(PWM_A, PWM_SET_DEADTIME, 0x00e0);
PESL(PWM_A, PWM_WRITE_VALUE_REG_0, 0x0000);
PESL(PWM_A, PWM_WRITE_VALUE_REG_1, 0x0000);
PESL(PWM_A, PWM_WRITE_VALUE_REG_2, 0x0000);
PESL(PWM_A, PWM_WRITE_VALUE_REG_3, 0x0000);
PESL(PWM_A, PWM_WRITE_VALUE_REG_4, 0x0000);
PESL(PWM_A, PWM_WRITE_VALUE_REG_5, 0x0000);
PESL(PWM_A, PWM_WRITE_DISABLE_MAPPING_REG1, 0);
PESL(PWM_A, PWM_WRITE_DISABLE_MAPPING_REG2, 0);
PESL(PWM_A, PWM_SET_ALIGNMENT, PWM_ALIGN_CENTER);
PESL(PWM_A, PWM_SET_COMPLEMENTARY_MODE, PWM_CHANNEL_45 | PWM_CHANNEL_23 | PWM_CHANNEL_01);
PESL(PWM_A, PWM_OUTPUT_PAD, PWM_ENABLE);
PESL(PWM_A, PWM_RELOAD_INT, PWM_ENABLE);
PESL(PWM_A, PWM_DEVICE, PWM_ENABLE);
PESL(PWM_A, PWM_LOAD_OK, NULL);
定时中断中计算duty cycle:
duty_cycle_1 = 0x4e20 + mult_r(0x4e20,mult_r(modulation_index,sin_vAsh));
我设置的是 center aligned pwm 模式。
PWM reload 更新 duty cycle:
#pragma interrupt saveall
void PWMReload_Interrupt(void)
{
GPIOB6_NegVal();
PESL(PWM_A, PWM_UPDATE_VALUE_REG_0, duty_cycle_1);
PESL(PWM_A, PWM_CLEAR_RELOAD_FLAG, NULL);
PESL(PWM_A, PWM_LOAD_OK, NULL);
}
|