Page 1 of 1

MCPWM assert failed

Posted: Thu Nov 09, 2023 7:56 pm
by nemka2008
I'm kind of new to the ESP-IDF framework and I get this error when I try to use the MCPWM API. I tried changing "period_ticks" and "resolution_hz" and i calculated the prescale and I was always inside the range of 0-256.

Currently I'm just testing how I works, but later I want to use it to drive 4 motors, that each require 2 PWM pins (one backward and one forward).

Code: Select all

#include "driver/mcpwm_prelude.h"
#include "driver/gpio.h"

//TIMER
mcpwm_timer_handle_t timer;

mcpwm_timer_config_t timer_config = {
   .group_id = 0,
   .clk_src = MCPWM_TIMER_CLK_SRC_PLL160M,  //MCPWM_TIMER_CLK_SRC_DEFAULT
   .resolution_hz = 1000,
   .count_mode = 0,
   .period_ticks = 1000,
   .flags = {
       .update_period_on_sync = true,
       .update_period_on_empty = false,
   },
};

//OPERATOR
mcpwm_oper_handle_t operator;

mcpwm_operator_config_t operator_config = {
	.group_id = 0
};
//GENERATOR
mcpwm_gen_handle_t generator;

mcpwm_generator_config_t generator_config = {
	.gen_gpio_num = 18,

};




void app_main()
{
	printf("Prescale: %u\n", prescale);


	mcpwm_new_timer(&timer_config, &timer);
	
	mcpwm_new_operator(&operator_config, &operator);

	mcpwm_operator_connect_timer(operator, timer);

	mcpwm_new_generator(operator, &generator_config, &generator);

	mcpwm_timer_enable(timer);

}
[Codebox]ELF file SHA256: 212f4cf8f7cfe2f5

Rebooting...
ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:7080
load:0x40078000,len:15584
load:0x40080400,len:4
0x40080400: _init at ??:?

0x400810f8: call_start_cpu1 at C:/Espressif/frameworks/esp-idf-v5.1.1/components/esp_system/port/cpu_start.c:154

0x4008172a: panic_abort at C:/Espressif/frameworks/esp-idf-v5.1.1/components/esp_system/panic.c:452

0x400857e1: esp_system_abort at C:/Espressif/frameworks/esp-idf-v5.1.1/components/esp_system/port/esp_system_chip.c:84

0x4008acd5: __assert_func at C:/Espressif/frameworks/esp-idf-v5.1.1/components/newlib/assert.c:81

0x400d6cdb: mcpwm_ll_timer_set_clock_prescale at C:/Espressif/frameworks/esp-idf-v5.1.1/components/hal/esp32/include/hal/mcpwm_ll.h:193 (discriminator 1)

0x400d6fa5: mcpwm_new_timer at C:/Espressif/frameworks/esp-idf-v5.1.1/components/driver/mcpwm/mcpwm_timer.c:109 (discriminator 2)

0x400d56eb: app_main at C:/Users/Luka/OneDrive - Srednja elektro racunalniska sola Maribor/Esspressif IDF Rescue maze 2024/Rescue maze 2024/main/main.c:104

0x400e57e8: main_task at C:/Espressif/frameworks/esp-idf-v5.1.1/components/freertos/app_startup.c:208 (discriminator 13)

0x40087c81: vPortTaskWrapper at C:/Espressif/frameworks/esp-idf-v5.1.1/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162

ho 8 tail 4 room 4
load:0x40080404,len:3876
entry 0x4008064c
I (31) boot: ESP-IDF v5.1.1 2nd stage bootloader
I (31) boot: compile time Nov 9 2023 19:58:03
I (31) boot: Multicore bootloader
I (35) boot: chip revision: v3.0
I (39) boot.esp32: SPI Speed : 40MHz
I (44) boot.esp32: SPI Mode : DIO
I (48) boot.esp32: SPI Flash Size : 2MB
I (53) boot: Enabling RNG early entropy source...
I (58) boot: Partition Table:
I (62) boot: ## Label Usage Type ST Offset Length
I (69) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (76) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (84) boot: 2 factory factory app 00 00 00010000 00100000
I (91) boot: End of partition table
I (96) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=0a328h ( 41768) map
I (119) esp_image: segment 1: paddr=0001a350 vaddr=3ffb0000 size=02178h ( 8568) load
I (123) esp_image: segment 2: paddr=0001c4d0 vaddr=40080000 size=03b48h ( 15176) load
I (131) esp_image: segment 3: paddr=00020020 vaddr=400d0020 size=15f78h ( 89976) map
I (166) esp_image: segment 4: paddr=00035fa0 vaddr=40083b48 size=08508h ( 34056) load
I (186) boot: Loaded app from partition at offset 0x10000
I (187) boot: Disabling RNG early entropy source...
I (198) cpu_start: Multicore app
I (198) cpu_start: Pro cpu up.
I (199) cpu_start: Starting app cpu, entry point is 0x400810f8
I (186) cpu_start: App cpu up.
I (217) cpu_start: Pro cpu start user code
I (217) cpu_start: cpu freq: 160000000 Hz
I (217) cpu_start: Application information:
I (221) cpu_start: Project name: app-template
I (227) cpu_start: App version: 1
I (231) cpu_start: Compile time: Nov 9 2023 20:16:19
I (237) cpu_start: ELF file SHA256: 212f4cf8f7cfe2f5...
I (243) cpu_start: ESP-IDF: v5.1.1
I (248) cpu_start: Min chip rev: v0.0
I (253) cpu_start: Max chip rev: v3.99
I (258) cpu_start: Chip rev: v3.0
I (263) heap_init: Initializing. RAM available for dynamic allocation:
I (270) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (276) heap_init: At 3FFB2A08 len 0002D5F8 (181 KiB): DRAM
I (282) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (288) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (295) heap_init: At 4008C050 len 00013FB0 (79 KiB): IRAM
I (302) spi_flash: detected chip: generic
I (305) spi_flash: flash io: dio
W (309) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (323) app_start: Starting scheduler on CPU0
I (328) app_start: Starting scheduler on CPU1
I (328) main_task: Started on CPU0
I (338) main_task: Calling app_main()

assert failed: mcpwm_ll_timer_set_clock_prescale /IDF/components/hal/esp32/include/hal/mcpwm_ll.h:193 (prescale <= 256 && prescale > 0)


Backtrace: 0x4008172a:0x3ffb4b10 0x400857e1:0x3ffb4b30 0x4008acd5:0x3ffb4b50 0x400d6cdb:0x3ffb4c70 0x400d6fa5:0x3ffb4ca0 0x400d56eb:0x3ffb4ce0 0x400e57e8:0x3ffb4d00 0x40087c81:0x3ffb4d30
[/Codebox]


Kind regards
Luka Zamuda