Reading PWM signal using ESP8266? Generating 30 KHz PWM signal? (Updated)
Reading PWM signal using ESP8266? Generating 30 KHz PWM signal? (Updated)
Is where any way to read 5v pwm signal (of PWM fan control)? Where i can read about it?
And how can i generate 30 Khz pwm signal with ESP8266? Is there any modules in the sale for this? What ways exists?
For example, to make PWM-regulation of PC fan - i need 30+ KHz PWM.
And how can i generate 30 Khz pwm signal with ESP8266? Is there any modules in the sale for this? What ways exists?
For example, to make PWM-regulation of PC fan - i need 30+ KHz PWM.
Last edited by Strik3r on Fri Dec 06, 2019 4:56 pm, edited 2 times in total.
Re: Reading PWM signal using ESP8266?
I haven't tested this myself, but depending on the width of the pulses, you might be able to use the approach I suggested in viewtopic.php?f=2&t=7067&p=40229 (machine.time_pulse_us)
Also, make sure you level shift the 5V signal with a voltage divider.
Also, make sure you level shift the 5V signal with a voltage divider.
Re: Reading PWM signal using ESP8266?
Thanks you for answer. I will read this thread.jimmo wrote: ↑Fri Dec 06, 2019 3:38 amI haven't tested this myself, but depending on the width of the pulses, you might be able to use the approach I suggested in viewtopic.php?f=2&t=7067&p=40229 (machine.time_pulse_us)
Also, make sure you level shift the 5V signal with a voltage divider.
Also, i will not make new thread and want to ask here:
How can i generate 30 Khz pwm signal with ESP8266? Is there any modules in the sale for this? What ways exists?
For example, to make PWM-regulation of PC fan - i need 30+ KHz PWM.
- MostlyHarmless
- Posts: 166
- Joined: Thu Nov 21, 2019 6:25 pm
- Location: Pennsylvania, USA
Re: Reading PWM signal using ESP8266?
Generating PWM is rather easy by using the machine.PWM class.
However, the esp8266 will NOT be able to directly drive anything bigger than an LED. To drive a PC fan you need a transistor that can sustain a couple hundred mA of current. And since a fan is an inductive load, you need a flyback diode as well to protect the transistor. For small stuff like PC fans or relays I usually just slam a ULN2803 in between the microcontroller and whatever I want to control. These things are 8 port Darlington transistor arrays with built in protection diode. They can handle up to 500mA per port (not on all 8 simultaneously though). If a single 500mA port isn't enough one can use multiple in parallel, so driving a 1A load is no problem. They can handle up to 50V on output, up to 30V on input (yes, you can protect your digital inputs with them too) and the best thing is that they are cheap. Dirt cheap.
Let me know if you need further help using those arrays. They will protect your expensive microcontroller if used right.
Regards, Jan
Re: Reading PWM signal using ESP8266?
Thanks! I know about machine.PWM and already used it, but machine.PWM can provide only 1KHz, but i asking about 30KHz - to correctly control PC fan i need 30KHzMostlyHarmless wrote: ↑Fri Dec 06, 2019 8:33 pmGenerating PWM is rather easy by using the machine.PWM
- MostlyHarmless
- Posts: 166
- Joined: Thu Nov 21, 2019 6:25 pm
- Location: Pennsylvania, USA
Re: Reading PWM signal using ESP8266? Generating 30 KHz PWM signal? (Updated)
Oh darn, I was thinking about the capabilities of the esp32, which can do up to 40kHz. At least I linked to the correct info in the docs.
You are right, the esp8266 can only go up to 1kHz. My old PIC18F's can do better than that.
Regards, Jan
You are right, the esp8266 can only go up to 1kHz. My old PIC18F's can do better than that.
Regards, Jan
Re: Reading PWM signal using ESP8266? Generating 30 KHz PWM signal? (Updated)
I'm sorry, isnt esp32 using the same machine.pwm class, in whitch docs written about 1KHz limit? Or i understand smthng wrong?MostlyHarmless wrote: ↑Fri Dec 06, 2019 8:58 pmOh darn, I was thinking about the capabilities of the esp32, which can do up to 40kHz.
Re: Reading PWM signal using ESP8266? Generating 30 KHz PWM signal? (Updated)
Same class, but the hardware has a different limit -- like Jan said, it goes up to 40kHz on ESP32.
The docs you're looking (that mention the 1kHz limit) are for the ESP8266 specifically.
The docs you're looking (that mention the 1kHz limit) are for the ESP8266 specifically.
Re: Reading PWM signal using ESP8266? Generating 30 KHz PWM signal? (Updated)
Ok, thanks! Didnt know about it. Already ordered ESP32 for my project with PWM.
I was thinking about outer PWM-generator, smthng like CY8C9520A. But ofk, the platform change to ESP32 - is simplier desidion
- MostlyHarmless
- Posts: 166
- Joined: Thu Nov 21, 2019 6:25 pm
- Location: Pennsylvania, USA
Re: Reading PWM signal using ESP8266? Generating 30 KHz PWM signal? (Updated)
If I understand the documentation right (and there is no guarantee for that), then the PWM on the esp8266 is implemented in software with an interrupt routine. The esp32 on the other hand uses dedicated hardware timers for that. This not only allows it to operate PWM on higher frequencies, but it makes the signal more reliable.
Regards, Jan
Regards, Jan