I am using an ESP32-PICO SoC to drive a display. I am programming it in Arduino framework using PlatformIO for Visual Studio Code. I have managed to set up a bit banging routine to drive my display. The bit bang is very lean and runs inside of a timer interrupt. I've programmed the interrupt to use hardware timer 0.
Code: Select all
timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &onTimer, true);
timerAlarmWrite(timer, 250, true); //250 microseconds = 4khz
timerAlarmEnable(timer);
I've set up my LEDC function to also use hardware timer 0.
Code: Select all
ledcSetup(ledChannel, freq, resolution);
ledcAttachPin(PWM, ledChannel);
* LEDC Chan to Group/Channel/Timer Mapping
** ledc: 0 => Group: 0, Channel: 0, Timer: 0
So why is it that when both my interrupt routine and the PWM are running at the same frequency and set to hardware timer 0, that the output signals are out of phase? This is causing visible jitter in my display, as the PWM signal goes high when the shift registers are clocking in new data. If I could control the phase of the PWM with respect to the interrupt, I would be able to make sure the PWM high does not overlap when the display is updating.
I appreciate any insight. Thank you.