Sound!

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

Moderators: Steve Anderson, Dave Moll, Andrew Davie

Re: Sound!

Postby Steve Anderson » Wed May 24, 2017 7:28 pm

Yep, check if the speaker is open circuit (after disconnecting it from the amp). It should read a few ohms, around 60% of it's rated impedance, say 5-6 ohms for a nominal 8 ohm speaker.

If it is open circuit the lash-up may have made the amp oscillate at an ultrasonic frequency frying the speaker. Why use a 60W amp on such a small speaker? I suggest using a simple analogue amp, not a class D amp, of just a watt or two. Without any filtering on the output of the PWM and that applied to the speaker could have fried it too. Use a filter and a simple analogue amp is all I can suggest, say a LM386 to get you going, a few hundred milliwatts. I've never had a problem with this method.

A few hundred milliwatts is more than yer average laptop shoves into its speakers.

Steve A.

The TPA3118 also has a BTL output arrangement (Bridged Transformer-Less) i.e. the speaker must be connected to the terminals marked 'Output', not connected to ground/0V anywhere. This is how the high output powers at low supply voltages are generated.

As an aside, class D amps generate a lot of HF noise much the same as switched-mode power supplies as they conceptually use the same method. Quite frankly I wouldn't go anywhere near them.
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 3779
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: Sound!

Postby Steve Anderson » Thu May 25, 2017 1:29 pm

Another thought...I'm assuming you're feeding the amp direct from the PWM output either with or without my suggested little filter (I do strongly suggest you use it though). I'm also assuming that the PWM waveform switches between 0V and 5V at the 180kHz frequency. With no sound modulating the PWM the output will be a 50% duty-cycle waveform at 180-odd kHz. This has an average DC component of 2.5V, pro-rata for other supply voltages. If the audio amp has no input coupling capacitor (possible to save component costs) that could upset the amp and cause all sorts of havoc.

The amp is expecting audio AC with no DC offset and no remnants of PWM, get rid of them and you may have a fighting chance.

To be sure place a 1uF non-electrolytic capacitor between the output of my little filter and the input of the amp. Anything around 1uF should be fine, it's not critical.

You may also find that you'll need to attenuate the resulting audio as at full output the voltage will be 5V p-p (or whatever supply is used) around 1.8V RMS. Being a consumer product there's a chance that this will well and truly overdrive the amp. Yes you can turn the volume down but as Klaas pointed out you'll be losing resolution...severely I would guess.

Steve A.

I've downloaded the datasheet for the active device and Texas Instruments recommends an input capacitor of 1uF for this sort of application, whether that's already on the board...who knows? You could use a 100nF (0.1uF) capacitor, there's no way a 10cm speaker will reproduce frequencies much below 200Hz whatever the makers claim.
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 3779
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: Sound!

Postby Andrew Davie » Thu May 25, 2017 7:03 pm

Steve Anderson wrote:Another thought...I'm assuming you're feeding the amp direct from the PWM output either with or without my suggested little filter (I do strongly suggest you use it though). I'm also assuming that the PWM waveform switches between 0V and 5V at the 180kHz frequency. With no sound modulating the PWM the output will be a 50% duty-cycle waveform at 180-odd kHz. This has an average DC component of 2.5V, pro-rata for other supply voltages. If the audio amp has no input coupling capacitor (possible to save component costs) that could upset the amp and cause all sorts of havoc.


This brings up a few interesting issues. But yes, I was feeding direct without your filter - last time I tried this, the filter gave zilch sound on the speaker. But I am now onto a new amplifier (even yet another new one which arrived yesterday). I will fill the details later. But your comment about "no sound" - this brought me to the startling realisation that on the clips with "no sound" there is actually a 0V input (which I guess is reasonable?) but on the videos "with sound" the midpoint 50% PWM is actually "no sound". So, silence on clips with sound has a value of 128 and silence on clips without sound is a value of 0. I think I might standardise this so that there's no such thing as "no sound" - but in fact "no sound" becomes "no deviation from 50%" (i.e., value of 128). But, not an issue I think... just something to keep in mind.

OK, here's the new audio amp board I got yesterday. I did a quick hookup and no sound. I need to go back to basics and confirm I haven't blown the output pin on the Arduino with earlier tests. So I'll put my oscilloscope on the pin soon and have a look-see. I will also put in the RC filter and "do it right". I have no idea about coupling capacitors on this board or the other.

I was asked "why 60W" with regard to my other amp selection. It's just that I have NO IDEA what's loud or what isn't, so I though 40W sounded a lot better than 1W and so I'd go with the highest I could get. I suspect now that's overkill - so this new one PAM8302 is about 1.5W @ 8 ohms and will hope to get that working. It's tiny, too - about the size of a small postage stamp. It's a class D, for whatever that's worth.

Steve Anderson wrote:The amp is expecting audio AC with no DC offset and no remnants of PWM, get rid of them and you may have a fighting chance. To be sure place a 1uF non-electrolytic capacitor between the output of my little filter and the input of the amp. Anything around 1uF should be fine, it's not critical.


So, check the output pin first, then put the RC filter on - connect the amp negative input to GND on the Arduino, then the positive input to the output of the RC filter as discussed before. I thought the filter had a small capacitor on it, but will review when I have things in front of me. Thanks for the advice.

Steve Anderson wrote:You may also find that you'll need to attenuate the resulting audio as at full output the voltage will be 5V p-p (or whatever supply is used) around 1.8V RMS. Being a consumer product there's a chance that this will well and truly overdrive the amp. Yes you can turn the volume down but as Klaas pointed out you'll be losing resolution...severely I would guess.


Mmmh, OK well would this be a resistor on the output pin? The amp itself has a volume pot on it; perhaps this would be useful?

Steve Anderson wrote:I've downloaded the datasheet for the active device and Texas Instruments recommends an input capacitor of 1uF for this sort of application, whether that's already on the board...who knows? You could use a 100nF (0.1uF) capacitor, there's no way a 10cm speaker will reproduce frequencies much below 200Hz whatever the makers claim.


Right, that's for the original amp (which I now have replacement spares for, too). But I'd like to use the smaller 1.5W one now it's in hand. I'll have a play with both. By the way, I checked the original speaker and confirm it's blown - 0 ohms across the leads. I have spares of that, too, now, and the spares read 7.7 ohms. Sound should be so simple, yet it's proving one of the trickiest parts of my learning process, it seems. Oh well, apart from the LEDs, the synching, the motor control, the PWM stuff, the Arduino, the SD card streaming, and all that stuff ;)
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1505
Joined: Wed Jan 24, 2007 4:42 pm
Location: Hobart, Tasmania, Australia

Re: Sound!

Postby Steve Anderson » Thu May 25, 2017 7:10 pm

First off I suggest hooking up the amp and loudspeaker and driving it from a known analogue source, say an iPod or PC output. Once confirmed working then try the Ardin...whatever the thing's called, with filter and cap.

I'm surprised the speaker read zero ohms...try touching a 1.5V battery across the terminals, you should hear a thump or crackle as you do so, this should not fry the speaker. A couple of tries over a second or two will confirm if the speaker is OK or not. Shorts in speakers are rare, they usually go open. Basically the fine wire in the voice-coil acts as a fuse, once blown, that's it.

The replacement amp does look better, at least it has an on-board gain control, set it to minimum initially. Try with iPod/whatever then reset to minimum for the PWM feed.

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

Re: Sound!

Postby Andrew Davie » Thu May 25, 2017 7:23 pm

Steve Anderson wrote:First off I suggest hooking up the amp and loudspeaker and driving it from a known analogue source, say an iPod or PC output. Once confirmed working then try the Ardin...whatever the thing's called, with filter and cap.

I'm surprised the speaker read zero ohms...try touching a 1.5V battery across the terminals, you should hear a thump or crackle as you do so, this should not fry the speaker. A couple of tries over a second or two will confirm if the speaker is OK or not. Shorts in speakers are rare, they usually go open. Basically the fine wire in the voice-coil acts as a fuse, once blown, that's it.

Steve A.


