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

AndyChiang
Posts: 5
Joined: Thu Oct 13, 2022 8:36 am

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

Postby AndyChiang » Fri Oct 14, 2022 5:29 am

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.
Attachments
timerDebug.log
(14.12 KiB) Downloaded 140 times
sdkconfig.txt
(53.64 KiB) Downloaded 153 times
main.c
(219.57 KiB) Downloaded 155 times

AndyChiang
Posts: 5
Joined: Thu Oct 13, 2022 8:36 am

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

Postby AndyChiang » Fri Oct 14, 2022 7:47 am

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)

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

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

Postby ESP_igrr » Fri Oct 14, 2022 8:34 pm

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.)

AndyChiang
Posts: 5
Joined: Thu Oct 13, 2022 8:36 am

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

Postby AndyChiang » Mon Oct 17, 2022 9:19 am

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.

AndyChiang
Posts: 5
Joined: Thu Oct 13, 2022 8:36 am

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

Postby AndyChiang » Mon Oct 17, 2022 9:32 am

exp-idf have (servo control) example, I can use it to modify. thanks.

AndyChiang
Posts: 5
Joined: Thu Oct 13, 2022 8:36 am

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

Postby AndyChiang » Tue Oct 18, 2022 6:53 am

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.

Who is online

Users browsing this forum: Bing [Bot] and 79 guests