Shop OBEX P1 Docs P2 Docs Learn Events
Who needs a speaker amplifier when you have a spare H-bridge? — Parallax Forums

Who needs a speaker amplifier when you have a spare H-bridge?

Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
edited 2010-03-02 15:33 in Propeller 1
Ken sent me an MSR1 controller board with the robot base he built (link) as part of a project he wants me to do. Since the motor-and-wheel units require HB-25s to drive them, the L6205 dual H-bridge onboard the MSR1 was uncommitted. I thought it might be kinda cool if I could press it into service as a speaker amplifier. That way, a speaker could be used with the robot, without any need for external circuitry. Well, as usual, it wasn't as straightforward as I thought it would be.

The first thing I tried was a PWM approach in the 30KHz region. It made beautiful sine waves (once I figured out it needed some post-filtering — see below), but speech output was dreadful, sounding as if the speaker were at the bottom of a very deep well and unable to pronounce his esses. So, I decided to use a software duty mode approach instead.

The L6205 has two inputs for each H-bridge. If the input levels are [noparse][[/noparse]0, 1], the output swings one way; if [noparse][[/noparse]1, 0], it swings the other. [noparse][[/noparse]0, 0] and [noparse][[/noparse]1, 1] inputs produce no output drive. So, with audio, to drive the positive-going swings, you set output A to 0, and modulate output B. For the negative swings, you set output B to 0 and modulate output A.

The chip has a limited frequency response, so the modulating has to be done in software. A counter's DUTY mode output would be way too fast. This is unfortunate, since it means there will be some audible DUTY doody in the output that has to be filtered externally. I resorted to an LC filter, as pictured here:

attachment.php?attachmentid=68216

Using the object included in each of the attached archives, I was able to get the following output from a sine-wave test program input:

attachment.php?attachmentid=68217

Traces 1 and 2 are the outputs from the Prop to the L6205 inputs. Traces 3 and 4 are the filtered outputs from the L6205, sampled at the speaker terminals. The red trace is the difference between traces 3 and 4 and represents what the speaker actually sees.

Here's the PASM program that does the DUTY output:

L6205         [b]mov[/b]       [b]dira[/b],in1_mask           'Set pins for L6205 inputs to output.           
              [b]or[/b]        [b]dira[/b],in2_mask
              [b]mov[/b]       time,[b]cnt[/b]                'Initialize timer.
              [b]add[/b]       time,period

main_loop     [b]rdlong[/b]    amp,[b]par[/b]                 'Get the instantaneous amplitude.
              [b]test[/b]      amp,sign [b]wz[/b]             'Is it negative?
        [b]if_z[/b]  [b]mov[/b]       next_outa,in1_mask       '  No:  Output to IN1 pin.
        [b]if_nz[/b] [b]mov[/b]       next_outa,in2_mask       '  Yes: Output to IN2 pin.
              [b]abs[/b]       amp,amp                 'Convert to absolute value.
              [b]shl[/b]       amp,#AMPLIFY            'Shift by amplification factor.
        [b]if_z[/b]  [b]add[/b]       phs,amp [b]wc[/b]              'Add |amp| to phase if it was positive.
        [b]if_nz[/b] [b]sub[/b]       phs,amp [b]wc[/b]              'Subtract |amp| from phase if it was negative.
        [b]if_nc[/b] [b]mov[/b]       next_outa,#0            'Zap output if there was no carry.
              [b]waitcnt[/b]   time,period             'Wait for timing interval.
              [b]mov[/b]       [b]outa[/b],next_outa          'Write the output pins.
              [b]jmp[/b]       #main_loop              'Please, sir, may I have another?

in1_mask      [b]long[/b]      0-0                     'Pin mask for duty output.
in2_mask      [b]long[/b]      0-0                     'Pin mask for sign output.
period        [b]long[/b]      80_000_000 / RATE       'Sampling period.
sign          [b]long[/b]      $8000_0000              'Sign bit mask.

amp           [b]res[/b]       1                       'Cog copy of amplitude.
next_outa     [b]res[/b]       1                       'Next value to srite to outa.
phs           [b]res[/b]       1                       'Current value of simulated PHSx.
time          [b]res[/b]       1                       'Next interval value for cnt.




WARNING: There are no safeguards in this program to protect a speaker from burnout. If the instantaneous amplitude variable gets stuck on an extreme positive or negative value for a long period of time, the speaker could draw excessive DC current. Use at your own risk!

The sound fidelity is not as good as the output from the Demo Board amplifier, but it's good enough that I still plan to use it on the bot — and it is LOUD!

-Phil

_

Post Edited (Phil Pilgrim (PhiPi)) : 3/1/2010 7:41:44 AM GMT

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2010-03-01 07:40
    As usual Phil, another nice use for an existing circuit. smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
    · Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
  • Ken GraceyKen Gracey Posts: 7,386
    edited 2010-03-02 04:56
    Hey Phil,

    Short of hooking it up and trying it for myself could you give us some feedback on whether or not some of the speech synthesis work you've done sounds okay with this circuit?

    On my last robot I used an LM386 circuit but I look forward to trying out your solution.

    I really like the convenience of using existing circuits from our boards. Makes documenting our projects quite a bit easier.

    Thanks for sharing!

    Ken Gracey
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-03-02 07:50
    Ken,

    With the LC filter between the L6205 and the speaker, my phonemic speech synthesizer sounds "almost" as good as it would from a regular amp (which isn't saying a whole lot, I know). Without the filter, there's a lot of hash (DUTY doody) that degrades the intelligibility quite a bit. The filter I used was cobbled together from components I had on hand, and I need to come up with a more thoughtfully-engineered design for it. Something with a sharper high-frequency cutoff would give better results. It's definitely a work in progress, but the results are encouraging enough to continue the pursuit. It would be a shame to let the H-bridge go to waste!

    -Phil
  • TonyWaiteTonyWaite Posts: 219
    edited 2010-03-02 10:52
    Phil:

    A hat-trick comes to mind to make a very economic pink-noise source - entirely in Propeller software!

    Your fabulous, white/pink-noise generator, bandpass filtered 50-5000Hz by Ahle's SIDcog 'setCutoff' function, driving 6 H-bridges into 6 megaphone horns in a hemi-dodecahedron array. The target is 120dB sound-power.

    Have I missed something or is this the perfect solution?

    Regards,

    T o n y
  • Ahle2Ahle2 Posts: 1,178
    edited 2010-03-02 14:29
    @TonyWaite
    Have you implemented the filter into your project then?

    @Phil Pilgrim
    I love unusual solutions like the one you have presented here [noparse]:)[/noparse]
    Didn't you use the video generator to output 8 PWM signals at once?

    /Johannes
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-03-02 14:43
    Very interesting: using motor drivers to implement communication devices.
    I, too, have used chips in off-labels ways. I recently turned a lone MOSFET into a communication device, albeit an ancient one. With very little extra wiring it was able to transmit smoke signals that could be read throughout the entire building.
  • kwinnkwinn Posts: 8,697
    edited 2010-03-02 15:03
    @ElectricAye Smoke signals plural or smoke signal one puff?
  • TonyWaiteTonyWaite Posts: 219
    edited 2010-03-02 15:30
    @Johannes

    I *tried* to insert your "setCutoff" PASM into Phil' s ":strand" PASM of his pink-noise code
    (http://forums.parallax.com/forums/default.aspx?f=25&m=417910);

    However, I confess that I lacked the mathematical insight to do this successfully!

    T o n y
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-03-02 15:33
    kwinn said...
    @ElectricAye Smoke signals plural or smoke signal one puff?

    One puff, I suppose, but that single puff was modulated by my gasping exasperation.
Sign In or Register to comment.