adafruit / seesaw

I2C friend to expand capabilities of other chips.
Other
76 stars 34 forks source link

setPWMFreq() not working #57

Closed evtimmy closed 1 year ago

evtimmy commented 2 years ago

Setup

Running the following code while varying the frequency parameter (between 0 to 60Khz in increments of 100):

  seesaw.setPWMFreq(5, frequency);
  seesaw.analogWrite(5, 127);

Expected: The pwm frequency to closely match the requested frequency.

Actual: Generated pwm wave has frequency either 300Hz or 660Hz or some very low frequency (similar to what's described here https://github.com/adafruit/seesaw/issues/55) when frequency 0 is requested. (observed with oscilloscope).

Any help to get this fixed/resolved appreciated!

evtimmy commented 1 year ago

Looks like setPWMFreq is actually working, but up to ~500Hz on SAMD09 and only a few increments. This is the code resposible for selecting the frequency, the frequency depends on the timer selected and the prescaler in https://github.com/adafruit/seesaw/blob/c22f5b564a60885baaad7a1223e918559606b1e5/bsp/bsp_timer.cpp#L111-L122

Closing this issue. For our purposes we would need a higher frequency, perhaps selecting a different timer for PWM on SAMD09.