Read PWM Signal from Device
-
How to read a PWM signal from a LED dimmer? The dimmer works on a 12V LED and I want to dim other - remote - LEDs with this value as well. Therefore a M5Atom or M5Core is connected to the dimmer and a PWM kit connected via EspNow to the additional LED.
LED Dimmer PWM > M5Core read PWM Signal "Value" > EspNow send "Value" > M5Atom with PWM kit > LED
-
there are 2 variants:
A) the PWM signal can be captured by measuring the time ratio between 1 and 0:
- Put the PWM signal into one of the GPIO. Make sure the voltage is not too high, use a voltage divider and if possible a additional Z-diode for protection).
- Set the input to an interrupt source for both edges
- in the INT-routine put the current time stamp into a variable and wait for an oposite edge appears. If you do this in a clever way, the controller can do other things in the mean while (e.g.sending the value over ESPnow)
- once you have a high and a low time you can calculate the ratio.
B) integrate the PWM and measure the analog voltage
- use a R-C circuit to integrate the PWM into a analog voltage
- divide the voltage by a trimmer potentiometer so that 100% equals full scale of the analog input. If possible use a Z-diode to protect the input
- measure the analog value by M5Atom
-
Okay .. I tried variant B and it works well with just two resistors .. in my case 100 and 27 Ohm. To get a realy clear 0..100 signal I measure the PWM signal and the source voltage 12-15V. This way I can better match what my dimmed 2.6V really is.
-
100 and 27 Ohm? In this Case you burn 118mA @ 15V or 1.77 Watts in the resistors. They may become a bit hot. Could be better with higher restistance (1k + 270 or 10k + 2k7) as the wasted power is smaller but the divider ratio is still the same.
- A Capacitor helps to stabilise the voltage on the input. You can also take a few samples / measurements and integrate it in a software loop to get more acurate value.
- A Zener Diode of 3.3V helps to protect your input. This is very recommended!
I put a small simulation where you can play around: https://tinyurl.com/2lshs6fj
(use the slider on right to change the PWM duty) -
@holofloh said in Read PWM Signal from Device:
I put a small simulation where you can play a
Sorry for that and thank´s for your feedback. I missed a "k" before Ohm. This is what I´ve tested.
Is this nearly the same https://shop.m5stack.com/products/adc-unit or what is the difference.
-
I was focused on the GPIO analog input of the core. The ADC I2C Unit is one possible way more to measure analog signals. I see in the schematic there is a 300K:100K divider for the input followed by an OpAmp. Yes it is more or less the same as my suggestion. It can measure up to 12V and bit more if you change the resistors. I strongly recommend to also protect this input. You never know what the LED driver really do (eg. transients while switching on or off) if you have not designed it by yourself (and even then...).
-
I will try the " craft approach ". The LED driver does not provide stable 12V, as it can be between 12 to 14.5V in a camper. And with your recommendations for diode and capacitor.