Skip to content

Using float vs long as input for adding precision for fast timers #10

@m00dawg

Description

@m00dawg

First I love this library! Given the SAMD51 docs and all the config options, and how those end up being presented in Arduino/Wire, it's a bit of a soup. This library makes all that dramatically easier.

Since I needed multiple timers I ended up having to change the library around for my own needs though it's mostly just changing which timers I'm using. Notably though I found that changing the input from long to float for the setPeriod function avoided some stairstep/cliffs I was getting due to rounding erros.

There's already floating point math happening here:

  int compareValue = (int)(GCLK1_HZ / (prescaler/((float)period / 1000000))) - 1;

So my suggestion is to basically make the period a float as input.

I did that to my customized version of the lib and it made a substantial difference to my application (which involves variable clocking the DAC for audio output).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions