On 7/9/07, Russell McMahon wrote: > >> now I am driving it from 2 cpu pin's with complimentary outputs > > Two pin drive allows you to do what you want. > For full volume at a given frequency you flip pins simultaneously. > For variable amplitude: > > Short answer: > > - Use complementary PWM on the two pins and low pass filter (or use > PWM so high that the result is inaudible). Switching a PWM for an inaudible signals equal creating EMI and noise on the board for nothing while some power is used for this. > - Alternate PWM mark space ratio at twice the desired output > frequency. > > PWM near 50:50 produces zero output. > Moving to more uneven mark/space ratios increases output amplitude. > > Amplitude = 2 x (50 - mark%*) % of full scale > > * use larger of mark or space % here to avoid negative sign > which is meaningful but not useful here. > > By suitable amplitude shaping within each output half cycle you can > produce a sine wave or any other desired waveform. > > PWM can be done in hardware (if complementary PWM hardware facilities > available) or software. > > Other mark space schemes than raw N:1 will allow lower update > overheads. > > Processing overhead may be severe for wide ranging volume variations. > > > > 2. Another method will less processor load is to use one pin to > produce tone out and PWM modulate the other at a somewhat higher > frequency to chop the tone. Filtering needed to deal with nasty > intermod sounds. Single pin output halves transducer drive voltage > over toggled pair system and may reduce max sound level to 1/4 > depending on transducer. This methode is often named one pin for frequency, one pin for amplitude and works on both situation when the piezo has or not a transformer. Is the best way to do it. > > 3. A diode gate driven from a DC signal derived from control PWM > would lessen the PWM load and remove intermodulation problems. > > Wazzat - they don't teach people about diode gates anymore ? :-) > > > > __________________ > > Explanation of sorts: > > If you create a series of transitions at much greater rate than the > fundamental output frequency you can produce a PWM signal of varying > amplitude and with alternating polarity across the transducer at the > fundamental frequency. You will probably need to low pass filter > this - although if the transition rate is high enough this may be > avoidable. > > As a very simple example - imagine you want a 500 Hz signal - 1 ms > high then 1 ms low alternately at 10% of the amplitude of the full > scale signal. > > Repeat 100 times > Output state 10 for 4.5 uS. > Output state 01 for 5.5 uS > Repeat 100 times > Output state 01 for 4.5 uS. > Output state 10 for 5.5 uS > > First 100 steps produce a signal of 0.45 of full scale > Second 100 steps produce 0.55 of full scale. > Output signal is 0.1 of full scale. > > > > Russell McMahon > > > > > > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist