Skip to content

Notes about specific architectures

Fabiano Riccardi edited this page Oct 25, 2023 · 3 revisions

On this page, I report details on specific architectures.

AVR

Timer 1 is default timer, but you can select 2-5 (if available on your specific MCU model). In hw_timer_avr.cpp you can find:

#define TIMER_ID 1

Please note that timer 0 and 2 are only 8-bit, hence some adjacent delays (especially in the middle of semi-period) may be visible or too coarse for your application. I suggest selecting a 16-bit timer.

SAMD

Timer 3 is the default, but you can select 4-7 (if available on your specific MCU model). In hw_timer_samd.cpp you can find:

#define TIMER_ID 3

I wouldn't encourage the usage of timer 0, 1, 2 because they are Timer/Counter for Control Applications (TCC). These are special timers that can be programmed to accomplish tasks entirely in hardware.

ESP8266

This is the most limiting board I had found: it has only 2 timers and the first is dedicated to HAL/OS API, and it is mainly used by wifi routines. Developers can freely access only to timer 1, multiplexing it between different purposes (Tone, PWM, etc...).

ESP32

ESP32 has 4 64-bit timers and timer 0 is the default. In hw_timer_esp32.cpp you can find:

#define TIMER_ID 0

Interrupt issue

ESP32 seems to have an issue with interrupt detection on GPIO, in particular the interrupt mode RISING triggers an interrupt even when the signal is falling and the slew rate of the signal is slow enough. You can find some useful details in this issue, which started in 2018.

The solution provided by this library is activating the FILTER_INT_PERIOD mode and set an appropriate semiPeriodShrinkMargin. If you want to measure the best value for this constant, a method is measuring the gap between the 2 interrupts generated by RISING and FALLING edges with an oscilloscope. To do this, modify the zero_cross interrupt routine to generate a small impulse (1us) every time the ISR is activated and focus the oscilloscope to view a couple of rising-falling edges.

The code to generate a pulse is very trivial:

// Setup
pinMode(13, OUTPUT);

...

// zero cross ISR
digitalWrite(13, HIGH);
delayMicroseconds(1);
digitalWrite(13, LOW);

This is what I have obtained using the RobotDyn Dimmer:

Robotdyn esp32 double interrupt trigger on RISING mode

The gap between the pulses is about 340us, so a good value is 400us.

NOTE: this issue doesn't occur with the Krida's dimmers since they provide a clean and sharp zero cross signal.

Clone this wiki locally