MCUdude / MegaCoreX

An Arduino hardware package for ATmega4809, ATmega4808, ATmega3209, ATmega3208, ATmega1609, ATmega1608, ATmega809 and ATmega808
GNU Lesser General Public License v2.1
247 stars 52 forks source link

analogWriteFrequency(kHz) to analogWriteFrequency(Hz) #184

Closed ltwin8 closed 1 year ago

ltwin8 commented 1 year ago

hello, is it possible to change analogWriteFrequency(kHz) to accept Hz?

to avoid bricking existing code it could be like if value <=64 interpret as kHz, else interpret as Hz

PWM frequencys below 1 kHz would be useful in some cases like driving lighting to avoid high frequency and allow for slower edges (EMI friendlier)

MCUdude commented 1 year ago

Sorry, but setting arbitrary PWM frequencies is not possible. You can try setting a lower main clock frequency (something lower than the default 16 MHz) and play around with the TCA0.SPLIT.CTRLA register to see what you can achieve.

https://github.com/MCUdude/MegaCoreX/blob/d0f0eff16e6d214397e13ca21dd24e53046e42e8/megaavr/cores/coreX-corefiles/wiring_analog.c#L196-L230