mcpwm unrealiable, gets stuck

msilverman
Posts: 3
Joined: Mon Nov 28, 2022 2:03 am

mcpwm unrealiable, gets stuck

Postby msilverman » Tue Jan 10, 2023 12:58 pm

I am having issue with basic usage of the mcpwm module. In the code below, I am varying the frequency on the fly. In the waveform below, you can see that it is stuck. If I power cycle it one of three things will happen:
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);
	}
}
Image

Who is online

Users browsing this forum: No registered users and 132 guests