SpenceKonde / megaTinyCore

Arduino core for the tinyAVR 0/1/2-series - Ones's digit 2,4,5,7 (pincount, 8,14,20,24), tens digit 0, 1, or 2 (featureset), preceded by flash in kb. Library maintainers: porting help available!
Other
558 stars 146 forks source link

Tone seriously broken? - It is implausible that it does not impact all parts, and there is a good chance that DxCore is also impacted. #369

Closed SpenceKonde closed 3 years ago

SpenceKonde commented 3 years ago

It seems there's a bug in the tone() function on the ATTiny1604 (possibly others, I don't have any others handy to test on at the moment). If you call the tone function with a duration specified:

tone(TONE_PIN, 440, 500);

It doesn't actually generate a tone output, it just toggles the specified pin high for the specified duration and then low again.

If you call the function with no duration, it generates the tone as it should, however if you then call noTone(); it stops generating the tone output, but it leaves the pin high, pumping DC into the speaker coil. The pin has to be manually set low again following noTone();

Originally posted by @hamsterdave in https://github.com/SpenceKonde/megaTinyCore/discussions/362

SpenceKonde commented 3 years ago

hum... it also doesn't appear to get the frequency right...

SpenceKonde commented 3 years ago

/facepalm yes, of course it does , but not if your whole loop body consists of one call to tone() so it's continually restarting the tone...

SpenceKonde commented 3 years ago

Okay the non-duration caases are sorted out....

SpenceKonde commented 3 years ago

Hmmm, @hamsterdave - I can't reproduce your reported issue with it failing when a duration was specified. - but I don't think any of the fixes I put in would have mae a difference on that front.....

Maybe I'll go try with a 1604....Nope, working there too. Though there was definitely a bug with it leaving outputs high, no question

SpenceKonde commented 3 years ago

@hamsterdave - I have corrected github version, but I was never able to reproduce the behavior you saw with it just leaving the pin high for the duration instead of outputting a tone... Is that one still reproducing for you with latest code? If it is, let me know and post or send me a sketch that causes it