Not at home at the moment. The two identical speakers have different resitances across the terminals. The "blown" one reads 0 ohms. The good ones read 7.7 ohms. I will revisit and report later!
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1505
Joined: Wed Jan 24, 2007 4:42 pm
Location: Hobart, Tasmania, Australia

Re: Sound!

Postby Steve Anderson » Thu May 25, 2017 7:48 pm

7.7 Ohms looks OK for an el-cheapo loudspeaker, so that should be fine. Start off with minimum gains and minimum levels everywhere. If you have a file with just a 1kHz tone on it you could look at the PWM waveform after the filter on a 'scope and confirm it's correct (before hooking up the amp). Even some music or speech should be recognisable - view on scope from iPod/whatever if you have no idea what music or speech should look like. It's generally very 'peaky'.

I suggest also setting the PWM module to produce a 50% output duty-cycle as part of the initialisation process as well as when a file comes to a halt or you stop/pause it. If a file has no sound data the PWM should also continue to output silence at a 50% duty-cycle. For 8-bit audio as you say you're using that's either 0x7F or 0x80.

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

Re: Sound!

Postby Andrew Davie » Thu May 25, 2017 10:49 pm

Starting on getting sound amplification working. I've previously failed several times for various reasons like stupidity and randomly plugging wires into places they don't belong. This time I have a few sacrificial speakers and a new amplifier board to try. I've gone with a "PAM8302" which cost just a couple of bucks and claims 1.5W @ 8 ohms. Previously I'd tried a 60W amp not realising that this was probably complete overkill.

So it was suggested to me that the first thing to try was just a CD player or computer. Well, I realised I still had an old "Doctor Who" NBTV format file on the CD that I used to use for NBTV signal source, so I hooked that up again, and tried to film with one hand while holding the positive/negative leads onto the output from the CD player. It's a bit crackly as the connection quality varies based on finger shake, but seems OK. I was also powering the amplifier itself from the Arduino, and running the Nipkow disc and Nextion LCD display at the same time, so I had a fair test of power usage with everything configured. All that's different in this test is that the sound is NOT coming from the PWM pin on the Arduino, but instead direct from the headphone out (not line out) on the CD player. I cranked up the volume on the CD player to MAX.

I wanted to see if amplifier was working, of course, and if the speaker was "loud enough" compared to the racket from the motor as it's stuttering and doing it's thing to keep the disk in synch. Well, it is. Just. But I expect the motor to be a lot quieter when I bury it out the back and in an enclosure. I also will be trying a few different motors and perhaps a higher speed too, just to try and optimise that side of things.

So, the upshot of all this - I confirm that the tiny 1.5W amp is sufficient for my needs, that it works, that the "power budget" on the Arduino seems to be sufficient.

So now I can move on to the somewhat tricky problem of using the PWM output from the Arduino to drive the speaker. I'm going to be using a RC filter to convert the PWM to analog, and hopefully all will work as heard here.



youtu.be/u3Ij-u5Ykq4
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1505
Joined: Wed Jan 24, 2007 4:42 pm
Location: Hobart, Tasmania, Australia

Re: Sound!

Postby Andrew Davie » Thu May 25, 2017 10:59 pm

Steve Anderson wrote:7.7 Ohms looks OK for an el-cheapo loudspeaker, so that should be fine. Start off with minimum gains and minimum levels everywhere. If you have a file with just a 1kHz tone on it you could look at the PWM waveform after the filter on a 'scope and confirm it's correct (before hooking up the amp). Even some music or speech should be recognisable - view on scope from iPod/whatever if you have no idea what music or speech should look like. It's generally very 'peaky'.


I have Audacity so I can see the sound easily enough. I think I will make a 19.2KHz sample of a 1kHz tone for testing, and as you say have a look at the PWM waveform (after the filter! yes!) of that. That will confirm for me the filter is working as expected, too, and I can see the voltage value centered around 2.5V, so to speak, with a maximum of 5.

Now I know the amp is working OK, as soon as I see the above, I should just be able to plug it in.

