Use of ADC to control PWM?

286 views
Skip to first unread message

Bryan Mayland

unread,
Feb 1, 2018, 7:58:46 PM2/1/18
to SonoffUsers
I designed a little custom board for doing some specialty PWM control and sensor data collection and had it in my mind to write my own software for it but suddenly it struck me that Sonoff-Tasmota did pretty much everything I wanted to do already!

One of the few features that I was planning on including was that my board has a big-ole panel mount potentiometer on it that was going to allow to control the dimming function for one of my channels. From reading the source code, I see that the ADC is only used for VCC reading and GPIO_ADC0. GPIO_ADC0 is only reported through the status JSON and web display. Is there any way to allow binding of the ADC value to one of the PWMs (other than capturing it in the telemetry and reacting every few minutes)?

It would be great if could directly control a PWM and also optionally invert and remap the ranges. For example if you want the whole potentiometer to range from 50% to 100% brightness or something zany like 35% to 67%. Conversely you could restrict the whole 0%-100% output to a subset of the analog range (for inputs that don't go all the to 0V and 1.0V). I don't see it in the code and I know there aren't any devices that have this sort of hardware. If it were implemented would it be accepted upstream? I definitely do not want to maintain a fork which just adds one feature.

Don Willingham

unread,
Feb 24, 2018, 9:48:04 AM2/24/18
to SonoffUsers
Some features may be accepted upstream, but just may be defaulted out, not conditionally compiled in.

Bryan Mayland

unread,
Apr 21, 2018, 12:20:52 PM4/21/18
to SonoffUsers
Well, let's see what happens. I've implemented and tested this feature and now I can digitally dim a PWM output by attaching a potentiometer to the esp8266 ADC input. Conditionally compiled in if USE_ADC_VCC is not set and USE_ADC_PWM is set.
Reply all
Reply to author
Forward
0 new messages