Increase tone resolution

Small change to increase tone resolution by multiplying before dividing.
This commit is contained in:
stevstrong 2018-03-20 11:53:03 +01:00 committed by GitHub
parent 54c6896180
commit 41b165cae0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -151,7 +151,7 @@ void tone(uint32_t pin, uint32_t freq, uint32_t duration) {
tone_ncount = tone_n = (count>>16)+1; // number of 16-bit count chunk tone_ncount = tone_n = (count>>16)+1; // number of 16-bit count chunk
tone_tcount = count/tone_ncount; // size of count chunk tone_tcount = count/tone_ncount; // size of count chunk
if(duration > 0) // number of half waves to be generated if(duration > 0) // number of half waves to be generated
tone_nhw = ((duration*freq)/1000)<<1; tone_nhw = (2*duration*freq)/1000;
else // no duration specified, continuous sound until noTone() called else // no duration specified, continuous sound until noTone() called
tone_nhw = 0; tone_nhw = 0;