0

I'm implementing code for a multiplexed 7-segment display (4 letters), e.g. it has two common cathodes and each pin corresponds to two segments depending on which cathode is grounded.

I have written some code that employs a timer and switches the cathodes on and off while also writing to the correct segments. In the first trial I also used a digitalWrite to the cathode PINS to pull them high / low, however I then thought - hey I could also do PWM and thus modulate the brightness of the display. So I ended up with the code similar to what follows:

// setting PWM properties
const int freq = 5000;
const int cathodeAPWMChannel = 0;
const int cathodeBPWMChannel = 1;
const int resolution = 8;

volatile int lastCathode = 0;
volatile int brightness = 10;

void IRAM_ATTR onTimer() {
   if (lastCathode == 0) {
      //14x digitalWrite to each segment
      lastCathode = 1;

      ledcWrite(cathodeAPWMChannel, brightness);
      ledcWrite(cathodeBPWMChannel, 0);
   } else {
      //14x digitalWrite to each segment
      lastCathode = 0;

      ledcWrite(cathodeAPWMChannel, 0);
      ledcWrite(cathodeBPWMChannel, brightness);  

   }
}

void setup() {
   setupPins();
   timer = timerBegin(0, 95, true);
   timerAttachInterrupt(timer, &onTimer, true);
   timerAlarmWrite(timer, 10000, true);
   timerAlarmEnable(timer);
}

The issue is that now from time to time (especially when I change the brightness) I crash the ESP32 with this in the serial console

Guru Meditation Error: Core  1 panic'ed (Cache disabled but cached memory region accessed)
Guru Meditation Error: Core  1 panic'ed (IllegalInstruction). 
Exception was unhandled.
Memory dump at 0x401634ac: bad00bad bad00bad bad00bad
Guru Meditation Error: Core  1 panic'ed (IllegalInstruction). Exception was unhandled.

I think it is because ledcWrite doesn't have the IRAM_ATTR set - however I'm not a C / C++ guy and I really don't understand why it is so important / how I could fix the problem. Any ideas?

  • it's possible the error occurs because of the code you removed from the snippet in your question - it's hard to say, because the code isn't there – Jaromanda X Jan 25 at 22:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.