1. It fails like it does below
2. It will run somewhat correctly, though some hiccups which there are no activity
3. work correctly
Why is this so unreliable?
note this is a cpp file
Code: Select all
#include "pwm.h"
#include "freertos/task.h"
#include "freertos/FreeRTOS.h"
extern "C" {
void app_main(void);
}
void app_main(void) {
static constexpr mcpwm_unit_t mcpwm_unit = MCPWM_UNIT_0;
mcpwm_gpio_init(mcpwm_unit, MCPWM1A, 26);
mcpwm_group_set_resolution(mcpwm_unit, 1E6);
mcpwm_timer_set_resolution(mcpwm_unit, MCPWM_TIMER_1, 10E3);
mcpwm_config_t pwm_config_11 = {
.frequency = 10,
.cmpr_a = 50,
.cmpr_b = 0,
.duty_mode = MCPWM_DUTY_MODE_0,
.counter_mode = MCPWM_UP_COUNTER,
};
mcpwm_init(mcpwm_unit, MCPWM_TIMER_1, &pwm_config_11);
/* start is called inside init */
while (1) {
mcpwm_set_frequency(mcpwm_unit, MCPWM_TIMER_1, 10);
vTaskDelay(1000/ portTICK_RATE_MS);
mcpwm_set_frequency(mcpwm_unit, MCPWM_TIMER_1, 100);
vTaskDelay(1000/ portTICK_RATE_MS);
mcpwm_set_frequency(mcpwm_unit, MCPWM_TIMER_1, 1000);
vTaskDelay(1000/ portTICK_RATE_MS);
mcpwm_set_frequency(mcpwm_unit, MCPWM_TIMER_1, 5000);
vTaskDelay(1000/ portTICK_RATE_MS);
}
}