Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: What is a/the use case for analogWriteResolution with resolution < 16?

  1. #1
    Junior Member
    Join Date
    Jul 2021

    What is a/the use case for analogWriteResolution with resolution < 16?

    Hi there,

    I'm studying the analogWrite and related functions (writeFrequency, writeResolution) on the Teensy 4.0 and after looking at the source code it seems like all the analogWriteResolution value does is scale the count value used by the PWM module... I'm just curious as to what use case a resolution less than 16 would have? Could it be useful for optimizing code somehow?

    From pwm.c in the Teensy 4 core:
    Line 143: 	uint32_t cval = ((uint32_t)val * (modulo + 1)) >> analog_write_res;
    This is the only spot I could find any mention of analog_write_res that wasn't just being passed along from analogWriteResolution.

    Hopefully this question hasn't been asked already - I couldn't find anything about it on this forum, but I'm also not sure my pjrc-search-fu is up to snuff... analogWriteResolution did not return many results.

    Thanks in advance


  2. #2
    Senior Member
    Join Date
    Dec 2013
    East Stroudsburg PA.
    You can find more information in this link: PWM Resolution (Teensy LC, 3.0 - 3.6, 4.0, 4.1).

  3. #3
    Senior Member
    Join Date
    Jul 2020
    If you want to generate very high frequency PWM perhaps?

    I've used limited resolution PWM at high speed to allow noise-shaping for instance. The noise
    shaping has the side effect of increasing the effective low-frequency resolution to much more
    than the actual resolution (the wonder of noise-shaping!) This is one way to directly output
    class D waveforms.

  4. #4
    Junior Member
    Join Date
    Jul 2021
    @Chris O. Thanks for the documentation - I remember looking that over, but I'm really glad I had another look - I guess the best use case is matching frequency to resolution so that each possible value used with analogWrite has a distinct output.

    @MarkT That's really interesting! I researched noise shaping a bit and it's still a bit over my head but it seems like a good use for analogWriteResolution. Thanks for sharing!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts