Searching \ for '[PIC]: ADC and sound sampling' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=sound
Search entire site for: 'ADC and sound sampling'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: ADC and sound sampling'
2002\09\19@010101 by Dale Botkin

flavicon
face
Trying to hash out a quick way to test whether a $4K widget will help one
of my kids out or not.

Correct me if I'm wrong, but it looks to me like the most audio horsepower
I could count on from a 20MHz PIC would be ADC sampling at around 33kHz:

Assume fairly low (50 Ohm) input impedance
Tacq ~ 11uS
Tad = 19.2uS
Tsample ~ 30.2uS

or around 33kHz sample rate, give or take a bit, which would be quite
adequate for normal speech, would it not?  Telephone quality is 56Kbit/sec
or 8K samples/sec., so even if I tried for 10-20K samples per second I'd
be getting relatively good quality sound, right?  Or did I miss anything?

The idea is to use the ADC to sample incoming sound and Roman's 1-bit
sound for output, with a delay in between.  I've never used the ADC at
more than a few hundred samples per second, is there quicksand to watch
out for?

Dale
---
We are Dyslexia of Borg.
Fusistance is retile.
Your ass will be laminated.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\19@080818 by Olin Lathrop

face picon face
> Correct me if I'm wrong, but it looks to me like the most audio horsepower
> I could count on from a 20MHz PIC would be ADC sampling at around 33kHz:
>
> Assume fairly low (50 Ohm) input impedance
> Tacq ~ 11uS
> Tad = 19.2uS
> Tsample ~ 30.2uS
>
> or around 33kHz sample rate, give or take a bit, which would be quite
> adequate for normal speech, would it not?  Telephone quality is 56Kbit/sec
> or 8K samples/sec., so even if I tried for 10-20K samples per second I'd
> be getting relatively good quality sound, right?  Or did I miss anything?

I didn't check the exact timing numbers, but the concept seems correct.

One thing to watch out for is aliasing.  In theory you only need to sample
at twice the frequency of the highest signal of interest.  8K samples/sec
for voice is adequate.  However, sampling that close to the limit requires a
very sharp anti-aliasing filter.  This is nearly impossible to do in analog
hardware.  The usual method is to oversample by 16x or so in a DSP, then
apply a sharp anti-aliasing filter on that stream before decimating to the
final output stream.

You don't have the cycles to do that in a PIC.  Do the best you can in
analog hardware to reduce frequencies beyond 4KHz, then sample at 32KHz.  If
you get clever, you can probably cook up a poor man's anti-aliasing filter
that looks at the nearest 8 samples to produce one output sample.  Just
averaging will be better than nothing, but a box filter doesn't make best
use of the available information.

What do you want to do with this audio stream.  Are you just trying to delay
it?  Why do you want to convert it to a 1 bit stream?  There may be easier
approaches if you look at the bigger picture.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\19@090106 by Dale Botkin

flavicon
face
On Thu, 19 Sep 2002, Olin Lathrop wrote:

> What do you want to do with this audio stream.  Are you just trying to delay
> it?  Why do you want to convert it to a 1 bit stream?  There may be easier
> approaches if you look at the bigger picture.

I planned to convert to a 1-bit stream to reduce the amount of RAM needed
to store the audio.  All I need to do is introduce a variable delay
ranging from nothing to maybe 200ms.  If I'm storing 8-bit samples, that's
a lot of RAM, and I don't think I can sample AND store and fetch from
serial EEPROM AND do everything else with a PIC and still get a reasonable
sample rate.

Dale

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\19@103616 by Olin Lathrop

face picon face
> I planned to convert to a 1-bit stream to reduce the amount of RAM needed
> to store the audio.  All I need to do is introduce a variable delay
> ranging from nothing to maybe 200ms.  If I'm storing 8-bit samples, that's
> a lot of RAM, and I don't think I can sample AND store and fetch from
> serial EEPROM AND do everything else with a PIC and still get a reasonable
> sample rate.

200mS at 8KHz is 1600 samples.  An 18F252 has 1536 bytes which is almost
enough, but an external memory would still be better.  You don't want to use
EEPROM for the external memory.  The easiest would be an 8 bit parallel RAM.

With an external 4Kbyte 8 bit parallel static RAM, you should be able to
sample at 16KHz, store the samples in a circular buffer in the RAM, read
them back out and write them to the PWM hardware.  That leaves 312
instructions per sample, which is plenty.  It would be even easier to use an
8Kbyte RAM and sample at 32KHz.  That way you can just forget software
anti-aliasing and reconstruction, have up to 250mS delay, and have 156
instructions per sample, which is still plenty.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\19@110742 by Dale Botkin