Steve Anderson wrote:I suggest also setting the PWM module to produce a 50% output duty-cycle as part of the initialisation process as well as when a file comes to a halt or you stop/pause it. If a file has no sound data the PWM should also continue to output silence at a 50% duty-cycle. For 8-bit audio as you say you're using that's either 0x7F or 0x80.


I'll make sure that all files DO have sound data - that is, 128 which I will hereby define as my format's official "0" offset. The range will therefore be 0 (=-128) to 255 (=+127). Thanks for the assistance/advice!

Now it's on to that RC-filter, tested using a 1kHz sine wave output on the Arduino pin as a PWM. I hope I haven't fried the Arduino pin already, but I do have one spare Arduino at the moment, and 8 more on the way! I spotted a bargain, couldn't resist.


Actually someone at work suggested to me that a working televisor would be a great interactive museum display so I hope to make a few and see if the local museum wants one. We shall see.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1505
Joined: Wed Jan 24, 2007 4:42 pm
Location: Hobart, Tasmania, Australia

Re: Sound!

Postby Andrew Davie » Fri May 26, 2017 1:03 am

Klaas Robers wrote: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.



Thanks for this info - useful to me because a) I didn't know that and b) this will drive my design of the final televisor. I'm going to have to think about how to build a "chamber" of some sort for the speaker. This doesn't fit well at all with my initial visualisation of how it is going to work :( As to the PWM, your notes are in agreement with Steves - feeding PWM to the amp is not a great idea. I'm going to try to get the RC filter working very soon. I've already killed one amp, one speaker, for sure. Possibly two amps. I've now got half a dozen amps and 4 spare speakers which should give you some idea of how confident I am that I know what I'm doing1 ;)
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1505
Joined: Wed Jan 24, 2007 4:42 pm
Location: Hobart, Tasmania, Australia

Re: Sound!

Postby Andrew Davie » Fri May 26, 2017 2:23 am

I was just thinking of the "journey" some of the sound takes. From a digital source (say, MP4) it's converted into a NBTV8 format (that's my 8-bit NBTV) and placed on a SD card. Then it's retrieved by an interrupt-based timer and used to set the PWM duty cycle. From there, the Arduino drives an output pin based on the duty cycle, switching bewteen 0V and 5V at something like 187kHz. Then it's going to go through a RC filter to convert it from digital to analog. From the RC filter it's going into the PAM8302 amplifier which is a class-D amp - and as far as I'm aware it outputs a PWM signal. Then to the speaker which effectively converts the fast PWM output back into an analog sound by virtue of the mechanical response of the speaker itself. So the sound is effectively going from digital to analog (SD to PWM) to digital (PWM out of amp) to analog (speaker output). Kind of weird :P
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1505
Joined: Wed Jan 24, 2007 4:42 pm
Location: Hobart, Tasmania, Australia

Re: Sound!

Postby Steve Anderson » Fri May 26, 2017 11:48 am

Yes, it's interesting to ponder upon the whole process from a microphone to your loudspeaker at home. It's also interesting when you explain to audiophools who spend vast fortunes on 'special cables', gold connectors and all the other cons that no such stuff is used in recording studios. Tin-plated connectors, plenty of Oxygen in the copper and the errors generated in an audio mixer (digital) by number-rounding. They close their ears - they don't want to know.

A studio, of any type, is built to a price, it has to meet a specification, yes, but it's invariably a minimum. Anyway...

"...Then to the speaker which effectively converts the fast PWM output back into an analog sound...",sort of, but any worthwhile class D amp has a filter on the output which consists of a coil (for low resistance) and a capacitor. It works in much the same way as the little input filter. It also helps reduce radiated interference from the speaker cables if you have cables of 2-3 metres long for a stereo.

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

Re: Sound!

Postby Andrew Davie » Fri May 26, 2017 9:58 pm

Well, a bit of progress.
I made a NBTV8 format video with a 1KHz sine wave (amplitude 5V) for the soundtrack.
I wired up another RC filter on the breadboard, and fed the PWM pin to the resistor, and measured with the oscilloscope on the junction between the capacitor the resistor. The resistor is 1K ohm, the capacitor 10nF. I'm seeing a 1KHz sine wave, albeit with significant noise. I believe I saw noise even without the sound playing, and I also believe it's coming when the motor is spinning. That might be a problem I need to look at.
However, yes - this looks like a (noisy) sine wave that's exactly what I hoped to see. In principle I could feed this into my amp.

