ESP32 Timer changes

m8nix70
Posts: 2
Joined: Tue Nov 26, 2024 4:55 pm

ESP32 Timer changes

Postby m8nix70 » Tue Nov 26, 2024 5:36 pm

Hello,

i wrote a simple 3 phase pulse-packet-control at the beginning of the year.
I can compile it with board management 2.0.17 but now get compile errors with 3.0.7
It looks like that 4 timer-functions are obsolete or changed?

outputs.ino 362 timerAlarmWrite(hw_timer[1], TRIGGER_ANGLE_PHASE_3, false); -> error: 'timerAlarmWrite' was not declared in this scope

outputs.ino 364 timerAlarmEnable(hw_timer[1]); -> error: 'timerAlarmEnable' was not declared in this scope

outputs.ino 447 if (timerStarted(hw_timer[1])) { -> error: 'timerStarted' was not declared in this scope

outputs.ino 1085 timerAttachInterrupt(hw_timer[1], &burst_trigger_isr, false); -> error: too many arguments to function 'void timerAttachInterrupt

I hope someone can help me with new function-names, or other functions who do the same thing I wanted.

Christian
Attachments
impulse_packet_control.zip
(9.99 KiB) Downloaded 59 times

lbernstone
Posts: 857
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32 Timer changes

Postby lbernstone » Wed Nov 27, 2024 2:41 am


m8nix70
Posts: 2
Joined: Tue Nov 26, 2024 4:55 pm

Re: ESP32 Timer changes

Postby m8nix70 » Wed Nov 27, 2024 2:45 pm

lbernstone wrote:
Wed Nov 27, 2024 2:41 am
There is a migration guide for 2.X to 3.X

Hello Ibernstone,
thank you for the migration guide link. I didn't know that one yet.
“Guide” is perhaps a somewhat exaggerated formulation.
A list of removed APIs and new APIs would be the more appropriate formulation.
There is no mention of how to replace the removed API functions with the new ones.
This is not explained in the two example applications in the latest Arduino-ESP32 Timer API either.

Anyway, I was able to solve three compiler errors.

1. the removed API:

Code: Select all

timerAlarmWrite(hw_timer[timer_no], alarm_value, timer_reload);
replaced with new API:

Code: Select all

timerAlarm(hw_timer[timer_no], alarm_value, timer_reload, 0);
2. the removed API:

Code: Select all

hw_timer[timer_no] = timerBegin(timer_no, (uint16_t)(getApbFrequency() / TIME_BASE), cnt_up);
replaces with new API :

Code: Select all

hw_timer[timer_no] = timerBegin((uint16_t)(getApbFrequency() / TIME_BASE));
3. the removed API:

Code: Select all

timerAttachInterrupt(hw_timer[1], &burst_trigger_isr, false);
replaced with new API:

Code: Select all

timerAttachInterrupt(hw_timer[1], &burst_trigger_isr);
But I don’t found a new API function, who is telling me that a timer is running or not.

Code: Select all

if (timerStarted(hw_timer[timer_no])) {
I also can't find a new API function to enable or disable a timer alarm

Code: Select all

if (timerAlarmEnabled(hw_timer[timer_no])) {
  timerAlarmDisable(hw_timer[timer_no]);
}
So, I am very disappointed with the migration guide.
You would think that for every removed API there is a new example. It’s a joke

I changed my sample code into a single file sketch.
Once for API 2.0.17 which generates executable code and secondly API 3.0.7 with the mentioned compile errors
It powers consumer at output o1 (phase 1) with 25%, consumer at phase 2 with 50% and consumer at phase 3 with 75% power.

Please help

Chris
Attachments
impulse_packet_control_3.0.7.zip
(6.6 KiB) Downloaded 38 times
impulse_packet_control_2_0_17.zip
(6.6 KiB) Downloaded 37 times

Who is online

Users browsing this forum: Google [Bot], Google Adsense [Bot] and 46 guests