This is expected and should be documented properly, but is not otherwise a problem AFAICS. Of course, the timer frequency is shared between channels of the same timer, so this API would change the frequency of all pins on the same timer. This could also be the default, but then there is no longer any easy way to change the frequency for all future analogWrite() calls. This explicitly specifies to not change the frequency. Something like this could be added using something like: A more obvious approach is to setup the timer frequency (prescaler and ARR value) once and then just use the existing value when calling analogWrite(). Having said that, there are certainly sketches where a "set frequency for all analogWrites"-approach is easier, so the current analogWriteFrequency() still makes sense (but can nicely co-exist with the above suggestion by using the analogWriteFrequency-specified default when no frequency is passed to analogWrite().Ĭurrently, every time analogWrite() is called, the timer is configured completely, including the PWM frequency. This removes the hidden global state and makes the analogWrite() calls predictable again. To solve this, it might be good if you could pass the frequency to use as an (optional) argument to analogWrite() directly. to really make this work generically, you would need to call analogWriteFrequency() before every call to analogWrite() (and again afterwards to restore the default if there is also code that is not aware of analogWriteFrequency(). This works, but when working with different libraries or code files (with different frequency requirements), this can be a bit cumbersome because this function hides some global state. Currently, there is an analogWriteFrequency() that sets the frequency for all future analogWrite() calls on all timer channels.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |