AVR unstable w/ buzzer

Go To Last Post
25 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I'm just working on ATMega8535 recently on an alarm clock project. The problem is, whenever the buzzer (the one that beeps when connected to DC power) starts beeping with a PWM, the AVR becomes unstable and running amok, blinking LED and sounding the buzzer not as it should be.

I've tried many different circuits for the buzzer but it just doesn't work anyway :(. What could be the possibility for my problem?

Regards :D

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We cannot possibly know. Try posting schematic and code and then we can tell you.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Pardon, but I can't post the code because it's horribly long :?

The schematic is really simple, overall it's just an LED connected to OC1A pin (toggled by timer1 CTC), and a buzzer connected to OC2 pin (driven by timer2 PWM). I don't see any problem with the code, however..

When the buzzer starts sounding, the LED's flash is a little distorted. The moment the LED is off, the buzzer produces a strange noise even though the timer2 is stopped (no PWM driven into buzzer). And after a while, the AVR reset by itself :?

That's what I can tell.. Any help? :?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Vashikovich wrote:
The schematic is really simple, overall...
So just 3 components in absolute total - one AVR, one LED and one buzzer? I guess not, so how about a schematic? And exactly what sort of buzzer (data sheet?)

It's almost certainly an electrical problem associated with the AVR driving the buzzer, but until there is a schematic...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We don't know what kind of buzzer it is.

Is it just a piezo disc, driven with square wave by AVR?

Is it a 5VDC 1mA buzzer, or 120VAC 1A buzzer?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are there decoupling capacitors?
Is your LED current limited via a resistor?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What kind of power source, transformer, battery, nuclear?

Do you have a regulator?

True, at this point, we need the schematic first, no software.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It smokes where voltage meets low resistance.
What current DMM reads for the buzzer connected to 5V DC?
Is the mode of operation cited below correct:

Quote:
one that beeps when connected to DC power) starts beeping with a PWM
?
Is this used for volume regulation maybe?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using 5V buzzer with this datasheet (http://www.electro-tech-online.com/custompdfs/2011/09/BUZZ.pdf), the one that beep with just DC power connected to it.

Power supply is linear with transformer, rectifier, caps filter, LM317 (regulating at 12V or 15V, I don't remember), and further 7805 for 5V.

Look, I've tried stripping any other components besides the AVR and the buzzer itself (except keypad for input), so it's only AVR, buzzer, and keypad, nothing else matters. I've also tried connecting buzzer directly to AVR pin, through transistor, and through darlington pair, but it's still the same.

The main idea is, I'm using Timer1 CTC for counting second, Timer2 PWM for driving buzzer with different tones, and Timer0 for counting musical measures. From what I hear from the buzz, it seems kinda like the timers clashing or what. When the output pin of Timer1 is low, the buzzer produces strange noise but not otherwise. After sometime, it changes the music by itself. And after some other time, the AVR reset by itself, too.

Here is the code regarding the situation :

//This part is for clock display only, and I have stripped them all already. The clock is displayed with the means of scanning and POV.

if (LEDSTATE == 1) {
                         
                        // Hour, 1st Digit
                        Display(hour/10);
                        STCP = 1;
                        SS1 = 1;
                        SS2 = 0;
                        SS3 = 0;
                        SS4 = 0;
                        STCP = 0;
                        delay_ms(1);
                             
                        // Hour, 2nd Digit 
                        Display(hour%10);
                        STCP = 1;
                        SS1 = 0;
                        SS2 = 1;
                        SS3 = 0;
                        SS4 = 0;
                        STCP = 0;
                        delay_ms(1);
                             
                        // Minute, 1st Digit
                        Display(minute/10);
                        STCP = 1;
                        SS1 = 0;
                        SS2 = 0;
                        SS3 = 1;
                        SS4 = 0;
                        STCP = 0;
                        delay_ms(1);
                            
                        // Minute, 2nd Digit
                        Display(minute%10);
                        STCP = 1;
                        SS1 = 0;
                        SS2 = 0;
                        SS3 = 0;
                        SS4 = 1;
                        STCP = 0;
                        delay_ms(1);
                        
                  } else {

                        SS1 = 0;
                        SS2 = 0;
                        SS3 = 0;
                        SS4 = 0;
                        
                  }

                  // This part is where the music comes. I want the music to play while the clock is displaying and flashing.
                                 
                  if (TIFR & (1 << TOV0)) {
                        tonemeasure++;
                        tonemeasure %= 30; 
                        switch (tone) {
                              case 1 :
                                    OCR2 = 1;     //B6
                                    switch (tonemeasure) {
                                          case 0  :
                                          case 6  :
                                          case 12 :
                                          case 18 :
                                                TCCR2 = 0x1F;
                                                break;
                                          case 5  :
                                          case 11 :
                                          case 17 :
                                          case 23 :
                                                TCCR2 = 0x00;
                                                break;
                                    }
                                    break; 
                                case 2 :
                                    OCR2 = 1;     //B6
                                    switch (tonemeasure){
                                          case 0  :
                                          case 15 :
                                                TCCR2 = 0x1F;
                                                break;
                                          case 13 :
                                          case 22 :
                                                TCCR2 = 0x00;
                                                break; 
                                    }     
                                    break;
                                case 3 :       
                                    OCR2 = 1;     //B6
                                    TCCR2 = 0x1F;
                                    break;
                                case 4 :
                                    TCCR2 = 0x1F;
                                    srand(TCNT1);
                                    OCR2 = rand() % 15;   //C4--B7
                                    if ((tonemeasure % 10) == 0) {
                                          OCR2 = rand() % 15;   //C4--B7
                                    }     
                                    break;
                                case 5 :
                                    TCCR2 = 0x1F;
                                    switch (tonemeasure % 10) {
                                          case 0 :
                                                OCR2 = 6;
                                                break;
                                          case 1 :
                                          case 9 :
                                                OCR2 = 5;
                                                break;
                                          case 2 :
                                          case 8 :
                                                OCR2 = 4;
                                                break;
                                          case 3 :
                                          case 7 :
                                                OCR2 = 3;
                                                break;
                                          case 4 :
                                          case 6 :
                                                OCR2 = 2;
                                                break;
                                          case 5 :
                                                OCR2 = 1;
                                                break;
                                    }     
                                    break;
                        }
                  }

[url][/url]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So it has current rating pretty close to the limit.
Yet another thing it's DC. Driving it PWM (that is AC with high harmonic content) is not the best idea: these have internal circuitry.
From the code it looks You need piezo speaker instead. It will happily accept PWM or whatever for melody output. MOSFET or BJT in different configurations can be used for increasing resulting SPL if needed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The buzzer current consumption may be rather large to be directly connected to AVR IO pin, it is up to 30mA at 5V.

Now do you have a resistor between AVR and the LED?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
The buzzer current consumption may be rather large to be directly connected to AVR IO pin, it is up to 30mA at 5V.

Replace that buzzer with piezo speaker. Use a transistor fir driving it.
Preserve buzzer for the future projects.

Quote:
Now do you have a resistor between AVR and the LED?

The best would be 0,5 kOhm or around in series. But after the first step You probably do not need it (LED test I have non my mind).
Edited

Last Edited: Fri. Aug 10, 2012 - 11:21 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kas wrote:

The best would be 0,5 kOhm or around in series. But after the first step You probably do not need it.

No, there must always be a resistor between AVR and LED! There are per-pin and per-group specific limits that should not be exceeded or operation of chip is not guaranteed, it may even break. Without this resistor some logic blocks inside the AVR may run with lower supply voltage when LED is on, and most likely it won't work.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh yeah, I forgot. As in normal alarm clock, the music plays in 2 occasions, one when selecting the desired ringtone and one when the alarm is actually set off. On the former, the buzzer and the ringtone play perfectly without any problem, but on the latter occasions it misbehaves as like I described earlier. The software part for playing the music is exactly the same, however..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually, all current-demanding parts like LED and buzzer is driven through ULN2803 darlington. And all of it except buzzer has already been stripped down, so the LED and the current won't be a problem..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So what happens if you:
- temporarily just make the buzzer output pin high, rather than PWM'ing it
- temporarily use another LED instead of the buzzer.

The results should pretty clearly indicate what is wrong.

And as you won't post a schematic, with or without component values, what value reservoir capacitor do you have?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Perhaps Monsieur OP does not have any schematic (everything is possible, on this earth) but could post photos of the upper and lower sides of his board?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here's the schematic. It's the only one I have, though not quite right.
- The LCD is currently disconnected.
- The 4 inverters is actually ULN2803, and it's also currently disconnected.
- The LED is connected through ULN2803 + 220R, also disconnected.
- The buzzer is currently connected with a transistor.
- There is a 470uF caps going from VCC to GND.

That's it :D[/img]

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You should add 100 nF decoupling capacitors for each circuit (i.e. at least your 8535, as electrochemical capacitors such as 470uF may have very poor high frequency bypassing properties).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The buzzer buzzes when you put steady 5V on it?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
What could be the possibility for my problem?

ATMega8535 is one of the OCD-less "entertaining" series. That is your problem.

Less seriously: What is your MCUCSR?

No RSTDISBL, no fun!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AVCC is not connected?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dbrion0606 wrote:
You should add 100 nF decoupling capacitors for each circuit (i.e. at least your 8535, as electrochemical capacitors such as 470uF may have very poor high frequency bypassing properties).

What do you mean by "for each circuit"? Do I need to replace the 470uF or left it intact?

Anyway, I think I've found the problem. When I increase the base resistance of the transistor that drives the buzzer, it behaves much more normally :D So, I think it's some sort of over current, but I still wonder why it's so significant although only <30 mA..

Thanks anyway for all you guys' cooperation :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One of the goals in electronics design is to know, exactly, why one's design either works, or failed.

If you don't figure out exactly why the circuit failed, then it is very difficult to be sure that you have actually solved the problem.

If you actually post a true schematic, showing what the current circuit is, with all the included parts actually included in the schematic, and all of the not included parts not drawn in the schematic, you might get some further feedback regarding your design, and suggestions for making it more reliable.

If you don't have a schematic drawing package you can download the ExpressPCB package, for free. You do not have to use its PCB layout or board ordering. You can use its schematic drawing program and export the file to a BMP file. It would then be best to convert the BMP file to a JPG file for the Forum. This is usually simply a matter of viewing the BMP file with your favorite image processing program, (such as IRFAN), and then saving it in the JPG format.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
What do you mean by "for each circuit"? Do I need to replace the 470uF or left it intact?

Every circuit -AVR, 74HC595,74HC04 - should be decoupled by 100 nF (to avoid spurious oscillations : cards in the 1980s had already that, it does not cost that much, and does not harm).
The 470 uF should not be replaced (can be used as a reservoir capacitor ) but 100-300 nf should be put in parallel to avoid ascillations from your regulator (depends on the series: this is recommanded by the manufacturer, and detecting spurious oscillations is very complicated and time consuming).