Possible to increase the PWM resolution?

Is it possible to increase the PWM resolution from 8 bit to 10 bit or possible 12 bit, with xod?

How can I read analog value between 0-1023 instead of 0-1?

(potentiometer value)

https://www.pjrc.com/teensy/td_pulse.html

How can I read analog value between 0-1023 instead of 0-1?

XOD likes to keep ranges of things as real numbers 0…1, which is a good thing, since other nodes are designed to work with that.

I’m guessing you found some examples/code somewhere that works with 0…1024, in “Arduino” style.

You can use “map” to convert the analog-read. I threw in “floor” to force it to integer values, but that may not be necessary for your application.

analog-to1024.xodball (4.0 KB)

It is ok if I just can see the valu 0-1023 in the UI!

Like in the map node.

As stated above, you can use the map function. Since source value is 0-1, you could also short-cut and just multiply by 1024. As hinted at above, if you are feeding this output to other XOD built-in nodes like ‘led’, you will need to leave it in the 0-1 range.

is it possible to increase the PWM resolution from 8 bit to 10 bit or possible 12 bit, with xod?

XOD appears to have no built-in node for this.

Only some boards support analogWriteResolution(): SAMD (Zero, Adafruit M0 and M4’s), Adafruit nrf52’s, etc. This is poorly documented. Possibly the easiest way to check is to write a regular Arduino sketch, very simple:

void setup() { analogWriteResolution(10); }
void loop() { delay(10); }

And simply “compile” it with the correct board selected.

If it is not supported, you get:
error: 'analogWriteResolution' was not declared in this scope

I wrote an untested node to implement analogWriteResolution(). “Untested”, you say? Yes, I’ve forgotten how to convince XOD to add boards, and I only have Adafruit SAMD boards. Will try to actually test soon.

  • only works on SAMD’s
  • generates an ERROR on non-SAMD
  • should be reviewed (code, documentation, etc)

Here is the xodball with the analog-write-resolution patch.

If anyone can test/improve before I get to it, please do!
analog-write-resolution

analog-write-resolution.xodball (1.9 KB)

(@mitch-bogart asked about this in 2020)

It is not input resolution I want to increase it is output pwm signal.

If I look here it looks like it is possible with only 2 outputs on arduino uno.

I am thinking that maybe Teensy is a better solution?

https://www.pjrc.com/teensy/td_pulse.html

I now saw this: Hur väljer jag rätt PWM-frekvens för LED?

The page is translated to English from Swedish.

It seems that I have to get to 2-4Khz to get flimer free dimming.

This also suggests that I need to use Teensy 4.0 or 4.1.

I forgot to say that I am going to dim led lights, with curves and min, mix pot for setting max brightness.

I want to make a dimmer that can mix led and light bulb. Same light output with one potentiometer. I will also mix diferent voltages. So the dimmer will control the minus side with MOSFETs.

What do you think?

I don’t understand. analogWriteResolution() is for output PWM, and the node I wrote does that. Note that it changes the bits-resolution for ALL pwm outputs.

analogWriteResolution() works on many of the faster/bigger boards, but definitely NOT on the uno (or other “AVR” boards). You would have to write a “c++” node, and implement whatever solution, and, of course, it wouldn’t work on other boards. Creating Nodes for XOD in C++ — XOD

I would say that the itsybitsy’s are nicer for this. And, I wrote a node for it. :smiling_face:

Can someone verify that the Teensy supports analogWriteResolution()? And if ARDUINO_ARCH_SAMD is defined for it? If so, then my patch should work.

I figured out how to add more boards, and tested on an itstybitsy m0. It worked, yay. Here’s a xodball with the (previous) analog-serial-resolution patch, and a main to test it.
analog-write-resolution.xodball (11.3 KB)

Realy good price.

Hade to Google what it was.

But basicly I want this

6 or 8 potentiometers with at least 1024 steps for input.

12-16 trim potentiometer for setting min max on each light output Chanel.

Or use encoder. Have not decided yet.

6 or 8 PWM output channels, as good as possible for diming led with out flimmer or sound. Whit as good resolution as possible. I imagine at least 2Khz.

