16 July 2025

Debugging ESP32 Timer Interrupts: A Tale of API Compatibility

 

The Silent Signal Generator

 

Have you ever spent hours debugging code that should work but doesn't? Recently, I faced this exact challenge with an ESP32-based signal generator project. The symptoms were perplexing: all configuration parameters were correctly set, the web interface was working flawlessly, but the CTCSS tone output was completely silent. The culprit? 

A timer interrupt that refused to fire...

The Setup

The project uses an ESP32 to generate precise CTCSS (Continuous Tone-Coded Squelch System) tones for radio applications with  a GPS to "discipline" the time for 0.5% or less accuracy. 

Yeah! Overkill, I know, but the architecture is straightforward:

  1. A web interface for controlling tone parameters (frequency, level, on/off)

  2. WebSockets for real-time communication

  3. A timer interrupt running at 10 kHz to drive the DAC output

  4. Direct Digital Synthesis (DDS) with a sine lookup table for waveform generation

Everything seemed perfect in theory, but in practice, the DAC remained stubbornly silent.

The Investigation: Hours of Head-Scratching

 

What followed were countless hours of frustrating debugging and head-scratching. I tried everything: different timer configurations, checking hardware connections, simplifying the code, even rewriting the interrupt handler from scratch. I attempted various approaches: minimizing critical sections to reduce conflicts with WebSockets, trying different timer frequencies, toggling GPIO pins to verify hardware functionality, and even considering direct register access to bypass the Arduino API entirely. Nothing worked. The timer stubbornly refused to fire its interrupt, and the oscilloscope showed a flat line where a beautiful sine wave should have been.

The extensive debug logged every aspect of the system and for no reason, the interrupt was silent. 

At one point, my frustration reached such heights that I was ready to abandon the Arduino framework entirely and start learning Assembler or Machine Code just to manipulate the ESP32's DAC at the lowest possible level. 

Anything to get that stubborn signal flowing! A pattern finally emerged: the timer was being initialized correctly (the code was compiling and running without errors), but the interrupt service routine (ISR) counter remained at zero. This meant the timer was configured but never actually firing its interrupt.

[DIRECT DEBUG] Timer status check:
ISR counter value: 0
CTCSS enabled: YES
CTCSS frequency: 100.00
Timer initialized: YES

The code was using the ESP32 Arduino Core 3.2.1, and the timer setup looked correct:

timer = timerBegin(timerFreq);
timerAttachInterrupt(timer, &onTimer);
timerAlarm(timer, alarmValue, autoReload, reloadCount);
timerStart(timer);

 

The Breakthrough: API Version Matters

After multiple failed attempts to fix the issue within the 3.2.1 framework, I discovered something crucial: ESP32 Arduino Core versions have significantly different timer APIs.

The newer 3.2.1 version had simplified the API, removing critical parameters like timer number selection and edge-triggered interrupt options. These simplifications made the API easier to use but less powerful for specialized applications like precise signal generation.

 

 


 

The Solution: Strategic Downgrade

The solution was to downgrade to ESP32 Arduino Core 2.0.9, which offers a more comprehensive timer API. This allowed explicit control over:

1. Timer selection - Using Timer 1 to avoid conflicts with system functions

2. Edge-triggered interrupts - For more responsive and reliable timing

3. Precise prescaler settings - For accurate frequency generation

The updated code looked like this:

// ESP32 Arduino Core 2.0.9 API with explicit timer number
int timerNumber = 1; // Using timer 1 to avoid conflicts
uint16_t prescaler = 80; // 80MHz / 80 = 1MHz timer frequency

timer = timerBegin(timerNumber, prescaler, true); // true = count up
timerAttachInterrupt(timer, &onTimer, true); // true = edge triggered

uint32_t alarmValue = 1000000 / DDS_SAMPLE_RATE; // 100 ticks for 10kHz
timerAlarmWrite(timer, alarmValue, true); // true = auto reload
timerAlarmEnable(timer);

 

 

The Results

The results were immediate and impressive:

[DIRECT DEBUG] Timer status check:
ISR counter value: 2232839
CTCSS enabled: YES
CTCSS frequency: 254.00
Timer initialized: YES

[INFO] ISR count: 2240000, Time since last report: 1003 ms
[INFO] Actual interrupt frequency: 9970.09 Hz (expected: 10000 Hz)
[INFO] DAC output active: yes, CTCSS enabled: yes

The timer was now firing at approximately 9970-9980 Hz (within 0.3% of the target 10 kHz), and the oscilloscope confirmed a clean CTCSS signal output from the DAC.

 


 

Key Takeaways

1. API Compatibility Matters: Always check API compatibility when upgrading frameworks or libraries. What works in one version may not work in another, even if the code compiles without errors.

2. Explicit is Better than Implicit: When working with hardware-level features like timers, explicit control often yields better results than simplified APIs.

3. Effective Debugging: Implement counters and detailed logging to make invisible problems visible. The ISR counter was crucial in diagnosing this issue.

4. Sometimes Downgrading is Upgrading: Don't be afraid to use an older version if it offers functionality that better suits your specific needs.

Conclusion: From Frustration to Triumph

After hours of pulling my hair out (not quite) and questioning my sanity (and programming abilities - truly!), the solution turned out to be something I never would have guessed initially. 

Those moments when you stare at perfectly valid code that simply won't work are some of the most frustrating in an amateur developer's life. Yet they're also the moments that teach us the most.

This experience reinforced an important lesson in embedded systems development: understanding the underlying hardware and API capabilities is just as important as writing correct code. Sometimes the most elegant solution isn't using the latest version, but rather the version that gives you the control you need.

