Go Down

Topic: Arduino Tone Library at Low Clock Speeds (Read 337 times) previous topic - next topic

monkey123

Hellooo! Simple question here... Does anyone know how to get the Arduino Tone library working at a system clock of 8kHz? Yes, I know that is slow. But I must get some kind of audible tones at that clock speed, just a couple of audible beeps.

Or if there is another option using just the Arduino I am open to that as well! Preferable if the method could work on any output, but DAC only is ok if it's a must.

pert

If you use an active piezo buzzer, it has the circuitry to generate an audible frequency built in to the buzzer so all you need to do to get a beep is set the output pin HIGH. Most of the piezo buzzers that are in an enclosure (rather than just the bare piezo discs) are active.

monkey123

If you use an active piezo buzzer, it has the circuitry to generate an audible frequency built in to the buzzer so all you need to do to get a beep is set the output pin HIGH. Most of the piezo buzzers that are in an enclosure (rather than just the bare piezo discs) are active.
I need to generate the tone on the chip, to send the tone to another device.

I understand a slower clock speed may limit the range of frequencies that can be generated, but as long as I can get some good audible tones it's fine.

Gerihatrick

Some time ago I used the NewTone library as it was better in most areas but specifically lower frequencies. It maybe worth a look

Grumpy_Mike

Quote
But I must get some kind of audible tones at that clock speed, just a couple of audible beeps.
You can. If you don't mind blocking code simply write successive zeros and ones to a pin in a tight loop. As digitalWrite has such a high overhead in terms of clock cycles then use direct port addressing to make the tones in the audible region.

monkey123

You can. If you don't mind blocking code simply write successive zeros and ones to a pin in a tight loop. As digitalWrite has such a high overhead in terms of clock cycles then use direct port addressing to make the tones in the audible region.
i.e. digitalWrite(1); digitalWrite(0); back and forth many times? How do you alter the tone from one pitch to another?

Grumpy_Mike

#6
May 08, 2019, 06:47 am Last Edit: May 08, 2019, 06:52 am by Grumpy_Mike
Quote
back and forth many times?
Yes normally in a for loop where the number of times the loop runs is the number of cycles you need to generate.

Quote
How do you alter the tone from one pitch to another?
You alter the two delays between the toggling of the output pins.
So before ( or after ) the digital write you put a delay of some sorts. Running at such a low frequency I am not sure if you will get much joy from the delay function but try it.

By the way this requirement to have different frequency of tone was not stated originally, this is the first we here of it.

Go Up