Describe the bug
Added in 1.0.5:
- Permit changing dutyCycle and keep same frequency on-the-fly should now work but it's not clear how.
- Add example - Example is not clear and is not included in the downloaded library from Arduino
- Not sure why bards need to be listed but I'm using the WaveShare RP2040-Zero $5 and small and castellated, just what I need for including in my project. Only difference from a generic is the cute little WS2812 RGB LED which I can't get to work.
- Yep, I can lower the debug level, though I'm not sure what those warnings are about.
A clear and concise description of what the bug is.
What are the units you are using for duty cycle? Normally with 16 but PWM you would just load a 16 bit count value and be done with it. It looks like you might be using float of 0.0 - 100.0% - Trying to be fast here why mess with floating point numbers?
I tried both
PWM_Instance[0]->setPWM(pin0, freq, (double(lookup8to16[i]), false); // Pass 16 bit value, but as a double (which is just a float?)
PWM_Instance[2]->setPWM(pin2, freq, (double(lookup8to16[(i])/655.35, false); //
// lookup8to16[] is a 256 value array of the gamma curve so brightness is properly log scale for human eye
Steps to Reproduce
Used your example PWM_Multi adding to the loop:
for (uint i=255; i>0; i-- ) {
PWM_Instance[0]->setPWM(pin0, freq, (double(lookup8to16[i]), false); //
PWM_Instance[2]->setPWM(pin2, freq, (double(lookup8to16[(i+0x80)&0xff])/655.35, false); // offset this one by 1/2 the table
delay(30);
}
Also tried
// Do it by reaching in past the library to the PWM hardware
pwm_set_counter (pwm_gpio_to_slice_num(pin0), (lookup8to16[i]/655.35)); // 0 to 100%?
pwm_set_counter (pwm_gpio_to_slice_num(pin1), lookup8to16[(i+64)&0xff]); // 16 bit value?
Expected behavior
I'm looking for a smooth increase and then decrease in the duty cycle (and thus LED brightness) from 0 to 100% and back to 0
Actual behavior
Depending on which version I try I get some smooth action then big jumps in brightness (something is wrapping to zero at the wrong time). Even when it is working over some of the range it's flickering when it shouldn't (resetting the slice? IDK)
debug
set level to 3 don't get any reports
One odd thing is that when I enable the Serial Monitor it always says (in orange at the top of Monitor pane):
"Not Connected. Select a board and port to connect automatically"
But then it works anyway. Took me a while to realize it's in a pane of the program window not a separate window as in 1.8
1.8 couldn't find the PIO.h file
Screenshots
I could send a video of the LED or scope traces of the PWM (Have to set up the o'scope)
Information
-
Arduino IDE 2.0.0 rc3 (also tried 1.8.15 but messed that up installing arduino-pico)
-
`RP2040-Zero from WaveShare
-
Contextual information
Smooth deep dimming down to 1/65536 full 16 bit dimming (most commercial dimmers are 10%-100% and "best" e.g. DALI are still only 1:1000 i.e. 0.1% Eyes can see much better than that.
-
Simplest possible steps to reproduce
Using PWM_Multi but removed array for frequence fixed freq = 2000;
Loop changed to above code
-
Anything that might be relevant in your opinion, such as:
Aspire 5 core i5 2.4GHz 20GB Ram; Windows 11 Home 21H2 - if that matters
I'd like a simple to use library, the whole point of a library is to hide complexity so once the PMW slice has been set up there should be simple routines like
setPWMfreq(pin#,newfreq);
setPWMdcPct(pin#,newdc); // In percent if people really want that
setPWMdc16(pin#, uint newDCval); // 16 bit value
I've been reading the Pico hardware manual, it's dense, this machine is so powerful!
I'm happy that you dug in and extracted a working PWM package, it just needs a little tweeking and documentation I think.
BTW another odd thing:
After working for quite a while loading code after compile just fine. It quit loading and now requires unplugging and holding boot button every time. Is that because I'm using all the PIO?