The relief when seeing that ISR counter finally incrementing was indescribable. The ESP32 Signal Generator now produces perfect CTCSS tones with rock-solid timing, proving that with the right approach, even the most stubborn bugs can be conquered. The countless hours of head-scratching were ultimately worth it, not just for the working project, but for the deeper understanding gained along the way.

Have you encountered similar API compatibility issues in your projects? Share your experiences in the comments below!

30 June 2025

Transmițătorul DSB „El Silbo” - AA1TJ


 
Michael Rainey, cunoscut sub indicativul AA1TJ, este un cunoscut operator radioamator american, inginer și pasionat de homebrew minimalist. 

Este celebru în comunitatea radioamatorilor pentru simplitatea și creativitatea sa radicală în proiectarea emițătoarelor - adesea construiește echipamente funcționale din cele mai puține piese posibile, folosind chiar circuite alimentate cu voce umană în unele proiecte.


Transmițătorul „El Silbo”, pe care l-a numit după limba fluierată Silbo Gomero din Insulele Canare, reflectă filozofia sa: comunicarea lipsit de complexitate - doar ingeniozitate. 

Inspirat de ideea de simplitate și eficiență, acest transmițător utilizează un design minimalist pentru a transmite semnale de voce  în bandă laterală dublă (DSB) pe frecvențe HF (în special, 80 de metri).


Michael a descris  acest proiect într-un mod captivant, aproape poetic, descriind modul în care circuitul „șoptește prin eter” - la fel ca limba Silbo Gomero însăși...

Transmițătorul "El Silbo DSB" nu este doar o construcție tehnică — este un omagiu adus artei designului minimalist în radioamatorism. 

Este un exemplu funcțional al modului în care un transmițător care utilizează doar câteva tranzistoare și componente pasive poate comunica în continuare semnale vocale în mod eficient, oferind:

  • O platformă de învățare pentru experimentatori radio
  • O provocare pentru cei interesați de comunicațiile QRP (cu putere redusă)
  • O demonstrație a modului în care circuitele analogice pot fi optimizate pentru vorbirea umană

El Silbo este un transmițător DSB (bandă laterală dublă) care funcționează pe banda de radioamatori de 80 de metri (~3,58 MHz). 

Acesta utilizează:

  • Un rezonator ceramic VXO (oscilator cu cristal variabil)
  • Un modulator simplu echilibrat care utilizează componente discrete
  • Un amplificator RF în două etape care utilizează tranzistoare RF de bază
  • Un filtru trece-jos sau ieșire directă într-o sarcină de 50 ohmi

Ce nu  utilizează:

  • Montajul nu folosește sursă de alimentare ci preia energia produsă de difuzorul folosit pe post de microfon. 

Puterea de ieșire tipică este de aproximativ 1,5 până la 2 miliwați, iar semnalul este compatibil cu receptoarele SSB standard, ceea ce îl face ideal pentru comunicații vocale ocazionale sau teste QRP.

 

Iată și detaliile - evident, Germanium:

 


 


 

27 June 2025

Arduino Based Repeater Controller

 A request from a fellow ham made me revisit an old project, and Arduino based repeater controller.

This lead to an iterative process to upgrade it from a simple Carrier Detect repeater to a more versatile one, that can use RSSI signal to activate the repeater. That's because the OM didn't have a Carrier Detect output on the radio that was available for his repeater.

 


In this version, the Mode can be selected by connecting a pin to the Ground) before the repeater is powered on.

Anti-kerchung was implemented for both Carrier detect and RSSI modes and in the later one, a hysteresis was defined.

Check it on Github for further explanations.

 

 

21 April 2025

Project "Router" - 1

 First is first...


const int uartPins[4][2] = {
  {3, 1},    // PC: RX=GPIO3, TX=GPIO1 (default Serial)
  {16, 17},  // U_1: RX=GPIO 16, TX=GPIO 17
  {18, 19},  // U_2: RX=GPIO 18, TX=GPIO19
  {23, 5}    // U_3: RX=GPIO 23, TX=GPIO 5
                            };

17 April 2025

ICOM IC-703+ de vanzare / For Sale

SOLD!

 Primul meu ICOM IC-703+ este de vanzare!

Dupa un eveniment distructiv accidental (o supravoltare datorita functionarii defectuoase a unei surse de laborator), m-am incumetat inainte de Craciunul lui 2024 sa il repar.

Reparatia a durat cam o luna, primul pas fiind identificarea componentelor defecte si plasarea de componente echivalente pentru a testa functionarea.

Apoi, dupa identificarea acestora, au fost comandate piesele originale, unele dintre ele avandu-le deja "pe stoc", achizitionate preventiv in urma cu multi ani (celebrul uPC2709).

Dupa aducerea in stare de functionare, am instalat si un filtru Collins CW de 500 Hz, YCF-115C.

Pentru ca am doua, acesta este de vanzare.

Se da impreuna cu microfon HM-173.

Cablu de separatie, bonus! 

Pret: (400 Eur) -  2000 Lei + transport prin curier. 

Disponibila fisa de service in care sunt evidentiate toate reparatiile. Contact prin email, indicativul @  gmail

 

Da, sunt doua! Al doilea a ajuns la mine prin bunavointa lui YO3FX (SK) care stia ca sunt in grea suferinta dupa primul...

Capacele au fost reconditionate.


Panoul frontal este impecabil.


Suruburile din pozele de mai jos au fost inlocuite cu unele compatibile, cu cap inecat, intocmai ca cele originale.





 







Most viewed posts in last 30 days