我正在研究三相逆变器,并且正在使用空间矢量pwm,但是在使用SVPWM之前,我需要生成准平方波,为此,我需要有6个引脚来输出同一时期。
我在arduino duo中成功同步了三个通道,并为每个通道输出互补输出。我现在需要做的是在每个周期结束时更改每个通道的占空比。可以在周期结束时使用中断来实现,但是我在理解如何配置Duo来处理中断和更改占空比方面遇到困难。以下是我已经拥有的。
void setup() {
PMC->PMC_PCER1 |= PMC_PCER1_PID36; //Enable PWM (Power On)
PWM->PWM_DIS = PWM_DIS_CHID0; //Disable PWM on Channel 0
PIOC->PIO_PDR |= PIO_PDR_P3 | PIO_PDR_P5 | PIO_PDR_P7; // Setting pins 3,5,7
(DUE Pins 35, 37, 39) to PWM Peripheral, not GPIO
PIOC->PIO_ABSR |= PIO_PC3B_PWMH0 | PIO_PC5B_PWMH1 | PIO_PC7B_PWMH2; // Setting pins to Peripheral B
PIOC->PIO_PDR |= PIO_PDR_P2 | PIO_PDR_P4 | PIO_PDR_P6; // Setting pins 2,4,6 (DUE Pins 34, 36, 38) to PWM Peripheral, not GPIO
PIOC->PIO_ABSR |= PIO_PC2B_PWML0 | PIO_PC4B_PWML1 | PIO_PC6B_PWML2; // Setting pins to Peripheral B
PWM->PWM_CLK = PWM_CLK_PREA(0) | PWM_CLK_DIVA(42); //Set PWM clocke rate to 2MHz (84MHz/42)
PWM->PWM_CH_NUM[0].PWM_CMR = PWM_CMR_CPRE_CLKA; // Period is left aligned,clock source is CLKA on Channel 0
REG_PWM_SCM |= PWM_SCM_SYNC0 | PWM_SCM_SYNC1 | PWM_SCM_SYNC2; // Synchronizing of Channels 0, 1 and 2
REG_PWM_CPRD0 = 1000000; //Channel 0 Period f = 2MHz/(2*CPRD)
REG_PWM_CDTY0 = 0; //Channel 0 Duty Cycle x% = (CDTY/ CPRD)*100%
REG_PWM_CPRD1 = 1000000;
REG_PWM_CDTY1 = 1000000;
REG_PWM_CPRD2 = 1000000;
REG_PWM_CDTY2 = 0;
PWM->PWM_ENA = PWM_ENA_CHID0; // Enable PWM on Channel 0
}
void loop() {
// put your main code here, to run repeatedly:
}