mcpwm: unable to get interruption working for more then 1 pin at a time

rafaeldantas
Posts: 1
Joined: Tue Feb 14, 2023 12:26 am

mcpwm: unable to get interruption working for more then 1 pin at a time

Postby rafaeldantas » Tue Feb 14, 2023 12:55 am

Hi all,

I'm kind of stuck in get the mcpwm capture working properly in my ESP32-WROON... esp-idf v3.3.4 commit cded0f5aa (I know, old toy!). But really appreciated any help on this.

My intend is to use the capture mode of the mcpwm to read 2x hall sensors output, I managed to generate the interruption properly for one of the cap inputs but the second one does not trigger the isr handler.

I've checked the basics - signal is arriving properly at the intended pins. :P

Follow how I had configured my pins, followed sample from mcpwm_basic_config_example.c

Code: Select all

 
   esp_err_t rv = ESP_OK;

  /* GPIO initialization */
  mcpwm_pin_config_t pin_config;
  pin_config.mcpwm0a_out_num = HBRIDGE_PIN_A;
  pin_config.mcpwm0b_out_num = HBRIDGE_PIN_B;
  pin_config.mcpwm_cap0_in_num = HALL_PIN_0;
  pin_config.mcpwm_cap1_in_num = HALL_PIN_1;
  rv = mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, pin_config.mcpwm0a_out_num);
  rv |= mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0B, pin_config.mcpwm0b_out_num);
  rv |= mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM_CAP_0, pin_config.mcpwm_cap0_in_num);
  rv |= mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM_CAP_1, pin_config.mcpwm_cap1_in_num);
  if (rv != ESP_OK) {
    SysError(BE_500_TODO, "set pin failed: rv (%d)", rv);
    return false;
  }

  /* Start hall capture */
  rv = mcpwm_capture_enable(MCPWM_UNIT_0, MCPWM_SELECT_CAP0, MCPWM_POS_EDGE, 0);
  rv |= mcpwm_capture_enable(MCPWM_UNIT_0, MCPWM_SELECT_CAP1, MCPWM_POS_EDGE, 0);
  if (rv != ESP_OK) {
    SysError(BE_500_TODO, "capture enable failed: rv (%d)", rv);
    return false;
  }

  MCPWM[MCPWM_UNIT_0]->int_ena.val = (1<<27) | (1<<28);

  /* enable hall isr */
  rv = mcpwm_isr_register(MCPWM_UNIT_0, hall_isr, NULL, ESP_INTR_FLAG_IRAM, NULL);
  if (rv != ESP_OK) {
    SysError(BE_500_TODO, "isr register failed: rv (%d)", rv);
    return false;
  }

  /* PWM configuration */
  mcpwm_config_t pwm_config;
  pwm_config.frequency = 20000;
  pwm_config.cmpr_a = 0.0;
  pwm_config.cmpr_b = 0.0;
  pwm_config.counter_mode = MCPWM_UP_COUNTER;
  pwm_config.duty_mode = MCPWM_DUTY_MODE_0;
  rv = mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &pwm_config);
  if (rv != ESP_OK) {
    SysError(BE_500_TODO, "init failed: rv(%d)", rv);
    return false;
  }
I'm also generating PWM output which is gracefully being measured on scope. Just the CAP1 event that suppose to be happening is never trigger!

Appreciated any help.

Rafael Dantas

Who is online

Users browsing this forum: Bing [Bot] and 73 guests