Re: [求助]SDK版本升级后,PWM功能失效
Posted: 2023年 Dec 21日 17:58
1.请确认是在 3.8.0框架下添加app后进行编译的结果,除app路径外其余没有进行修改
2.请贴下pwm初始化和pwm设置duty 程序代码
1.请确认是在 3.8.0框架下添加app后进行编译的结果,除app路径外其余没有进行修改
2.请贴下pwm初始化和pwm设置duty 程序代码
好的,我知道了。初始化完成后tal_pwm_init()(初始化函数中,将频率值赋值给了g_pwm_precision数组),调用tkl_pwm_precision_set()这个函数,将precision设置值为1000,重新覆盖g_pwm_precision。将精度改回来。600,就对应的脉冲频率为60%
感谢!!!
huanghuan 2023年 Dec 21日 17:581.请确认是在 3.8.0框架下添加app后进行编译的结果,除app路径外其余没有进行修改
2.请贴下pwm初始化和pwm设置duty 程序代码
1.是的,直接将app拷贝到3.8.0框架下编译的。
Code: Select all
//pwm初始化
OPERATE_RET app_pwm_init(VOID_T)
{
OPERATE_RET v_ret = OPRT_COM_ERROR;
APP_DATA_T app_kv_data;
TUYA_PWM_BASE_CFG_T v_cfg;
tkl_pwm_mapping_to_gpio((UINT32_T)TUYA_PWM_NUM_0, USER_PWM_CH1_PIN); //PD2
tkl_pwm_mapping_to_gpio((UINT32_T)TUYA_PWM_NUM_1, USER_PWM_CH2_PIN); //PC3
tkl_pwm_mapping_to_gpio((UINT32_T)TUYA_PWM_NUM_2, USER_PWM_CH3_PIN); //PB4
tkl_pwm_mapping_to_gpio((UINT32_T)TUYA_PWM_NUM_3, USER_PWM_CH4_PIN); //PB5
UINT8_T ch;
for(ch=0; ch < PWM_CHANNEL_NUM; ch++){
tal_system_memset(&app_kv_data, 0, sizeof(APP_DATA_T));
tal_system_memset(&v_cfg, 0, sizeof(TUYA_PWM_BASE_CFG_T));
app_light_ctrl_data_switch_get(ch, &app_kv_data.onoff);
app_light_ctrl_data_bright_get(ch, &app_kv_data.bright);
if(app_kv_data.onoff == 0) v_cfg.duty = 0;
else v_cfg.duty = app_kv_data.bright;
v_cfg.frequency = pwm_frequency;
v_cfg.polarity = pwm_polarity;
tkl_pwm_init(ch, &v_cfg);
}
//启动pwm
v_ret = tkl_pwm_start(TUYA_PWM_NUM_0);
if(v_ret != OPRT_OK){
TAL_PR_ERR("!!!!!!!!!!!!!!!!!!!!!! PC1 mapping start !!!!!!!!!!!!!!!!!!!!!!");
}
v_ret = tkl_pwm_start(TUYA_PWM_NUM_1);
if(v_ret != OPRT_OK){
TAL_PR_ERR("!!!!!!!!!!!!!!!!!!!!!! PC4 mapping start !!!!!!!!!!!!!!!!!!!!!!");
}
v_ret = tkl_pwm_start(TUYA_PWM_NUM_2);
if(v_ret != OPRT_OK){
TAL_PR_ERR("!!!!!!!!!!!!!!!!!!!!!! PB4 mapping start !!!!!!!!!!!!!!!!!!!!!!");
}
v_ret = tkl_pwm_start(TUYA_PWM_NUM_3);
if(v_ret != OPRT_OK){
TAL_PR_ERR("!!!!!!!!!!!!!!!!!!!!!! PD2 mapping start !!!!!!!!!!!!!!!!!!!!!!");
}
g_user_pwm_init_flag = TRUE; //pwm初始化标志
g_pwm_bPolarity = pwm_polarity; //pwm极性标志
app_light_ctrl_ch_num_set(PWM_CHANNEL_NUM); //设置pwm通道数
TAL_PR_DEBUG("pwm init ok!");
return v_ret;
}
//更改duty
STATIC VOID_T __app_ctrl_pwm_duty_set(UCHAR_T channel, USHORT_T duty)
{
//TAL_PR_DEBUG("channel = %d , duty = %d\n", channel, duty);
if (duty > MAX_DUTY)
{
TAL_PR_DEBUG("PWM SET DUTY ERR");
return;
}
if (channel >= sg_light_channel)
{
TAL_PR_DEBUG("PWM SET DUTY CHANNEL ERR");
return;
}
if (OPRT_OK != tal_pwm_duty_set((TUYA_PWM_NUM_E)channel, duty))
{
TAL_PR_DEBUG("PWM SET DUTY ERR");
return;
}
}