r/ArduinoHelp • u/The_ESP_Shadow • Sep 25 '26
ESP32 PWM at 250 Hz seems to interact strangely with my 4 ms
/r/electronic_circuits/comments/1wpwsvf/esp32_pwm_at_250_hz_seems_to_interact_strangely/
1
Upvotes
1
u/gm310509 Sep 26 '26
I am a bit confused about what you are trying to do.
The following code measures how long analogWrite (plus one full call to micros) takes to execute.
This code does not measure the frequency of the PWM. PWM is setup in hardware. The time difference between a and b simply measures how long it takes to set that up - after which the hardware will independently do its PWM thing.
Then, you effectively add in another 4 milliseconds with your do nothing loop between the setup and print.
Lastly, your output doesn't seem to add up. 4000 plus 3 lots of 5 is 4015, not 8000.
Maybe try printing the value of your variables a through h?
FWIW, your m1time seems extraordinarily lengthy. It is hard to believe that it takes 4 milliseconds to set up a PWM on an ESP32 - on an 8 bit AVR, it just involves setting a small handful of values (about 6 of them) into some IO registers and you are done.