Open sova32 opened 1 week ago
@sova32 you copied the example_main.c, but didn't copy the Kconfig file. example_setup_sync_strategy
has three different implementations, controlled by how you select the Where the sync event is generated from"
from the Kconfig.
your official code dont work!!!
https://github.com/espressif/esp-idf/blob/v5.3.1/examples/peripherals/mcpwm/mcpwm_sync/main/mcpwm_sync_example_main.c
/*
include "sdkconfig.h"
include "freertos/FreeRTOS.h"
include "freertos/task.h"
include "esp_log.h"
include "driver/mcpwm_prelude.h"
include "driver/gpio.h"
const static char *TAG = "example";
define EXAMPLE_TIMER_RESOLUTION_HZ 1000000 // 1MHz, 1us per tick
define EXAMPLE_TIMER_PERIOD 1000 // 1000 ticks, 1ms
define EXAMPLE_GEN_GPIO0 0
define EXAMPLE_GEN_GPIO1 2
define EXAMPLE_GEN_GPIO2 4
define EXAMPLE_SYNC_GPIO 5
if CONFIG_EXAMPLE_SYNC_FROM_GPIO
static void example_setup_sync_strategy(mcpwm_timer_handle_t timers[]) { // +----GPIO----+ // | | | // | | | // v v v // timer0 timer1 timer2 ESP_LOGI(TAG, "Create GPIO sync source"); mcpwm_sync_handle_t gpio_sync_source = NULL; mcpwm_gpio_sync_src_config_t gpio_sync_config = { .group_id = 0, // GPIO fault should be in the same group of the above timers .gpio_num = EXAMPLE_SYNC_GPIO, .flags.pull_down = true, .flags.active_neg = false, // by default, a posedge pulse can trigger a sync event .flags.io_loop_back = true, // then we can trigger a sync event using
gpio_set_level
on the same GPIO }; ESP_ERROR_CHECK(mcpwm_new_gpio_sync_src(&gpio_sync_config, &gpio_sync_source));}
endif // CONFIG_EXAMPLE_SYNC_FROM_GPIO
if CONFIG_EXAMPLE_SYNC_FROM_TEZ
static void example_setup_sync_strategy(mcpwm_timer_handle_t timers[]) { // +->timer1 // (TEZ) | // timer0---+ // | // +->timer2 ESP_LOGI(TAG, "Create TEZ sync source from timer0"); mcpwm_sync_handle_t timer_sync_source = NULL; mcpwm_timer_sync_src_config_t timer_sync_config = { .timer_event = MCPWM_TIMER_EVENT_EMPTY, // generate sync event on timer empty }; ESP_ERROR_CHECK(mcpwm_new_timer_sync_src(timers[0], &timer_sync_config, &timer_sync_source));
}
endif // CONFIG_EXAMPLE_SYNC_FROM_TEZ
if CONFIG_EXAMPLE_SYNC_FROM_SOFT
static void example_setup_sync_strategy(mcpwm_timer_handle_t timers[]) { // soft // | // v // +-timer0--+ // | | // v v // timer1 timer2 ESP_LOGI(TAG, "Create software sync source"); mcpwm_sync_handle_t soft_sync_source = NULL; mcpwm_soft_sync_config_t soft_sync_config = {}; ESP_ERROR_CHECK(mcpwm_new_soft_sync_src(&soft_sync_config, &soft_sync_source));
}
endif // CONFIG_EXAMPLE_SYNC_FROM_SOFT
void app_main(void) { ESP_LOGI(TAG, "Create timers"); mcpwm_timer_handle_t timers[3]; mcpwm_timer_config_t timer_config = { .clk_src = MCPWM_TIMER_CLK_SRC_DEFAULT, .group_id = 0, .resolution_hz = EXAMPLE_TIMER_RESOLUTION_HZ, .period_ticks = EXAMPLE_TIMER_PERIOD, .count_mode = MCPWM_TIMER_COUNT_MODE_UP, }; for (int i = 0; i < 3; i++) { ESP_ERROR_CHECK(mcpwm_new_timer(&timer_config, &timers[i])); }
}
/run/media/vadiki/250_GB_ST_1GB/projects/filamentor_v2/program/main/main.c: In function 'app_main': /run/media/vadiki/250_GB_ST_1GB/projects/filamentor_v2/program/main/main.c:201:5: error: implicit declaration of function 'example_setup_sync_strategy' [-Werror=implicit-function-declaration] 201 | example_setup_sync_strategy(timers); | ^
~~~~~~ cc1: some warnings being treated as errors ninja: build stopped: subcommand failed.