MCPWM example code for Interrupts on timer 0 TEZ and TEP

masterpo88
Posts: 1
Joined: Wed Jul 24, 2019 7:38 pm

MCPWM example code for Interrupts on timer 0 TEZ and TEP

Postby masterpo88 » Thu Jul 25, 2019 1:20 am

The Arduino1.8.9 code below generates 15.63kHz square waves on pins 12 and 14, prints out "mcpwm_test_072419". The mcpwm interrupt status register does not show timer0 events even though they must occur to generate the square waves output on pins 12 and 14. How do I get the TEZ and TEP event info?

#include <stdio.h>
#include <esp_log.h>
#include <esp_err.h>
#include <esp_intr.h>
#include <esp_intr_alloc.h>
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
#include <freertos/xtensa_api.h>
#include <freertos/task.h>
#include <soc/mcpwm_reg.h>
#include <soc/mcpwm_struct.h>
#include <soc/io_mux_reg.h>
#include <soc/gpio_sig_map.h>
#include <driver/mcpwm.h>
#include <driver/periph_ctrl.h>

static mcpwm_dev_t *MCPWM[2] = {&MCPWM0, &MCPWM1};
static const char *MCPWM_TAG = "MCPWM";
static portMUX_TYPE mcpwm_spinlock = portMUX_INITIALIZER_UNLOCKED;
float dutycycle = 50.0;
void setup()
{
Serial.begin(115200);
delay(1000);
Serial.println("mcpwm_test_072419");

mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, 12); //S1
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0B, 14); //S2
mcpwm_config_t off_grid_inv_pwm; //
off_grid_inv_pwm.frequency = 15360 * 2; // Up-Down mode requeires 2 periods of 15360Hz
off_grid_inv_pwm.cmpr_a = 50.0; //percent // S1 duty cycle is zero; S1 is OFF
off_grid_inv_pwm.cmpr_b = 50.0; //percent // S2 duty cycle is zero; S2 is OFF
off_grid_inv_pwm.duty_mode = MCPWM_DUTY_MODE_0; // active high
off_grid_inv_pwm.counter_mode = MCPWM_UP_DOWN_COUNTER; // up/down/symmetric
mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &off_grid_inv_pwm);
mcpwm_set_duty(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_B, dutycycle);
mcpwm_set_duty(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A, dutycycle);
}

void loop()
{
uint32_t mcpwm_intr_status;
//Poll for TEP and TEZ events
mcpwm_intr_status = MCPWM[MCPWM_UNIT_0]->int_st.val; //Read interrupt status
if(mcpwm_intr_status != 0)Serial.println(mcpwm_intr_status);
}

kodl1969
Posts: 1
Joined: Tue Oct 26, 2021 10:45 pm

Re: MCPWM example code for Interrupts on timer 0 TEZ and TEP

Postby kodl1969 » Tue Oct 26, 2021 11:09 pm

Hello, its best work. Fist searched example for real implementation MCPWM on ESP32...
Please help me in my project. I need generate 2 (3) phase shifted PWM signal for MPPT solar regulator with enhanced power. My source is: https://www.instructables.com/DIY-1kW-M ... ontroller/ - In this project used ledc for driving single phase powerstage. i need generate 2 (3) phase shifted pwm signal for driving mppt step down. Power stage hardware for any kW power is not problem... http://forum.mypower.cz/viewtopic.php?p=143517#p143517 - its powerstage of my LF 8kW inverter makeshift controled with EG8010 -its low price bad chineese controller for this using...
sorry for bad english...

Who is online

Users browsing this forum: No registered users and 128 guests