I guess I need multiplex pots.

I need 12 or 18 switch inputs.

Everything els is bonus.

If price is low, of course that is good!

I will be doing a special dimmer for my flightsimulator project that can do it all.

DIM LEDs
DIM OEM 5volt light bulbs
DIM 5, 12, 28 Volts
Set 3 diferent curves depending on typ of light.

Ofcorse flimmer free and dim as low as possible.

I managed to do this so far:

A long way left, plus I am going to design the pcp.

Smal note it need to handel at least 150W in 5Volt.

Could you split discussion of the whole project into a new topic? And confine this thread to the PWM issues?

Perhaps I misunderstood.

“Resolution” (via analogWriteResolution) gives you more values of brightness. This is most noticeable at the low end, where a value of 1 = 2% brightness for 8 bit, but 0.001% for 16 bit. This was important in one of my projects because I wanted smooth fading at the low end. For example, going from 10 to 9, with 8 bit resolution: you notice a “bump” in the brightness. But with 16bit, going from 2569 ( same as 10@8bit) to 2568 does not visually “bump”. I picture it as “more steps between 10 and 9”. And that does give smooth fading at low values.

Above about 30 (@ 8 bit), I find that the resolution doesn’t matter for LED brightness.

Do you need more steps for something? Does your project need to do stuff at dim values?

Frequency is how fast (handwave) it turns the LED (pwm) on/off. You can imagine a frequency of 10Hz would have a very visible flicker. And a 10KHz would not, even under fast motion. There is no convenient support for changing frequency in Arduino land (but there is in circuitpython land!). I avoid register twiddling, as it is almost never worth it to me.

Do you actually see a flickering at the default PWM frequency, for your use? You could use an external PWM board, like this. I used that board, and then discovered analogWriteResolution (poorly documented, remember?). Some boards have a higher PWM frequency than the default Arduino.

Sound. I assume that you are referring to a high-pitch sound that can happen with PWM. I have nothing intelligent to say about this! Does it already happen for you? :man_shrugging:

In conclusion, you seem to be asking for 2 things: resolution and frequency. My node only deals with resolution.

So is it possible to change the resolution out to PWM in XOD? What hardwar (IO card) do you sugest to use then, if I want 6-8 PWM outputs. I dont think I need 16bit but 12 would be good. As you sad I only think this is inportant at the lower end of brightnes.

I can see som flickering with how I connected things, but that maybe has not to do with frequency. I dont know what defult frequensy Arduino Have, but as you sad 10Khz is probably sufissiant.

What I could google Arduino UNO use lower frequency. below 1Khz.

I am open for using any IO card, as long as it not to expencive and have a smal footprint.

Again, the node I wrote (see .xodball above) does this. However, ONLY for SAMD boards.

Adafruit’s Feather M0 or Feather M4 has many PWM outputs (and is SAMD). Adafruit’s ItsyBitsy (M0 or M4, also SAMD) has 13 PWM. Both do at least 14 bits, I believe (I think they actually do 16 bits).

If frequency is still a concern, you’ll have to try to evaluate various boards, like: Breakout Boards, PWM Drivers Products Category on Adafruit Industries . Getting them to work with XOD is another question!

I could not find that node in XOD?

Am I missing something?

But you sad you hade used something like that in a erlier project?

What card did you use then?

Yes. I wrote the node, it is not part of XOD. You have to download it. It is uploaded in this topic, at:

a reply with the xodball

But, here is the link to the xodball:
https://forum.xod.io/uploads/short-url/xQ8z7gYtAnrtOx2xnMijfCwpz1b.xodball

This, I did not use XOD. I used Arduino IDE.

This is a explanation how far I have come:

I think the led node works farly well.

If I ca use Teansy and skip the min value, I dont have to use Multiplex, then I can use 12 pots for controling 6 PWM outputs.

Does this work on Teensy?

Also wonder if I in som way can connect the Freetronics N-Drive Shield to Teensy or Adafruit SAMD boards, with the regards to 3.3V

I found this: gst/pwm-prescaler-set — XOD

Could I test this in the wait of cards? Or does it not do the same as your node?

Regards Jacob!