1ksine.jpg
1ksine.jpg (292.56 KiB) Viewed 2222 times


RCFilter2.jpg
RCFilter2.jpg (351.52 KiB) Viewed 2222 times


Small steps!
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1505
Joined: Wed Jan 24, 2007 4:42 pm
Location: Hobart, Tasmania, Australia

Re: Sound!

Postby Andrew Davie » Fri May 26, 2017 10:34 pm

Here's the first working completely integrated sound-and-video playing version of my televisor. I followed instructions from Steve and Klaas (thanks!!), took things step by step - and hey there! It's actually quite loud - perhaps a little distorted; difficult for me to tell - I noticed some "noise" in the 1KHz test sine wave I was doing for testing.

But anyway, here it is in all its glory - I'm using a PAM8302 mono 1.5W @8 ohms amp from AliExpress, and a small 10cm speaker I got from Jaycar - both just a few $ each. The Arduino is outputting a 187KHz signal on pin 6 which is the sound represented as PWM. I run a simple RC filter (1K resistor, 10nF capacitor) to convert to analog before feeding into the amp. So lucky to have people who know what they're doing to give me "sound" advice. See what I did there? ;)

Note in the video that the volume control is working just fine, and I've got it quite low for normal use. Of course there's that howl/whine in the background which is the motor. I will try and quieten that down when I start assembling a better mount for everything.


youtu.be/_G8K0zu4v34
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1505
Joined: Wed Jan 24, 2007 4:42 pm
Location: Hobart, Tasmania, Australia

Re: Sound!

Postby Steve Anderson » Sat May 27, 2017 12:55 am

Progress indeed! Yes, the noise on the 1kHz waveform looks lower in frequency that the 180-odd kHz PWM waveform. Try running it without the motor connected...if the software doesn't get upset and see what you get. It is a very simple filter, usually I would suggest something somewhat better, but this was more of a 'get-you-going' exercise.

The problem could well be earth/ground loops which can be a devil to eliminate. Try some heavier gauge cable/wire in the grounds and ensure all power supplies are well decoupled/bypassed near active devices. Also minimise earth/ground cable lengths with the heavier gauge wire. Then see what, if any, improvement results.

Steve A.

Now that I've actually watched the video and seen the lash-up the noise does NOT surprise me at all! Tidy it up, make it compact and get rid of all those long trailing wires, the breadboard and bolt things to ground where need be with nice fat cable.

As Klaas mentioned even the simplest of baffle-boards for the loudspeaker will improve the sound no end, it will also be louder - and in this case so will the unwanted noise. Get rid of it.
User avatar
Steve Anderson
"Fester! Don't do that to 'Thing'"
 
Posts: 3779
Joined: Fri Mar 30, 2007 10:54 pm
Location: Bangkok, Thailand

Re: Sound!

Postby Andrew Davie » Sat May 27, 2017 1:07 am

Steve Anderson wrote:Now that I've actually watched the video and seen the lash-up the noise does NOT surprise me at all! Tidy it up, make it compact and get rid of all those long trailing wires, the breadboard and bolt things to ground where need be with nice fat cable.


Will do! But it's already way exceeded my expectations so even if not improving much I will still be very happy. I was thinking about Klaas's comments about the sound, and noise therein with the amplification, etc... and I thought you know, all I want is something recognisable. This isn't a CD, it's not an audio system. We're not listening to music. There's a hellish loud spinning electric motor/disk right next to the speaker. It's functional, legible, loud enough - it's pretty much "adequate" for purpose.

So, now I'm starting on the tidy-up, hopefully we will see a bit of improvement in the signal, but ultimately... it's probably good enough if it doesn't improve.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1505
Joined: Wed Jan 24, 2007 4:42 pm
Location: Hobart, Tasmania, Australia

PreviousNext

Return to Andrew Davie's Arduino Televisor

Who is online

Users browsing this forum: No registered users and 1 guest