主题中讨论的其他器件:TMS320F28379D
大家好、
我正在尝试将 PWM3B 同步到一个外部脉冲序列、这样外部信号的下降边沿将 PWM 时基计数器设定为零。
我没有使用外部 SYNC 引脚、因为它已经被用于将 PWM1和2同步到 一个不同的同步方案。
我尝试通过数字比较模块处理 TZ1#以驱动同步事件信号、但由于某种原因、产生的 PWM 似乎在随机位置同步。 如果我注释掉设置的数字比较部分、问题就不存在(但当然没有同步)。
也许同步事件会在外部信号为低电平时而不是第一次检测到为低电平时一直升高?
此时我的 PWM 设置代码:
GPIO_Handle GPIO = GPIO_init ((void *) GPIO_base_ADDR、sizeof (GPIO_Obj); PWM_Handle PWM = PWM_init (PWM_ISHR_PWM_base_address、sizeof (PWM_Obj))); //将 GPIO 配置为 TZ#输入。 /GPIO_setDirection (GPIO、GPIO_Number_12、GPIO_Direction_Input); GPIO_setPullup (GPIO、GPIO_Number_12、 GPIO_PULLUP_Enable); GPIO_setLow (GPIO、GPIO_Number_12); GPIO_setMode (GPIO、GPIO_Number_12、GPIO_12_Mode_TZ1_NOT); //将 GPIO 配置为 PWM 输出。 /GPIO_setDirection (GPIO、GPIO_Number_5、GPIO_Direction_Output); GPIO_setPullup (GPIO、GPIO_Number_5、 GPIO_PULLUP_Enable); GPIO_setLow (GPIO、GPIO_Number_5); GPIO_setMode (GPIO、GPIO_Number_5、GPIO_0_Mode_EPWM1A); /*时基子模块。 */ PWM_setSyncMode (PWM、PWM_SyncMode_Disable); PWM_enableCounterLoad (PWM); PWM_setPhase (PWM、0U); PWM_setPeriodLoad (PWM、PWM_PeriodLoad_Immediate); PWM_setPeriod (PWM、59999); PWM_setCount (PWM、0U); PWM_setCounterMode (PWM、PWM_CounterMode_Up); PWM_setHighSpeedClkDiv (PWM、 PWM_HspClkDiv_BY_1); PWM_setClkDiv (PWM、PWM_ClkDiv_BY_1); //计数器比较子模块。 // PWM_setCmpA (PWM、0U); PWM_setCmpB (PWM、30000);//开始时占空比为50%。 /PWM_setShadowImage Mode_CMPB (PWM、PWM_ShadowImage Mode_Shadow); PWM_setLoadMode_CMPB (PWM、PWM_LoadMode_Zero); /* Action 限定符子模块。 /PWM_setActionQUAL_Zero_PwmA (PWM、PWM_ActionQual_Disabled); PWM_setActionQual_CntUp_CMPB_PwmA (PWM、PWM_ActionQual_Disabled); PWM_setActionQual_Period_PwmA (PWM、 PWM_ActionQUAL_Disabled); PWM_setActionQUAL_Zero_PwmB (PWM、PWM_ActionQual_set); PWM_setActionQual_CntUp_CMPB_PwmB (PWM、PWM_ActionQual_clear); //跳匣区域子模块。 /PWM_setTripZoneState_DCAEVT1 (PWM、PWM_TripZoneState_DoNothing); PWM_setTripZoneState_DCAEVT2 (PWM、PWM_TripZoneState_DoNothing); PWM_setTripZoneState_DCBEVT1 (PWM、 PWM_TripZoneState_DoNothing); PWM_setTripZoneState_DCBEVT2 (PWM、PWM_TripZoneState_DoNothing); PWM_setTripZoneState_TZA (PWM、PWM_TripZoneState_DoNothing); PWM_setTripZoneState_TZB (PWM、PWM_TripZoneState_DoNothing); //数字比较子模块。 // PWM_setDigitalCompareInput (PWM、PWM_DigitalCompare_A_High、PWM_DigitalCompare_InputSel_TZ1);//为 DCAH 输入选择 TZ1#。 // PWM_setTripZoneDCEventSelect_DCAEVT1 (PWM、PWM_TripZoneDCEventSel_DCxHL_DCxLX);//将 DCAEVT 设置为 DCAH =低电平、DCAL =无关。 // PWM_DisableDigitalCompareBlankingWindow (PWM); //设置事件参数:使用未过滤的事件信号,信号不是异步的,不生成 SOC,生成同步信号。 /PWM_setDigitalCompareAEvent1 (PWM、false、false、false、true); /*通过强制同步启动 PWM。 */ PWM_forceSync (ishrHandle->PWM);