Page 1 of 1

The square-wave-output generated by timer can't greater 40000Hz

Posted: Fri Oct 14, 2022 5:29 am
by AndyChiang
Module: ESP32-WROOM-32D
IDF version: V4.2
OS: Win7
Expected result: Generate 10000Hz squal wave by timer is successful
Real result: Watchout occurs when the generated frequence is over 80000Hz
Tested timer: Timer 0 of Group0
Output pin: IO26
Test Step: (1)Set TIMER_INTERVAL0_SEC = 0.000009
(2)Change state of IO26 (from 0 to 1 or 1 to 0) in timer_group0_isr
(3)View the result on IO26 use Oscilloscope
Attached: (1)main.c of project (a2dp_gatts_coex)
(2)sdkconfig of project (a2dp_gatts_coex)
(3)log file when watchdog occurs
Since the sdkconfig have no text format that can't upload, so I add .txt, please delete .txt format when need build it.

Re: The square-wave-output generated by timer can't greater 40000Hz

Posted: Fri Oct 14, 2022 7:47 am
by AndyChiang
Sorry, some description need correct:
Expected result: 50000Hz(change state from 0 to 1 or 1 to 0 in 10us)
Real result: Watchdog occurs when the generated frequency greater than 40000Hz(change state from 0 to 1 or 1 to 0 in 12.5us)

Re: The square-wave-output generated by timer can't greater 40000Hz

Posted: Fri Oct 14, 2022 8:34 pm
by ESP_igrr
Is generating a square wave the final result you'd like to achieve, or is it just a simplified example?

ESP chips have many peripherals which let you generate complex waveforms while using little CPU time. So if the waveform you are generating is pre-defined, you can set up RMT, SPI, I2S or LEDC peripheral to generate it.

(The limitation you are running into is due to the total time it takes to switch between the task and interrupt context. Once the system doesn't have enough time to do anything other than constantly entering and exiting the interrupt, the watchdog occurs.)

Re: The square-wave-output generated by timer can't greater 40000Hz

Posted: Mon Oct 17, 2022 9:19 am
by AndyChiang
I need generate a CW or CCW signal to control servo motor.
It is a square wave between 0Hz to 50000Hz.
Since the frequency must be change anytime, so I select use timer to control.
I think maybe PWM is selection.

Re: The square-wave-output generated by timer can't greater 40000Hz

Posted: Mon Oct 17, 2022 9:32 am
by AndyChiang
exp-idf have (servo control) example, I can use it to modify. thanks.

Re: The square-wave-output generated by timer can't greater 40000Hz

Posted: Tue Oct 18, 2022 6:53 am
by AndyChiang
Our control must can control the number of pulse and the frequency of output pulse at the same time.
So, can not use PWM and only can utilize the ISR of timer that priority is more high.