我正在同时启用多个 PWM,我不想复制粘贴代码 6 次,但我无法启用 6 个不同的 PWM,有效的代码是:
void pwmPinChoices(void){
pwm_channel_disable(PWM, PWM_CHANNEL_7);
pwm_pin6_instance.ul_prescaler = PWM_CMR_CPRE_CLKA;
pwm_pin6_instance.ul_period = 100;
pwm_pin6_instance.ul_duty = 50;
pwm_pin6_instance.channel = PWM_CHANNEL_7;
pwm_channel_init(PWM, &pwm_pin6_instance);
pio_set_peripheral(PIOC, PIO_PERIPH_B, PIO_PC24B_PWML7);
pwm_channel_enable(PWM, PWM_CHANNEL_7);
}
我希望能够更改 pwm_pinx_instance 和 pwm_channel_x,我尝试使用数组但它不起作用..
我试过的代码是:
void pwmChoices(void){
char ChlArr = [0, 1, 4, 5, 6, 7];
char PinArr = [34, 36, 6, 7, 8, 9];
for(int i = 0; i < 6; i++){
pwm_channel_disable(PWM, PWM_CHANNEL_ChlArr[i]);
pwm_PinArr[i]_instance.ul_prescaler = PWM_CMR_CPRE_CLKA;
pwm_PinArr[i]_instance.ul_period = 100;
pwm_PinArr[i]_instance.ul_duty = 50;
pwm_PinArr[i]_instance.channel = PWM_CHANNEL_ChlArr[i];
pwm_channel_init(PWM, &pwm_PinArr[i]_instance);
pio_set_peripheral(PIOC, PIO_PERIPH_B, PIO_PC24B_PWMLChlArr[i]);
pwm_channel_enable(PWM, PWM_CHANNEL_ChlArr[i]);
}
但是使用这段代码我得到了很多函数未声明的错误..