Shop OBEX P1 Docs P2 Docs Learn Events
Is it possible to change the volume of a piezo in software — Parallax Forums

Is it possible to change the volume of a piezo in software

Brian CarpenterBrian Carpenter Posts: 728
edited 2006-06-01 04:45 in General Discussion
i read someware that if i use a reistor ladder and a few different pins this would be atainable.· Any thoughts?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


It's Only A Stupid Question If You Have Not Googled It First!!

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2006-05-31 14:57
    How are you operating the piezo?

    Are you driving it at a fixed frequency, or does it vary within the application?

    If it is a "fixed" frequency, then you might be able to find a resonate frequency near the frequency that you desire.

    My point is that the resonate frequency will be noticeably louder than a non-resonate frequency. Using this characteristic,
    you could effectively change the volume simply by shifting the frequency slightly in or out of resonance.

    To find the resonate frequency, just create a test program to sweep a range of frequencies and note where certain peaks are.


    Here is a push-pull Piezo amplifier circuit that will efficiently drive a piezo off of a single I/O pin.
    http://forums.parallax.com/attachment.php?attachmentid=36227

    Also, check out this thread...
    http://forums.parallax.com/showthread.php?p=468648

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Benjamin_bakerBenjamin_baker Posts: 18
    edited 2006-06-01 03:05
    It would be attainable with a resistor ladder and a few different pins. That's what people mean by accomplishing something in hardware. changing the volume in software would be an alteration of the 5Vp-p waveform to produce those changes. Beau's idea is awesome, and you probably wouldn't be able to tell the difference in tone (the ear is a tricky thing) What is your application, and how many levels of volume do you need?

    P.S. the datasheet for your piezo speaker probably has an average figure for the resonant frequency of that specific speaker, you could start your search around there.
  • pjvpjv Posts: 1,903
    edited 2006-06-01 04:45
    Hi Altitudeap;

    There are yet several other ways to achieve this. If you simply want medium to low volume, just create a single ended (one side of the piezo grounded) pulse-density modulated DAC output that alternates between two voltage levels at the desired resonant frequency of the piezo. Typically somewhere in the 2.5 kHz range. This requires only one DAC (one port bit, a resistor and a capacitor), and the volume is determined by the levels chosen for the DAC levels. And those can be determined in software. Altogether probably a dozen or so lines of ISR assembly routine.

    If you need low to higher volume, then make two of those, and run them in opposite phase. This requires two DACs (two port bits, resistors and capacitors), and around two dozen lines of ISR assembler code.

    These two approaches use the DACs to generate square waves. You can also go fancier, with another dozen or so lines and generate sine waves, but for a piezo which has a very dominant fundamental, that might not be worth it. You'll have to try.

    You can garner a lot of what I'm referring to here, including dual sinewave generation software from perusing one of my entries in last year's Parallax contest. There, with two DACs, I created two separate sinewaves, each of a selectable frequency. If you chose the frequencies to be the same, then also the phase between them can be selected. That is a third way to generate variable levels; the difference between two sinewaves of the same frequency and amplitude is itself a sinewave of the same frequency; its amplitude is a function of the phase relationship between the two; zero when in-phase, and maximum when fully out of phase.

    Have fun trying this.

    Cheers,

    Peter (pjv)
Sign In or Register to comment.