flavicon
face
On Thu, 19 Sep 2002, Olin Lathrop wrote:

> 200mS at 8KHz is 1600 samples.  An 18F252 has 1536 bytes which is almost
> enough, but an external memory would still be better.  You don't want to use
> EEPROM for the external memory.  The easiest would be an 8 bit parallel RAM.

Thanks for your input, I appreciate the responses.

Actually, the easiest seemed to me to be reducing the sample size to 1 bit
and only needing 200 bytes at 8kHz.  The 16F876, which is the target
device, has enough internal RAM to do this.  I figure I probably won't
need delays as high as 200ms, so may be able to increase the sample rate
to 16 or 20kHz and still be able to use internal RAM.

I've got no interest in the 18F family at this point for several reasons,
none of which are particularly germane to this discussion.  I suppose I
could use an external parallel RAM to store tons of samples, which would
be really nice, but I'm trying to keep the physical size to a minimum.  I
may need to just bite the bullet & wire up one of the old static RAM chips
I have laying around, sample as fast as is convenient and use the PWM as
you suggested.  Sure would make life easier, the tradeoff being a little
larger device.  I'll probably try it both ways.

Dale

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\19@115338 by Roman Black

flavicon
face
Dale Botkin wrote:

> Correct me if I'm wrong, but it looks to me like the most audio horsepower
> I could count on from a 20MHz PIC would be ADC sampling at around 33kHz:

33kHz 8 bit sampling sounds reasonable, amd with
a slowly changing analog signal (like audio) you
can go even faster as the PIC ADC internal capacitor
does not need to change that much per sample.

> around 33kHz sample rate, give or take a bit, which would be quite
> adequate for normal speech, would it not?  Telephone quality is 56Kbit/sec
> or 8K samples/sec., so even if I tried for 10-20K samples per second I'd
> be getting relatively good quality sound, right?  Or did I miss anything?
>
> The idea is to use the ADC to sample incoming sound and Roman's 1-bit
> sound for output, with a delay in between.


Well recorded 8bit speech will be excellent even at
low bitrates like 8kHz. Playback using 1bit sound like
my BTc 1bit or 1.5bit system will need slightly higher
bitrates. 19.5kHz is 256 insts with a 20MHz PIC clock,
so you only have to encode or decode one sound sample per
256 PIC instructions. 19.5kHz playback sounds quite
ok with speech. Full analog recording, and instant
compression to 1bit sound are easily possible on a 20mHz
PIC.

The 1bit playback does contain some sampling noise,
but this is reduced a lot at higher sample rates.
Your suggestion of 33kHz will give good speech playback,
but only gives 151 instructions to get the 8bit ADC
sample, do the BTc encoding, and send that one bit
to the eeprom. It does seem do-able. :o)

At 33kHz the bulk of the aliasing noise will be at
16.5kHz and 11kHz, these are high enough to enable use
of some harsh low-pass playback filtering and give good
speech recording and playback.

My choice would be to go with the 256 insts/sample
rate of 19.5kHz, and then try making it work at that
"sensible" bitrate. :o)

I haven't done any PIC encoding using the BTc system
but the algorithm is quite simple and I can send you
the C source for the BTc encoding as used in the
dos and windows versions. Looking at my C-- source
code I have a feeling you can do it in, say,
12 PIC instructions! ;o)

The new Windows version of my BTc sound encoder is also
finished (and now gives playback of the BTc encoded
sound on the PC soundcard!) I've been (slowly) working
on the help file in between other recent projects.
:o)
-Roman

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\19@125108 by Mike Mansheim

flavicon
face
Dale Botkin wrote:
> Assume fairly low (50 Ohm) input impedance
> Tacq ~ 11uS
> Tad = 19.2uS
> Tsample ~ 30.2uS

> or around 33kHz sample rate, give or take a bit,...

If you only need to sample one channel (don't know if that applies or
not), I've always assumed you can sample faster, but have never had to
test it with a high sample rate.
Can someone tell me if this is correct?  It's not clear to me from the
data sheet.  I assume Tacq is required for changing input channels.  If
you are not changing input channels, then I assume you only need to wait
the extra 2 Tad before starting the next conversion (Tad = 1.6us in the
data sheet; 12 Tad = 19.2us are required for a conversion).  I base this
assumption on the statement the charge holding capacitor is not
disconnected during the conversion.  In this case then, the total time
would be 14 Tad = 22.4us, or 44KHz.

