BLE芯片PHY6212---PWM两路调试

文章目录

前言

两路PWM驱动牙刷电机,一定情况下PHY6212存在复位且电机控制力度不足

软件上的排查

两路PWM波形输出理应为异步,原因在于采用了定时不断开启,关闭,长时间运行会导致定时精度不准确,导致同一时间两路都输出高或者低时,或者高,低同步的时间长,整体电流就会变高且对应的电机转动力度降低

处理

在配置PWM时不用定时器,两路采用相反的配置输出即可(附上测试demo),关键部分已框红

static uint8 key_TaskID;

#define PWM0_PIN P32
#define PWM1_PIN P33
#define PWM_TOP_VALUE 100

void PWM_Init(void)
{	

		hal_pwm_close_channel(PWM_CH0);
		hal_pwm_destroy(PWM_CH0);
		hal_pwm_close_channel(PWM_CH1);
		hal_pwm_destroy(PWM_CH1);
		hal_pwm_stop();
		hal_gpio_pin_init(PWM0_PIN, IE);
		hal_gpio_pin_init(PWM1_PIN, IE);//输入
    	hal_gpio_pull_set(PWM0_PIN,PULL_DOWN);//下拉
	 	hal_gpio_pull_set(PWM1_PIN,PULL_DOWN);
		hal_pwm_init(PWM_CH0, PWM_CLK_DIV_64, PWM_CNT_UP_AND_DOWN, PWM_POLARITY_FALLING);
		hal_pwm_set_count_val(PWM_CH0, 40, PWM_TOP_VALUE);
		hal_pwm_open_channel(PWM_CH0, PWM0_PIN);
	 	hal_pwm_init(PWM_CH1, PWM_CLK_DIV_64, PWM_CNT_UP_AND_DOWN, PWM_POLARITY_RISING);
		hal_pwm_set_count_val(PWM_CH1, 40, PWM_TOP_VALUE);
		hal_pwm_open_channel(PWM_CH1, PWM1_PIN);
		hal_pwm_start();
}				
void Key_Demo_Init(uint8 task_id)
{
    uint8_t i = 0;
    key_TaskID = task_id;
	PWM_Init();
	LOG("PWM_init\n");
}

PWM_POLARITY_FALLING 1
PWM_POLARITY_RISING 0

即可输出相反的PWM波形,效果如下
BLE芯片PHY6212---PWM两路调试

上一篇:BT401模块蓝牙音频ble芯片功耗实测说明


下一篇:ViewTool Hollong BLE Sniffer Support Linux OS Introduction