sduino icon indicating copy to clipboard operation
sduino copied to clipboard

tone() support or workaround?

Open H3wastooshort opened this issue 4 years ago • 4 comments

I would really like to have the tone() function or some way to replicate it's functionality, if it's not too much of a hastle to implement. AFAIK from the Datasheet, the STM8S003?3 series has a built-in tone generator.

H3wastooshort avatar Mar 13 '21 12:03 H3wastooshort

It has a tone generator, the "BEEPER" periperheral. That thing however only has 3 possible output frequencies: 1, 2 or 4 kHz (refer datasheet / user manual and e.g. here). So it can't support arbitrary audible frequencies from like 0-44kHz with that.

But ofc it should be possible with a timer / PWM output. I've outlined some initial ideas some time ago there.

However a simple high-low write and a microsecond delay works on my STM8S103F3 (and pretty much every other). I've slightly adapted a sketch for a tetris theme and it plays nicely on a buzzer, with simulated 2-tone polyphony, with the play_one_note function as basis.

maxgerhardt avatar Mar 22 '21 22:03 maxgerhardt

for what it's worth, I added an implementation here : https://github.com/stefaandesmet2003/sduino It's using TIM2 (similar to AVR), but STM8 TIM2 is 16-bit. STM8S003 has TIM2 peripheral, so it should work too.

stefaandesmet2003 avatar Apr 12 '21 09:04 stefaandesmet2003

very cool! you can open a pull request

H3wastooshort avatar Apr 14 '21 12:04 H3wastooshort

agree, but it looks like this repo is a bit stalled for the moment

stefaandesmet2003 avatar Apr 14 '21 14:04 stefaandesmet2003