Part Number:TMS320F280049
现有8路PWM,其中,pwm1a,1b和pwm4a,4b为第一组;pwm2A ,2b和pwm3a,3b为第二组。第二组相对第一组移向180°。以pwm1为基准如何同步pwm2,pwm3,pwm4,按手册来配置无法做到信号同步输出。
Green Deng:
你好,这款芯片的同步信号,其中PWM 1/2/3是一组,也就是说,PWM2/3的同步信号来自PWM 1,而PWM4的同步信号也是来自PWM1的,而不是PWM3。
明白这点之后,其余的就是将PWM2/3在PWM1的基础上做移相了。不知道你的配置是否是这样的理念。
,
dengji liu:
我目前是你说的那种方式配置的,pwm2,3的同步信号来自pwm1,并且pwm4的同步信号也来自pwm1.移相已经实现了,就是第一个脉冲无法做到同步,有时第一个脉冲的周期是设定的3倍,有时候低一个脉冲的周期是设定脉冲的一半。我无法同步第一个脉冲的同步输出,其中pwm1B,2B,3B,4B都是由对应的pwm1a,2a,3a,4a互补生成的。我现在需要有PWM1A的输出同步其余7路pwm的输出。以下是我的配置文件。
void InitEPWM(void){ Gpio_Pwm_cfg(); PWM2_PWM3_Close(); //lop1 pwm关闭 PWM1_PWM4_Close(); //lop2 pwm关闭 SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC); // 关同步 Disable sync(Freeze clock to PWM as well) initEPWM2(); initEPWM3(); initEPWM1(); initEPWM4(); SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC); // 开同步 Enable sync and clock to PWM}void Gpio_Pwm_cfg(void){ // 设置 GPIO0/1 为 ePWM1A/1B GPIO_setPadConfig(0, GPIO_PIN_TYPE_PULLUP); GPIO_setPinConfig(GPIO_0_EPWM1A); GPIO_setPadConfig(1, GPIO_PIN_TYPE_PULLUP); GPIO_setPinConfig(GPIO_1_EPWM1B); // 设置 GPIO2/3 为 ePWM2A/2B GPIO_setPadConfig(2, GPIO_PIN_TYPE_PULLUP); GPIO_setPinConfig(GPIO_2_EPWM2A); GPIO_setPadConfig(3, GPIO_PIN_TYPE_PULLUP); GPIO_setPinConfig(GPIO_3_EPWM2B); // 设置 GPIO4/5 为 ePWM3A/3B GPIO_setPadConfig(4, GPIO_PIN_TYPE_PULLUP); GPIO_setPinConfig(GPIO_4_EPWM3A); GPIO_setPadConfig(5, GPIO_PIN_TYPE_PULLUP); GPIO_setPinConfig(GPIO_5_EPWM3B); // 设置 GPIO6/7 为 ePWM4A/4B GPIO_setPadConfig(6, GPIO_PIN_TYPE_PULLUP); GPIO_setPinConfig(GPIO_6_EPWM4A); GPIO_setPadConfig(7, GPIO_PIN_TYPE_PULLUP); GPIO_setPinConfig(GPIO_7_EPWM4B);}//EPWM1的初始化配置void initEPWM1() { EPWM_setClockPrescaler(EPWM1_BASE, EPWM_CLOCK_DIVIDER_1,EPWM_HSCLOCK_DIVIDER_1); //ePWM 时钟为100MHZ EPWM_setTimeBaseCounterMode(EPWM1_BASE,EPWM_COUNTER_MODE_UP_DOWN); //设置计数模式(增计数) EPWM_setTimeBaseCounter(EPWM1_BASE,0); //计数初始值设置 EPWM_setTimeBasePeriod(EPWM1_BASE,PWM_PERIOD); //计数周期 fs=100kHz(1000) EPWM_setPeriodLoadMode(EPWM1_BASE,EPWM_PERIOD_SHADOW_LOAD); EPWM_setCounterCompareShadowLoadMode(EPWM1_BASE, EPWM_COUNTER_COMPARE_A, EPWM_COMP_LOAD_ON_CNTR_ZERO); EPWM_disablePhaseShiftLoad(EPWM1_BASE); EPWM_setPhaseShift(EPWM1_BASE, 0U); EPWM_setCounterCompareValue(EPWM1_BASE,EPWM_COUNTER_COMPARE_A,EPWM1_MIN_CMPA); //设定比较值 EPWM_setCounterCompareValue(EPWM1_BASE,EPWM_COUNTER_COMPARE_B,EPWM1_MIN_CMPA); EPWM_setActionQualifierAction(EPWM1_BASE,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_LOW,EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA); EPWM_setActionQualifierAction(EPWM1_BASE,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_HIGH,EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA); EPWM_setActionQualifierAction(EPWM1_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_LOW,EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA); EPWM_setActionQualifierAction(EPWM1_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_HIGH,EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA); EPWM_setSyncOutPulseMode(EPWM1_BASE,EPWM_SYNC_OUT_PULSE_ON_COUNTER_ZERO); //计数到零时发出同步脉冲 EPWM_setRisingEdgeDeadBandDelayInput(EPWM1_BASE,EPWM_DB_INPUT_EPWMA); EPWM_setFallingEdgeDeadBandDelayInput(EPWM1_BASE,EPWM_DB_INPUT_EPWMA); //配置死区输入模式 EPWM_setDeadBandDelayPolarity(EPWM1_BASE,EPWM_DB_RED,EPWM_DB_POLARITY_ACTIVE_HIGH); EPWM_setDeadBandDelayPolarity(EPWM1_BASE,EPWM_DB_FED,EPWM_DB_POLARITY_ACTIVE_LOW);//配置极性 EPWM_setDeadBandDelayMode(EPWM1_BASE,EPWM_DB_RED,true); EPWM_setDeadBandDelayMode(EPWM1_BASE,EPWM_DB_FED,true); //配置输出模式 EPWM_setDeadBandOutputSwapMode(EPWM1_BASE,EPWM_DB_OUTPUT_A,false); EPWM_setDeadBandOutputSwapMode(EPWM1_BASE,EPWM_DB_OUTPUT_B,false); //输出不交换 EPWM_setRisingEdgeDelayCount(EPWM1_BASE, 80); //上升沿延时 EPWM_setFallingEdgeDelayCount(EPWM1_BASE,80); //下降沿延时 EPWM_enableADCTrigger(EPWM1_BASE,EPWM_SOC_A); EPWM_setADCTriggerSource(EPWM1_BASE,EPWM_SOC_A,EPWM_SOC_TBCTR_PERIOD); EPWM_setADCTriggerEventPrescale(EPWM1_BASE,EPWM_SOC_A,1); }//EPWM2的初始化配置void initEPWM2() { EPWM_setClockPrescaler(EPWM2_BASE, EPWM_CLOCK_DIVIDER_1, EPWM_HSCLOCK_DIVIDER_1); //ePWM 时钟为100MHZ EPWM_setTimeBaseCounterMode(EPWM2_BASE,EPWM_COUNTER_MODE_UP_DOWN); //设置计数模式(updown EPWM_setTimeBaseCounter(EPWM2_BASE,0); //计数初始值设置 EPWM_setTimeBasePeriod(EPWM2_BASE,PWM_PERIOD); //计数周期 EPWM_setPeriodLoadMode(EPWM2_BASE,EPWM_PERIOD_SHADOW_LOAD); //周期加载模式 EPWM_setCounterCompareShadowLoadMode(EPWM2_BASE, EPWM_COUNTER_COMPARE_A,EPWM_COMP_LOAD_ON_CNTR_ZERO); EPWM_setCounterCompareValue(EPWM2_BASE,EPWM_COUNTER_COMPARE_A,EPWM2_MIN_CMPA); //设定比较值 EPWM_setCounterCompareValue(EPWM2_BASE,EPWM_COUNTER_COMPARE_B,EPWM2_MIN_CMPA); EPWM_setActionQualifierAction(EPWM2_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_LOW,EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA); EPWM_setActionQualifierAction(EPWM2_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_HIGH,EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA); EPWM_setActionQualifierAction(EPWM2_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_LOW,EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA); EPWM_setActionQualifierAction(EPWM2_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_HIGH,EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA); EPWM_enablePhaseShiftLoad(EPWM2_BASE); //使能相位寄存器 EPWM_setSyncOutPulseMode(EPWM2_BASE,EPWM_SYNC_OUT_PULSE_ON_EPWMxSYNCIN); //计数到零时发出同步脉冲 EPWM_setPhaseShift(EPWM2_BASE,2000); EPWM_setRisingEdgeDeadBandDelayInput(EPWM2_BASE,EPWM_DB_INPUT_EPWMA); //互补生成PWMB EPWM_setFallingEdgeDeadBandDelayInput(EPWM2_BASE,EPWM_DB_INPUT_EPWMA); EPWM_setDeadBandDelayPolarity(EPWM2_BASE,EPWM_DB_RED,EPWM_DB_POLARITY_ACTIVE_HIGH); EPWM_setDeadBandDelayPolarity(EPWM2_BASE,EPWM_DB_FED,EPWM_DB_POLARITY_ACTIVE_LOW);//配置极性,这里实际上体现了PWMA和PWMB是互补的 EPWM_setDeadBandDelayMode(EPWM2_BASE,EPWM_DB_RED,true); EPWM_setDeadBandDelayMode(EPWM2_BASE,EPWM_DB_FED,true); //配置输出模式 EPWM_setDeadBandOutputSwapMode(EPWM2_BASE,EPWM_DB_OUTPUT_A,false); EPWM_setDeadBandOutputSwapMode(EPWM2_BASE,EPWM_DB_OUTPUT_B,false); //输出不交换 EPWM_setRisingEdgeDelayCount(EPWM2_BASE,80); //上升沿延时 EPWM_setFallingEdgeDelayCount(EPWM2_BASE,80); //下降沿延时 }//EPWM3的初始化配置void initEPWM3() { EPWM_setTimeBaseCounterMode(EPWM3_BASE, EPWM_COUNTER_MODE_UP_DOWN); EPWM_disablePhaseShiftLoad(EPWM3_BASE); EPWM_setClockPrescaler(EPWM3_BASE,EPWM_CLOCK_DIVIDER_1,EPWM_HSCLOCK_DIVIDER_1); EPWM_setTimeBasePeriod(EPWM3_BASE, PWM_PERIOD); EPWM_enablePhaseShiftLoad(EPWM3_BASE); //使能相位寄存器 EPWM_setSyncOutPulseMode(EPWM3_BASE,EPWM_SYNC_OUT_PULSE_ON_EPWMxSYNCIN); //计数到零时发出同步脉冲 EPWM_setPhaseShift(EPWM3_BASE, 2000); //移向180° EPWM_setTimeBaseCounter(EPWM3_BASE, 0); EPWM_setCounterCompareValue(EPWM3_BASE, EPWM_COUNTER_COMPARE_A,EPWM3_MIN_CMPA); EPWM_setCounterCompareValue(EPWM3_BASE, EPWM_COUNTER_COMPARE_B,EPWM3_MIN_CMPA); EPWM_setPeriodLoadMode(EPWM3_BASE,EPWM_PERIOD_SHADOW_LOAD); //周期加载模式 EPWM_setCounterCompareShadowLoadMode(EPWM3_BASE, EPWM_COUNTER_COMPARE_A, EPWM_COMP_LOAD_ON_CNTR_ZERO);//比较值加载模式 EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_LOW,EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA); EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_HIGH,EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA); EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_LOW,EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA); EPWM_setActionQualifierAction(EPWM3_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_HIGH,EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA); EPWM_setRisingEdgeDeadBandDelayInput(EPWM3_BASE,EPWM_DB_INPUT_EPWMA); EPWM_setFallingEdgeDeadBandDelayInput(EPWM3_BASE,EPWM_DB_INPUT_EPWMA); //配置死区输入模式 EPWM_setDeadBandDelayPolarity(EPWM3_BASE,EPWM_DB_RED,EPWM_DB_POLARITY_ACTIVE_HIGH); EPWM_setDeadBandDelayPolarity(EPWM3_BASE,EPWM_DB_FED,EPWM_DB_POLARITY_ACTIVE_LOW);//配置极性 EPWM_setDeadBandDelayMode(EPWM3_BASE,EPWM_DB_RED,true); EPWM_setDeadBandDelayMode(EPWM3_BASE,EPWM_DB_FED,true); //配置输出模式经过死区 EPWM_setDeadBandOutputSwapMode(EPWM3_BASE,EPWM_DB_OUTPUT_A,false); EPWM_setDeadBandOutputSwapMode(EPWM3_BASE,EPWM_DB_OUTPUT_B,false); //输出不交换 EPWM_setRisingEdgeDelayCount(EPWM3_BASE,80); //上升沿延时 EPWM_setFallingEdgeDelayCount(EPWM3_BASE,80); //下降沿延时 }//EPWM4的初始化配置void initEPWM4() { EPWM_setTimeBasePeriod(EPWM4_BASE, PWM_PERIOD); EPWM_enablePhaseShiftLoad(EPWM4_BASE); //使能相位寄存器 EPWM_setSyncOutPulseMode(EPWM4_BASE,EPWM_SYNC_OUT_PULSE_ON_EPWMxSYNCIN); //计数到零时发出同步脉冲 EPWM_setPhaseShift(EPWM4_BASE, 0); EPWM_setTimeBaseCounter(EPWM4_BASE, 0U); EPWM_setCounterCompareValue(EPWM4_BASE, EPWM_COUNTER_COMPARE_A,EPWM4_MIN_CMPA); EPWM_setCounterCompareValue(EPWM4_BASE, EPWM_COUNTER_COMPARE_B,EPWM4_MIN_CMPA); EPWM_setTimeBaseCounterMode(EPWM4_BASE, EPWM_COUNTER_MODE_UP_DOWN); EPWM_disablePhaseShiftLoad(EPWM4_BASE); EPWM_setClockPrescaler(EPWM4_BASE,EPWM_CLOCK_DIVIDER_1,EPWM_HSCLOCK_DIVIDER_1); EPWM_setPeriodLoadMode(EPWM4_BASE,EPWM_PERIOD_SHADOW_LOAD); //周期加载模式 EPWM_setCounterCompareShadowLoadMode(EPWM4_BASE, EPWM_COUNTER_COMPARE_A, EPWM_COMP_LOAD_ON_CNTR_ZERO);//比较值加载模式 EPWM_setActionQualifierAction(EPWM4_BASE,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_LOW,EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA); EPWM_setActionQualifierAction(EPWM4_BASE,EPWM_AQ_OUTPUT_A,EPWM_AQ_OUTPUT_HIGH,EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);//pwm4A==1 EPWM_setActionQualifierAction(EPWM4_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_LOW,EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA); EPWM_setActionQualifierAction(EPWM4_BASE,EPWM_AQ_OUTPUT_B,EPWM_AQ_OUTPUT_HIGH,EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);//pwm4b==0 EPWM_setRisingEdgeDeadBandDelayInput(EPWM4_BASE,EPWM_DB_INPUT_EPWMA); EPWM_setFallingEdgeDeadBandDelayInput(EPWM4_BASE,EPWM_DB_INPUT_EPWMA); //配置死区输入模式 S4,S5=0 EPWM_setDeadBandDelayPolarity(EPWM4_BASE,EPWM_DB_RED,EPWM_DB_POLARITY_ACTIVE_HIGH); EPWM_setDeadBandDelayPolarity(EPWM4_BASE,EPWM_DB_FED,EPWM_DB_POLARITY_ACTIVE_LOW);//配置极性 EPWM_setDeadBandDelayMode(EPWM4_BASE,EPWM_DB_RED,true); EPWM_setDeadBandDelayMode(EPWM4_BASE,EPWM_DB_FED,true); //配置输出模式 EPWM_setDeadBandOutputSwapMode(EPWM4_BASE,EPWM_DB_OUTPUT_A,false); EPWM_setDeadBandOutputSwapMode(EPWM4_BASE,EPWM_DB_OUTPUT_B,false); //输出不交换 EPWM_setRisingEdgeDelayCount(EPWM4_BASE,80); //上升沿延时 EPWM_setFallingEdgeDelayCount(EPWM4_BASE,80); //下降沿延时 }
,
Green Deng:
具体是PWM1的第一个脉冲不固定还是同步的PWM2/3/4的第一个脉冲不固定?
另外,这个情况我也咨询了其他工程师,会一起帮忙看一下这个问题。
,
dengji liu:
pwm1,2,3,4的第一个脉冲都不固定
,
Green Deng:
抱歉最近帖子多来不及回复,我把你的问题发布到英文E2E论坛了,有工程师问到一些细节,你看一下:e2e.ti.com/…/tms320f280049-question-about-pwm-synchronization