Pages: [1]   Go Down
Author Topic: Piezo is making a soft sound after having played a tone() - how can I stop it?  (Read 1558 times)
0 Members and 1 Guest are viewing this topic.
Zürich, Switzerland
Offline Offline
Newbie
*
Karma: 0
Posts: 40
Shall a gadget be useful?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

I connected a piezo speaker to a ATMEGA32U4 (pin 9). The other piezo-pin goes to ground

When I power up the board, the piezo is completely quiet. I then play a tone using tone(9,500,1000);. After having played the tone (and also after having executed noTone(9)), there is a soft hissing noise coming from the speaker.

Does anyone have any idea how to stop the noise?

Thank you,
Dani
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13870
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there a measurable voltage?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
God Member
*****
Karma: 15
Posts: 508
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Post your sketch.

I suspect this. When the sketch first powers up, all pins are in INPUT mode. This high Z input impedance causes there to be no current flow through the speaker, causing absolutely no noise.

When tone() is run, the pin is forced to OUTPUT. After noTone(), the pin is still OUTPUT, but written LOW. This is a low impedance output that can cause some currents and noise to flow.

After noTone(), try setting the pin to INPUT and see what happens.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34547
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
After noTone(), try setting the pin to INPUT and see what happens.
Yes, or write a logic LOW to the pin after the noTone.
Logged

Offline Offline
God Member
*****
Karma: 15
Posts: 508
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
After noTone(), try setting the pin to INPUT and see what happens.
Yes, or write a logic LOW to the pin after the noTone.
noTone() already does that.
Code:
void noTone(uint8_t _pin)
{
  int8_t _timer = -1;
 
  for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
    if (tone_pins[i] == _pin) {
      _timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
      tone_pins[i] = 255;
    }
  }
 
  disableTimer(_timer);

  digitalWrite(_pin, 0);
}
Logged

Pages: [1]   Go Up
Jump to: