Hi Everyone,
Happy arduino user here, and also first post on this forum, so if it's not in the correct section i will gladly modify it.
I recently wrote my own code to make music with a stepper motor, using tone() function.
I'm quite happy with it, but the pitch resolution gets lower and lower as the frequency goes down (there are only 31 values between 31 and 62 Hz).
The result is the stepper motor sounding more out of tune as he gets to its bass register, either too sharp of too flat, depending on the frequency value rounding result.
My questions are : is it possible to modify the Tone() function to accept float as frequency input and output the correct frequency ?
Is it enough to just replace this :
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
by this ?
void tone(uint8_t _pin, float frequency, unsigned long duration)
I make progress, but the tone() code is currently too complex for me to understand well.
I don't think the hardware clock, either 8 or 16 mhz will be an issue, as it already provides good resolution for higher notes.
Is it simpler to write another function from scratch ? I was thinking of doing it using micros().
As tone() is used in many projects, and as i didn't find any good replacement, I think it would be a great improvement to be able to generate precise frequencies in the bass register.
Thanks for reading !
Paul