Page 1 of 1

mcpwm_isr_register does not execute command

Posted: Fri Feb 10, 2023 9:45 pm
by sevi_at
I have the problem that the command mcpwm_isr_register does not execute the interrupt command.

Code: Select all

//#include <driver/dma.h>
#include <driver/gpio.h>
#include <driver/adc.h>
#include <esp_adc_cal.h>
#include <driver/mcpwm.h>

portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;

// PWM
#define PWM1_Ch       0
#define PWM1_Res      10     // 10 bits = 1024 levels = 0,05859375A per step
#define PWM1_Freq     1000   // 980 - 1020 range, 1000 nominal
int PWM1_DutyCycle =  1000;  // 0= -12V  1000= 12V

// ADC-Kanal für die Verwendung definieren
#define ADC1_GPIO35_CHANNEL ADC1_CHANNEL_7
#define ADC_CHANNEL ADC1_CHANNEL_7
#define ADC_WIDTH ADC_WIDTH_BIT_12
#define ADC_ATTEN ADC_ATTEN_DB_11
#define ADC_VREF 1100
esp_adc_cal_characteristics_t adc_chars;

void IRAM_ATTR pwmHigh(void*) 
{
   portENTER_CRITICAL_ISR(&timerMux);
   
  // ADC-Messwert abfragen
  raw_value = adc1_get_raw((adc1_channel_t)ADC_CHANNEL);
  // Berechnen des Spannungswerts aus dem ADC-Messwert
  voltage = esp_adc_cal_raw_to_voltage(raw_value, &adc_chars);

 Serial.printf("\r\nInterrupt:", voltage); 
  
   portEXIT_CRITICAL_ISR(&timerMux);
}

void TaskCP(void*) {
  VOID SETUP() { ////////////////////////////////////////// SETUP //////////////////////////////////////////

 adc1_config_width(ADC_WIDTH_BIT_12);
 adc1_config_channel_atten(ADC1_GPIO35_CHANNEL, ADC_ATTEN_DB_11); 
 esp_adc_cal_value_t val_type = esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN, ADC_WIDTH, ADC_VREF, &adc_chars);

    // Hier kann man die Pin-Belegung für PWM und ADC festlegen
    mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, CTRL_PILOT);
    
    // Hier wird der PWM-Signalgenerator konfiguriert
    mcpwm_config_t pwm_config;
    pwm_config.frequency = 1000;  // 1kHz
    pwm_config.cmpr_a = 50;       // Duty-Cycle von 50%
    pwm_config.counter_mode = MCPWM_UP_COUNTER;
    pwm_config.duty_mode = MCPWM_DUTY_MODE_0;
    mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &pwm_config);
    mcpwm_start(MCPWM_UNIT_0, MCPWM_TIMER_0);

// Hier wird der Interrupt-Handler für das PWM-Signal registriert
    mcpwm_isr_register(MCPWM_UNIT_0, pwmHigh, NULL, ESP_INTR_FLAG_IRAM, NULL);   

  }
  VOID LOOP() {  ////////////////////////////////////////// LOOP //////////////////////////////////////////

 adcHigh = voltage;
     
    DELAY(1); //time for another task run.
  }
}

I do not understand that!? the PWM signal is generated without any problems, but... who sees the error? I've been looking for quite a while..... but I haven't used this function until now.

Please support!

THX

Re: mcpwm_isr_register does not execute command

Posted: Mon Feb 13, 2023 6:34 am
by sevi_at
would be nice if someone could help me here!

Code: Select all

mcpwm_isr_register(MCPWM_UNIT_0, pwmHigh, NULL, ESP_INTR_FLAG_IRAM, NULL); 
THX!