Some other interesting possibilities for fast a/d sampling (only in the
future at this point) are a couple of motor control versions from
Microchip:
18F4431:  200K samples/second, with 2 S&H buffers, so 2 channels could be
         sampled simultaneously.
dsPic whatever:  500K samples/second, with 4 S&H buffers.

I heard the 18F4431 mentioned in passing at the masters, and looked it up
then on Microchip's website to get the info I've posted here.  I can't
find that info on the website now, so I'm posting it from notes I made
back then.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\19@143841 by Olin Lathrop

face picon face
> I assume Tacq is required for changing input channels.  If
> you are not changing input channels, then I assume you only need to wait
> the extra 2 Tad before starting the next conversion

No.  The acquisition time is required to allow the charge hold capacitor to
charge to whatever the new voltage level is.  When a conversion starts, the
capacitor is disconnected from the input so that whatever voltage is on it
will remain constant during the conversion.

In theory you could reduce the acquisition time if you knew the maximum
possible difference from the last sample was less than full scale.  This
could be the case, for example, if the input signal was frequency limited to
less than 1/2 the sample rate.  However, unless you are really desparate for
a slightly higher sample rate I wouldn't play such games.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\19@155220 by Jinx

face picon face
> I've got no interest in the 18F family at this point for several
> reasons, none of which are particularly germane to this
> discussion.  I suppose I could use an external parallel RAM to
> store tons of samples, which would be really nice, but I'm
> trying to keep the physical size to a minimum

You should be able to quite easily find an old HDD logic board
with at least one 32kB SMT SRAM on it. One of those would
fit into the footprint of an F877. Either that or an S-DIP cache
from a motherboard

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\19@162346 by Peter L. Peres

picon face
On Fri, 20 Sep 2002, Roman Black wrote:

*>Dale Botkin wrote:
*>
*>> Correct me if I'm wrong, but it looks to me like the most audio horsepower
*>> I could count on from a 20MHz PIC would be ADC sampling at around 33kHz:
*>
*>33kHz 8 bit sampling sounds reasonable, amd with
*>a slowly changing analog signal (like audio) you
*>can go even faster as the PIC ADC internal capacitor
*>does not need to change that much per sample.

On the contrary, it needs to charge fully for each and every sample. It is
not a smoothing capacitor, it's a part of the (presumably) C/2C A/D
converter.

Peter

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\19@164644 by Dale Botkin

flavicon
face
On Fri, 20 Sep 2002, Jinx wrote:

> You should be able to quite easily find an old HDD logic board
> with at least one 32kB SMT SRAM on it. One of those would
> fit into the footprint of an F877. Either that or an S-DIP cache
> from a motherboard

Strictly thru-hole for this one.  On reflection, the extra chip won't be a
big deal, if it's small enough to be portable it's OK.  I've got a pile of
old 8K and 32K SRAMs around, I may end up using one.  Wow, it's been a
while since I had to resort to that!  8-)  Last time was for an 8051
project.

Dale

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\19@170225 by Dale Botkin

flavicon
face
On Thu, 19 Sep 2002, Peter L. Peres wrote:

> On Fri, 20 Sep 2002, Roman Black wrote:
> *>33kHz 8 bit sampling sounds reasonable, amd with
> *>a slowly changing analog signal (like audio) you
> *>can go even faster as the PIC ADC internal capacitor
> *>does not need to change that much per sample.
>
> On the contrary, it needs to charge fully for each and every sample. It is
> not a smoothing capacitor, it's a part of the (presumably) C/2C A/D
> converter.

No, actually I did read that in the midrange manual.  Tacq can be
shortened quite a bit if, as Roman said, the input doesn't change much
between samples - 1/2LSB for full resolution, I think.  I'm not in THAT
much of a hurry.

Dale

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\09\19@183157 by Jinx

face picon face
> Strictly thru-hole for this one.

You wouldn't have to lay down PCB tracks. Use eg component
lead offcuts (you do save them don't you ?) between the memory
and the PIC pins on the solder side of the board. Cache RAM is
commonly a 28 pin 0.3" IC, which would fit underneath the F877
if you use a socket. It could also go on the solder side, which is
handy if you want to retro-fit to a board

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...