Skip to content

AttachInterrupt does not work on output of PWM (2.0.2)#6140

@mstegen

Description

@mstegen

Board

ESP32Dev module

Device Description

I'm using a PWM output, and setup a pin interrupt so i can detect the start of the PWM signal.
This works fine in 2.0.1, but not on 2.0.2

Hardware Configuration

no

Version

latest master

IDE Name

PlatfromIO

Operating System

Win10/Linux

Flash frequency

80Mhz

PSRAM enabled

no

Upload speed

115200

Description

attachInterrupt should be able to attach to the output signal of the PWM signal generated by ledC.
this does work in 2.0.1, but not in 2.0.2.

I noticed that there were changes made to the LEDC code (#6045)
when using the old (2.0.1) code for ledcAttachPin in my code, it works again.
So something in the new code, does not allow a PIN interrupt to be attached to the PWM output.

Below is test code to reproduce the problem.

Sketch

#include<Arduino.h> #definePIN_PWM_OUT19 #definePWM_CHANNEL0volatileuint32_t isrCounter = 0; // PWM pin low to high transition ISRvoid IRAM_ATTR onPulse(){// increment counter isrCounter++} voidsetup(){pinMode(PIN_PWM_OUT, OUTPUT); // Setup PWM on channel 0, 1000Hz, 10 bits resolutionledcSetup(PWM_CHANNEL, 1000, 10); // channel 0 => Group: 0, Channel: 0, Timer: 0ledcAttachPin(PIN_PWM_OUT, PWM_CHANNEL); // attach the channels to the GPIO to be controlledledcWrite(PWM_CHANNEL, 512); // channel 0, duty cycle 50%// Setup PIN interrupt on rising edgeattachInterrupt(PIN_PWM_OUT, onPulse, RISING); Serial.begin(115200); while (!Serial)} voidloop(){Serial.printf("ISR Counter: %u\n",isrCounter); delay(1000)}

Debug Message

The Counter in above test code will not increase. 

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions