mcpwm控制舵机触发看门狗问题

caesarken
Posts: 2
Joined: Thu Sep 01, 2022 3:48 am

mcpwm控制舵机触发看门狗问题

Postby caesarken » Thu Sep 01, 2022 3:57 am

  1. #include <stdio.h>
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4. #include "driver/gpio.h"
  5. #include "esp_log.h"
  6. #include "led_strip.h"
  7. #include "sdkconfig.h"
  8. #include "driver/ledc.h"
  9. #include "driver/mcpwm.h"
  10.  
  11.     printf("start.......");
  12.     //初始化pwm引脚
  13.     mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, 18);
  14.  
  15.     //初始化pwm配置结构
  16.     mcpwm_config_t pwm_config = {
  17.         .frequency = 100, // frequency = 50Hz, i.e. for every servo motor time period should be 20ms
  18.         .cmpr_a = 0,      // duty cycle of PWMxA = 0
  19.         .counter_mode = MCPWM_UP_COUNTER,
  20.         .duty_mode = MCPWM_DUTY_MODE_1,//
  21.     };
  22.     //初始化pwm配置
  23.     mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &pwm_config);
  24.     //设置对应 pwm单位、定时器、通道的空占比
  25.     mcpwm_set_duty_type(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_GEN_A, MCPWM_DUTY_MODE_0);
  26.     int t = 0;
  27.     bool dir = true;
  28.     bool predir = false;
  29.     mcpwm_set_duty_in_us(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_GEN_A, 1833);
代码是正常的,也能正常控制舵机。
我发生的问题是这样的,舵机已经稳定在某个角度,这时候我想试一下舵机的力度,于是手动去转动舵机的轴……然后舵机就开始不稳定,触发了看门狗,舵机一直在校正(控制台能看见,系统一直在快速重启),大概过了几秒才稳定下来。

在使用micropython都没有发生这样的问题…… 是不是哪里没有配置到?

Who is online

Users browsing this forum: No registered users and 48 guests