-
Notifications
You must be signed in to change notification settings - Fork 13.3k
PWM analogWriteRange BUG? #2592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You do not use analogWriteRange to control an LED's brightness, you use analogWrite for that. Change your loop to, say, the following, and you'll see the LED's brightness change:
|
Than you for you answer! |
yes and no. You are going outside of the range that the hardware can do. Why in the world you need 10000 steps? that is not the frequency ;) it's the resolution. And then setting a value of 1 means that the time between start of the period and the time that you hit the count it will be so small that you will overlap your setting function and things will go to hell. |
it's need for led bright regulation.... if it's only 1000 and set analogWrite(gpio,1) average current via 1 Amper LED is 1mA but it is very big size :-( - i think if increase resolution to 10000 - at analogWrite(gpio,1) current will be 0.1 mA. I jus need really LED softoff... but now it's can be only decrease bright to some level and than discret off. and i did'nt understand how after |
? I'm not positive that you understand what PWM does. Led current is controlled by resistors and not PWM. PWM gives pulses and depending on the width is for how long the LED will stay on from that period (AT FULL BRIGHTNESS). Setting range to 10000 means that you can analogWrite(pin, 0-10000) and not that you will send 1/10000 of the current through |
Yes i understand it! |
Um, no, you clearly do not understand how it works. analogWriteRange() does not adjust the LED's brightness, period. You use analogWrite() to do that, like I already provided an example earlier. analogWriteRange() just changes the range of what analogWrite() considers the maximum value, like e.g. with the default setting (ie. 1023) half brightness would be analogWrite(PIN, 511), but if you changed the maximum to only 255 with analogWriteRange(255) you'd get half the brightness with analogWrite(PIN, 127) instead. You really need to read what is being said to you: analogWrite() is the command that sets the brightness. |
analogWrite(gpio,1); |
WereCatf - thank you - i really understand how it's work! but i have'nt enought english knowledge :-) for explain it's.... ( chukcha not writer - chucha just reader (only joke)) i understand analogWriteRange change resolution - that what i needed... but bright i change with analog write of course.... thank's and sorry for my english.... |
No. That is not how it works, period. |
analogWriteRange(100000); |
@gorec2005 Okay, I am only going to say this once: stop using analogWriteRange()! You do not understand how it works, and you do not need it! Just simply change the value of analogWrite()-call and POOF -- the LED's brightness will change! |
@WereCatf thank you again! - for change brightness i use analogWrite(). but range of 1000 (~10bit) is not enought for me - i need 10000 (~12bit) or may be 16bit for linearry change brightness of LED from switched off state to full brightness, but LED bright physic's and human bright sens eye is not equal :-(... now i use equation for linearry change bright :
for soft ON |
it's my mistake - i did not clearly describe.... - sorry.... |
@me-no-dev you said "You are going outside of the range that the hardware can do." |
simple math ;) but I do not want to go deeper than that. If you want 12-16 bit PWM, go get a PWM chip that can do it. You do not ever need 10000 steps to change the brightness of a LED!!! Ever!!!! |
10000 steps * 1000 Hz = 10MHz or 100ns between 0 and 1 <<<< not doable by software!!! |
"Further on, 1023 is 10 bit and not 8 bit." - i mistake... it's not a soft on and soft off - it's a brightness jump+soft brightness change and so on... |
hm... i try'ed.... |
how you have connected your led? You do realize there are many users of this thing and if it was working as much as you say, we would have known about it :) |
i connect LED via mosfet when gpio is 0 mosfet is closed and led is off... i will try to use oscilloscope later and show what i get... |
RANGE 10000 analogWrite(10) analogwrite(1) |
you are more than welcome to improve the PWM code in the core and make it work better |
continue... :-) |
increasing the frequency or increasing the steps is the same exact thing. |
Hi!
did not work! - says in serial:
If i change analogWrite ( led, 1 ); to analogWrite ( led, 2 ); - it's work but only five sec's than also wdt reset! |
this sketch have wdt reset! - try it please... `int led = 15; void setup() { void loop() { |
I try'ed newpwm from https://github.com/StefanBruens/ESP8266_new_pwm It's really cool! - timebase 200ns and period 0-5000(default)! |
Hi @gorec2005 Thanks for providing a link to a library that does more than 10bit. @WereCatf and @me-no-dev, I currently use an arduino between my esp8266 and my leds, and run the arduino in 16bit pwm mode. I used to use 8bit pwm, but the difference between 0 and 1 is so huge with my 10 watt leds that I couldn't exactly get it to comfortably dim up and down. Here is a blog post I found on doing 16bit pwm on an arduino: https://www.arduinoslovakia.eu/blog/2017/7/16-bitove-rozlisenie-pwm-pre-arduino?lang=en |
Just stumbled on this thread and I feel for @gorec2005 as the contributors berating him were evidently the ones not understanding. A decent range definitely matters, and when coding PWM for PICs such as in a DMX controller, I've always used 16 bit levels with 32 bit math. Incoming 8 bit DMX levels would be scaled up to 16 bit, and the engine would fade quickly between level changes in the 16 bit space to smooth the transitions. This gives the smoothest dimming imaginable without requiring a high DMX frame rate or using two DMX channels to increase range, and with a suitable response curve rather than simply linear, the bottom end can be handled with refinement. |
Hardware
Hardware: ESP-12
Core Version: from GIT 08.10.2016
Description
Bright not changed if change PWM analog Range... and all time bright is maximum!
i don't understand - it's a bug or feature...
Settings in IDE
Module: Nodemcu v1
Flash Size: 4MB
CPU Frequency: 160Mhz
Flash Mode: dio
Flash Frequency: 40Mhz
Upload Using: SERIAL
Reset Method: nodemcu
Sketch
The text was updated successfully, but these errors were encountered: