Sound!

A "new fashioned" televisor, using an Arduino to drive the motor and display.

Moderators: Steve Anderson, Dave Moll, Andrew Davie

Sound!

Postby Andrew Davie » Mon Apr 17, 2017 12:12 am

I hacked in some code to the interrupt that services the video and had a go at getting the sound working. I wired up a speaker and hooked it into the Arduino pin I expected the sound to be coming from. Spun up the disc and -- worked the very first time! It's not amplified, but it is working. Really quite happy - although this video has overpowering noise from the televisor motor, if you watch about 20s in you will be able to hear sound from the speaker. I'm pleased on a couple of fronts - firstly, my 8-bit sound seems reasonably OK for the purposes I want. Secondly, there was enough processing time available in the interrupt (I rewrote it yesterday with efficiency in mind) to handle the sound AND the video. Next step, I suppose, is to amplify it - I was thinking of using the IRL540 in a similar way to the motor circuit and power the speaker from 12V (it's 5V directly off the Arduino right now).


youtu.be/B1UaN4eRqcQ

Another step forward!
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1508
Joined: Wed Jan 24, 2007 4:42 pm
Location: Hobart, Tasmania, Australia

Re: Sound!

Postby Andrew Davie » Mon Apr 17, 2017 10:40 pm

I don't know if I'm over-thinking this, but the more I get into sound amplification the more difficult it seems to be.

My first thoughts were to just use an IRL540 as a single-transistor amplifier. Seemed to work fine for the motor, right? First a bit of background - the sound is played from an 8-bit source (the right channel of the WAV file data). At 19200Hz, each byte (0-255) sets the duty cycle of a PWM signal output on pin 6 of the Arduino. The PWM is running at 187.5 kHz. I think. It's complicated. Anyway, a high frequency. The square wave PWM is cycling from 0V to 5V.

So for my first test I hooked up the speaker to this PWM pin and GND. That gives me functional sound, but I only did that for short tests. The sound is quite low, and I understand this can damage my Arduino. No idea why, I don't really understand anything about the dynamics of speakers yet. But, forging on...

So as I said my first thoughts were to use a single transistor circuit, like this...

Image

but the more I got into reading, the less this sort of approach seemed to be recommended. There are lots of variations and advice out there, and I'm quite confused. Here's a selection...

Image

Image

Image


... and more. Essentially as I am currently understanding things, I don't want an external volume control - because I get this in software already by pre-adjusting the duty cycle (multiply by volume setting on the LCD panel slider). All I want is amplification. The Arduino PWM pin can supply a maximum of 20 mA. The Arduino 5V pin would be my preferred power source for the speaker, but also a possibility is the 13 VDC which supplies the motor. The latter could handle higher current, but I think I can get up to 500 mA from the Arduino 5V pin.

My criteria - I don't particularly care about high-quality sound. I am, after all, sourcing from an 8-bit data stream. However, I would prefer not to have much added noise or hiss as a result of the amplification I'm using.

Another line of attack seems to be an external amp circuit, such as these...

Image
SparkFun Mono Audio Amp Breakout - TPA2005D1

What I'm not sure about here is the input - can I feed these a high frequency PWM signal and expect them to work?

All as clear as mud right now!
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1508
Joined: Wed Jan 24, 2007 4:42 pm
Location: Hobart, Tasmania, Australia

Re: Sound!

Postby Steve Anderson » Tue Apr 18, 2017 5:21 pm

You could use any small amplifier but ideally you should filter off the PWM component so the amp and loudspeaker don't have to handle it. A simple RC filter of say 1k in series with the PWM signal, then a 10nF cap to ground will do that. Feed the signal from the junction of the R and C into the amp. This will suppress your 187.5kHz PWM component by about 60db. (1000).

Steve A.
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 3800
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: Sound!

Postby Andrew Davie » Tue Apr 18, 2017 9:35 pm

Steve Anderson wrote:You could use any small amplifier but ideally you should filter off the PWM component so the amp and loudspeaker don't have to handle it. A simple RC filter of say 1k in series with the PWM signal, then a 10nF cap to ground will do that. Feed the signal from the junction of the R and C into the amp. This will suppress your 187.5kHz PWM component by about 60db. (1000).

Steve A.


Thanks Steve. I read a bit about RC filters today. Since you said "ideally", but not "mandatorially" and since I had a Jaycar "The Champ" kit amplifier lying around, I thought I'd just the amplifier first... to see how it sounded. At first it was incredibly... awful... but I must have had a dry solder joint or... SOMETHING... because after fiddling with it a bit the sound "came good" and although there appears to be a lot of low-level noise when I turn down the volume (via my LCD touch-panel), I'm not entirely sure what the cause of that is. Maybe the 187.5kHz PWM is influencing. I've done a small sample recording of the sound from the speaker - with my phone - and then processed in Audacity to make just a fraction louder to make the quality more apparent. It's not great - it's not terrible. Certainly not as loud as I had hoped. Maybe good enough to go with for now. By the way, I had my incredibly loud motor/disc disconnected for this recording.

scamp.wav
(4.51 MiB) Downloaded 95 times
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1508
Joined: Wed Jan 24, 2007 4:42 pm
Location: Hobart, Tasmania, Australia

Re: Sound!

Postby Steve Anderson » Tue Apr 18, 2017 10:00 pm

Well, the expression 'ideally' was to infer that the loudspeaker is inductive - a coil within a magnetic field. At 180kHz (or whatever) it's not going to pass much current, current in a loudspeaker = volume. It is a way of averaging things out, but it's not that efficient. Average out the PWM with a simple RC filter in this case and you should have bags of noise.

For LEDs driven with PWM our eyes do the averaging as the LEDs respond quickly to the PWM, loudspeakers do not, they're mechanical.

Steve A.
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 3800
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: Sound!

Postby Andrew Davie » Tue Apr 18, 2017 10:25 pm

Steve Anderson wrote:Well, the expression 'ideally' was to infer that the loudspeaker is inductive - a coil within a magnetic field. At 180kHz (or whatever) it's not going to pass much current, current in a loudspeaker = volume. It is a way of averaging things out, but it's not that efficient. Average out the PWM with a simple RC filter in this case and you should have bags of noise.

For LEDs driven with PWM our eyes do the averaging as the LEDs respond quickly to the PWM, loudspeakers do not, they're mechanical.

Steve A.


Got it! Wilco.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1508
Joined: Wed Jan 24, 2007 4:42 pm
Location: Hobart, Tasmania, Australia

Re: Sound!

Postby Andrew Davie » Wed Apr 19, 2017 12:03 am

Something's wrong! I thought I understood the suggestion, but here's the non-working result...

rcfilter.jpg
rcfilter.jpg (207.99 KiB) Viewed 4440 times


Signal from Arduino comes in from the bottom left wire, connects to a 1K resistor which then has a 10nF capacitor crossing to ground. From the join of the resistor/capacitor, I take the signal direct to the amp signal-in. Meanwhile, the other leg of the capacitor connects to ground - one wire going to Arduino ground and the other to the amp ground.

If I move the wire from "A" to "B" (C6 to I6) I have my original wiring configuration and I hear the sound. With it as shown in the picture I hear nothing.
Can you see any mistakes?
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1508
Joined: Wed Jan 24, 2007 4:42 pm
Location: Hobart, Tasmania, Australia

Re: Sound!

Postby Steve Anderson » Wed Apr 19, 2017 3:26 pm

Sorry Andrew I have no idea why this isn't working. What audio amp are you using?

Steve A.
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 3800
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: Sound!

Postby Andrew Davie » Wed Apr 19, 2017 9:15 pm

Steve Anderson wrote:Sorry Andrew I have no idea why this isn't working. What audio amp are you using?

Steve A.


I'm using the "The Champ" from Jaycar Electronics, linked earlier.

I did a little experiment changing the resistor. With no resistor, of course - sounds fine but not terribly loud. With an 18 ohm resistor it sounds pretty bad, but still legible (just) kind of stuttering and "overloaded" with 220 ohm it sounds illegible and awful and of course with 1K no sound at all.

I've purchased some cheap amps from AliExpress just to have a play with. Because... well, basically because they're cheap and ... new toy.
Will be quite some time before they arrive, but here they are anyway...

Low-Power-TDA8932-35W-Digital-Amplifier-Board-Module-Mono-Power
5 pieces - 2130-Mono-2-5W-Class-D-Audio-Amplifier-PAM8302-module-Mono-2-5W-Class
TPA3118-PBTL-mono-digital-amplifier-board-1X60W-12V-24V-POWER-AMP
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1508
Joined: Wed Jan 24, 2007 4:42 pm
Location: Hobart, Tasmania, Australia

Re: Sound!

Postby Klaas Robers » Thu Apr 20, 2017 2:05 am

Andrew, I would definetely use an analogue potentiometer for volume control and let the Arduino output a PWM signal as loud as possible. Then you use the full 8 bits range and you get a certain signal to noise ratio.

If you are going to make a lower volume in a digital way, the sound will be less loud, but the noise will have the same amplitude. Then you go from 8 bits quantisation to 7 bits, 6 bits, 5 bits. With an analogue volume control the quantisation will remain 8 bits and sound and noise will decrease in the same ratio. Don't let it get worse than it is already.
User avatar
Klaas Robers
Frankenstein was my uncle.
 
Posts: 1431
Joined: Wed Jan 24, 2007 8:42 pm
Location: Valkenswaard, the Netherlands

Re: Sound!

Postby Andrew Davie » Thu Apr 20, 2017 3:03 am

Klaas Robers wrote:Andrew, I would definetely use an analogue potentiometer for volume control and let the Arduino output a PWM signal as loud as possible. Then you use the full 8 bits range and you get a certain signal to noise ratio.

If you are going to make a lower volume in a digital way, the sound will be less loud, but the noise will have the same amplitude. Then you go from 8 bits quantisation to 7 bits, 6 bits, 5 bits. With an analogue volume control the quantisation will remain 8 bits and sound and noise will decrease in the same ratio. Don't let it get worse than it is already.


Just when I thought I had things under control! OK, well #1 I am NOT going to use an analog potentiometer - it spoils the whole ethos of my LCD/touch panel display. But what might work is to use a digital potentiometer, and use your suggestion of "full loudness" PWM, and then the digital pot controlled via the LCD volume value. A shame, as it becomes much more complex :( On the other hand, I could just have a pre-set volume on the televisor and that's it - no adjustment. The amplifier circuit(s) I am/will be using all have a variable pot to adjust volume. They will be hidden internally but it would let me find a reasonable value and still have the PWM full-tilt. But again, I'm NOT using any sort of knobs or dials on this thing - an analog potentiometer is not going to happen. But I understand the problem, well not really understand, but accept, and thanks for pointing it out.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1508
Joined: Wed Jan 24, 2007 4:42 pm
Location: Hobart, Tasmania, Australia

Re: Sound!

Postby Steve Anderson » Thu Apr 20, 2017 2:48 pm

The only thing I can think of is the amp you're using is class D. Being on-off switching, a form of PWM, the two are interacting. The amp is expecting an analogue source not PWM - hence my suggested filter. What you probably need is a good old analogue amplifier. That's all I can come up with at the moment.

Steve A.
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 3800
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: Sound!

Postby Andrew Davie » Mon May 22, 2017 11:20 pm

OK, back to sound and I'm going to have to start from square 1 because I don't understand what's happening.

Today my replacement amplifier arrived. I have a TPA3118 60W Mono Digital Audio Power Amplifier Board and it seemed pretty straightforward to hook up. One pair for power (I'm supplying with about 12.5VDC), another for the input (I'm going to GND on the arduino for - and to pin 6 for +). See my architecture/wiring layout here. Finally there's the +/- to speaker. All hooked up and (honestly!) hanging onto the wires this time to disconnect if they feel warm, or if I smell something.

I get sound from the (small) speaker I'm using - must be about 10 cm diameter. But I'm not sure what it is. I try the volume slider and sound is all distorted and cracking/breaking. I smell something burning - instantly disconnect. All wires OK, nothing heated. Amp board is still showing an ON light when I test it, so I think that's OK. But next time I connect and try with lower volume - nothing. So something's dead, and judging by the smell I'd be guessing it's the speaker.

Right, that's where I'm at. Clearly I'm doing something very wrong at the moment. I am wondering if I just put too much juice to the speaker this time and basically just fried it. The amp claims 60W in some specs, and the volume was, well... high. I wanted to make it sound good but yeah, I did slide it right up so there's that.

SO I think the first step is to get another speaker and try with the volume set to 0, and ever so slowly increase it, see if I hear anything.

Aside from that, I guess I could also try the RC filter but that failed me dismally last time and I don't know what I was doing wrong.
Failing that, I'll be jotting down notes as/if/when I find them regarding use of speakers on the Arduino.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1508
Joined: Wed Jan 24, 2007 4:42 pm
Location: Hobart, Tasmania, Australia

Re: Sound!

Postby Klaas Robers » Mon May 22, 2017 11:43 pm

Andrew, a loudspeaker needs a baffle to give some sound. A baffle is a stiff board of wood or whatever, about 1...2 cm thick, with a hole in the center, where you fix the loudspeaker in a way that the distance through the air from the front to the back is as long as possible. Make the baffle at least 50 x 50 cm, but the larger the better. You can place it in a corner of the room, or even better, hang it against the ceiling in a corner of the room. That is what I had in my students time.

A different solution is to place the speaker in the wall of a closed box, at least 30 x 30 x 30 cm. See that the walls are stiff and not resonating. The box / baffle can be part of the enclosure of your Telvisor.

If the speaker is not mounted in a baffle / box, it will give no low and no mid tones, only some highs. The lows and the mids will though produce heat in the LS-coil. Somtime it helps a little bit to place it at the edge of the table, with a small sector over that edge, but tha is not a permanent solution.

And then: place a low pass fiter between the PWM output and tthe input of the amplifier. It might be that the amplifier dislikes to be fed directly with PWM signals and/or the speaker doesn't like them. Then you can kill a speaker or amplifier without that you hear any sound.
User avatar
Klaas Robers
Frankenstein was my uncle.
 
Posts: 1431
Joined: Wed Jan 24, 2007 8:42 pm
Location: Valkenswaard, the Netherlands

Re: Sound!

Postby Dave Moll » Wed May 24, 2017 4:43 pm

Andrew Davie wrote:I am wondering if I just put too much juice to the speaker this time and basically just fried it.


Is the speaker reading open circuit? That would certainly confirm that it's toast.
User avatar
Dave Moll
Just nod and pretend you understand me
 
Posts: 376
Joined: Tue Feb 27, 2007 9:11 am

Next

Return to Andrew Davie's Arduino Televisor

Who is online

Users browsing this forum: No registered users and 1 guest