有个项目使用TuyaOS-3.8.1开发的,发现PWM 频率设置为4K的时候正常,设置为1KHz的时候,会出现异常,附录出现问题的部分代码片段,模块Log输出详情见附件。
Code: Select all
if(channel == 3) { /* channel is C */
uiCold = (UINT_T)(fPercent * uiPeriod);
TAL_PR_DEBUG("uiCold = %d, fPercent = %f, duty = %d", uiCold, fPercent, duty);
} else if(channel == 4) { /* channel is W */
if((uiCold == 0) && ((UINT_T)(fPercent * uiPeriod) == 0)) {
// tuya_pwm_stop(pChannelList[3],pChannelList[4]);
TUYA_CALL_ERR_LOG(tkl_pwm_multichannel_stop(&pChannelList[3], 2));
} else {
// tuya_pwm_reset_duty_cycle(pChannelList[3], pChannelList[4], uiCold, (UINT_T)(fPercent * uiPeriod), uiPeriod, 0);
TUYA_CALL_ERR_LOG(tkl_pwm_duty_set(pChannelList[3], uiCold));
TUYA_CALL_ERR_LOG(tkl_pwm_duty_set(pChannelList[4], (UINT_T)(fPercent * uiPeriod)));
TUYA_CALL_ERR_LOG(tkl_pwm_multichannel_start(&pChannelList[3], 2));
TAL_PR_DEBUG("uiCWarm = %d, fPercent = %f, duty = %d", (UINT_T)(fPercent * uiPeriod), fPercent, duty);
}
} else {