Shop OBEX P1 Docs P2 Docs Learn Events
Digital noise on buzzer — Parallax Forums

Digital noise on buzzer

T ChapT Chap Posts: 4,223
edited 2010-10-17 20:48 in General Discussion
An LM386 is driving several buzzers from a Prop pin to increase the volume. There is a high pitched noise that is always audible if I2C is scanning some devices. I need a board fix to solve this, it is not possible to redesign the layout right now. There is already an FET that acts as a shunt to GND on the input of the 386, which serves to allow variable buzzer volume. When the FET is open(megohm), the digital noise is lowest, but when it is closed (~32ohms) and shorting the input to GND, then the noise is higher. I had hoped the shunt could be used to turn off the noise when buzzer is not in use, but as you can see the opposite effect occurs.

Can anyone suggest a quick and easy board fix? The buzzer operates from 1k to 3k, so I am guessing a filter may work, but really don't want to alter the buzzer sound as it is required for feedback.

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-10-16 12:04
    Can you post a schematic, please? And maybe an image of your layout?

    -Phil
  • T ChapT Chap Posts: 4,223
    edited 2010-10-16 20:07
    Phil, I will get a pic off my shop computer (with Eagle) on Sunday. I did look at it today, and recall that the issue started when I changed the design to include an I2C extender chip which has rigid pullups to 5v. Unfortunately, I see the data line running directly under the optofet that is the shunt to the input on the LM386. There is a 10K res that is in the path from the Prop buzzer output pin to the 386 input. If I short across the resistor, the noise stops. But with the direct short, the shunt can't work by pulling the input to GND(varying resistance) to set the beep volume. I tried putting some small caps from the input to GND thinking they might quieten things up, no luck.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-10-16 20:45
    Rather than using the shunt, could you just modulate the output level using a DUTY mode counter to generate the audio?

    -Phil
  • T ChapT Chap Posts: 4,223
    edited 2010-10-16 22:06
    Here is how I generate the beeps. I did not know you could adjust the beep volume by any other means than external of the Prop. The code is a modified piezo object, using only one counter instead of the two from the object, I can't spare a counter in the main program. If you know a way to reduce the volume please let me know, then I can bypass the 10k between the Prop and the 386 input and probably be fine.
    pub beep(pinn, freqq, durr)
        if durr <> 0                                                       
          durr--
    
          ctrb[30..26] := %00100
          ctrb[8..0] := pinn
          frqb := calcfrq(freqq)
          if durr <> -2
            phsb := 0
          dira[pinn]~~                                            
          if durr <> -2
            repeat durr * 100 
            waitpeq(0, |< pinn, 0)                                        
            ctrb := 0
            dirb[pinn]~
            ctrb := frqb := 0
            durr := 0                                              
    
    pri calcfrq(f)
    
      repeat 33
        result <<= 1
        if f => clkfreq
          f -= clkfreq
          result++
        f <<= 1
    
    
  • LeonLeon Posts: 7,620
    edited 2010-10-17 02:47
    Using PWM will give control over the amplitude, as Phil pointed out.
  • T ChapT Chap Posts: 4,223
    edited 2010-10-17 06:49
    I experimented with setting duty to control the volume and that is great, but requires a dedicated cog running PASM, unfortunately the program can't spare(or rob) anything in this case.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-10-17 10:54
    Here's a program that will work for you:
    CON
    
      _clkmode      = xtal1 + pll16x
      _xinfreq      = 5_000_000
    
      AUDOUT        = 11
      FREQ          = 880
    
    PUB start | vol
    
      repeat
        repeat vol from 1 to 11
          beep(AUDOUT, FREQ, 500, vol)
          waitcnt(cnt + clkfreq / 2)
    
    PUB beep(pinn, freqq, durr, voll) | period, cycles, frqhi, frqlo, t
    
    '' Send a squarewave to pinn of frequency freqq for durr milliseconds.
    '' Volume level is determined by voll (0 - 11) and exponentially increasing.
    
      if ((period := clkfreq / (freqq << 1)) < 4000)
        return
      cycles := freqq * durr / 1000
      if (voll)
        frqhi := $10_0000 << (voll #> 0 <# 11) - 1
      else
        frqhi := 0
      frqlo := 0
      frqb~
      ctrb := %00110 << 26 | pinn
      dira[pinn]~~
      t := cnt
      repeat cycles
        waitcnt(t += period)
        frqb := frqhi
        waitcnt(t += period)
        frqb := frqlo
      dira[pinn]~
      ctrb~
    
    It uses the timer to generate a DUTY mode output on the positive swings of the square wave, and a low on negative swings, thus effectively modulating the volume by the value of frqb. I've set it up for a 12-level, exponentially increasing volume range, but the range and taper can be programmed any way you like it. Or just use the raw frqb values for voll. The routine returns without doing anything if freqq is above 10KHz at 80MHz clock speed, although this is a very conservative limit.

    BTW, if you need additional filtering to accommodate the DUTY mode output, you should be able to replace your shunt transistor with a cap and adjust the series resistor for the right time constant.

    -Phil
  • T ChapT Chap Posts: 4,223
    edited 2010-10-17 12:40
    Wow Phil. That is some very clever trickery. I don't get how it is working but it does, so I will hardwire past the series resistor and call it a day. THANKS!
  • T ChapT Chap Posts: 4,223
    edited 2010-10-17 20:42
    I like this concept Phil, I don't think I have seen this done before with the Prop but have wanted to explore this area of modulating a signal for volume purposes. I was attempting this but did not have any luck with my ideas. What is interesting is that you can create a frequency(tone/beep etc) with just the counter, but in your example, the actually frequency of the beep is determined by the periods on and off, while the counter frequency is simply affecting the intensity or volume of the beep.
    392 x 262 - 16K
    vol.jpg 16.5K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-10-17 20:48
    That's close. The difference from your illustration is that the counter output is DUTY mode, which is like PWM but with a very high frequency and a less regular period. The frqb value determines the percentage of time that the pin is high, not its output frequency. This is because the level that goes to the pin is the carry out of phsb, not the value of its high-order bit. A simple low pass RC filter can then convert the DUTY output to an analog level.

    -Phil
Sign In or Register to comment.