AVR soundcard

16 views
Skip to first unread message

StefanRichter

unread,
Oct 6, 2007, 6:47:24 AM10/6/07
to Low Cost ATA
Some time ago I independently had the idea to do a SIP phone using
AVRs although just for fun without a higher purpose. I uploaded the
current source and some audio samples.

My approach is straight but pretty stupid: There is a PWM which will
overflow at 8kHz and cause an interrupt. In its handler, data is read
from the ADC, a new conversion is triggered, output is written to the
PWM and the input converted to A-law.

The output chain is the worst part. It has a 6th order analog filter,
but the 8kHz noise is just to powerful. I'm also in trouble with
clipping amplifier and there should be some better DC offset as the
opamps just have a single 5V supply.

The input chain is much better. It a single transistor amp and the ADC
is DC coupled to its collector again to have an DC offset (ADC is
ground to Vref). The gain is not high enough for the mic, but a second
stage might do it. The analog output sound equal as the input.

I cheated for the test. I directly connected my PC because of gain
problem. The original is http://www.archive.org/download/china_chinese_librivox/China_and_the_Chinese_01_Giles.mp3
(well, first free speech I found on my machine). There is some noise
in the input, probably because input is just filled with zeros to give
13 bits and there is crosstalk of output. The output is the input
played back and has nasty (sub-)harmonics at 4kHz and 16kHz and of
course the 8kHz PWM clock.

Since it's done on plugin board there is room for analog improvement,
but the digital stuff really needs some knowledge and not my brain
dead approach.

StefanRichter

unread,
Oct 10, 2007, 11:05:15 AM10/10/07
to Low Cost ATA
Meanwhile I did changed the Alaw converter. It now uses the ADC bits
as LSB bits and not as MSB bits of the audio input which seems to be
much better.

DavidRowe

unread,
Nov 12, 2007, 10:07:40 PM11/12/07
to Low Cost ATA
Hi Stefan,

I think you have made an excellent start, and thanks for uploading the
code. This will help me get started with the RS232 side.

So far I have working:

1/ Regulated -48V on-hook supply.

2/ Off hook detection, this is based on sensing loop current with the
A/D, similar to Stefan's approach.

3/ Unregulated off hook current supply. I messed around with closed
loop off hook current regulation but I haven't got the patience to
derive a proper control system (loop gains, filtering etc). However
while experimenting I discovered that a simple fixed PWM value feeding
the DC-DC converter works really well, as phones work fine over a
range of currents, and the phone has its own Voffhook voltage
regulation.

So now I am ready to try some audio I/O, which I think is a key risk
of this project. Some thoughts:

1/ I will try to operate the PWM at the maximum frequency (about 32kHz
on my AVR), this will push the fundamental and harmonics way out in
frequency. We can then oversample the 8kHz alaw signal before PWM
output. Oversampling can be a bit tricky, especially on a low CPU
power device, but we can use tricks like linear or quadratic
interpolation, or maybe an oversampling FIR filter.

2/ I think also a good idea to sample the A/D as fast as possible
(about 15kHz for me), to remove aliasing problems. We can have a
digital LPF to remove some of the aliasing.

One problem - I would really like to get these oversampled signals to
and from the PC at the higher sample rates, but I am not sure if RS232
will be fast enough. It is much easier to prototype the signal
processing on the PC than on the AVR. An alternative I guess is to
program some sort of SPI or 4 bit parallel interface using the PC's
parallel port and up/download samples that way.

> Meanwhile I did changed the Alaw converter. It now uses the ADC bits
> as LSB bits and not as MSB bits of the audio input which seems to be
> much better.

Stefan - have you posted one of these new samples? Which wave file is
it?

Thanks,

David

StefanRichter

unread,
Nov 13, 2007, 7:00:48 AM11/13/07
to Low Cost ATA

On Nov 13, 4:07 am, DavidRowe <da...@rowetel.com> wrote:
> Hi Stefan,
>
> I think you have made an excellent start, and thanks for uploading the
> code. This will help me get started with the RS232 side.
>
> So far I have working:
>
> 1/ Regulated -48V on-hook supply.
>
> 2/ Off hook detection, this is based on sensing loop current with the
> A/D, similar to Stefan's approach.
>
> 3/ Unregulated off hook current supply. I messed around with closed
> loop off hook current regulation but I haven't got the patience to
> derive a proper control system (loop gains, filtering etc). However
> while experimenting I discovered that a simple fixed PWM value feeding
> the DC-DC converter works really well, as phones work fine over a
> range of currents, and the phone has its own Voffhook voltage
> regulation.
>
> So now I am ready to try some audio I/O, which I think is a key risk
> of this project. Some thoughts:
>
> 1/ I will try to operate the PWM at the maximum frequency (about 32kHz
> on my AVR), this will push the fundamental and harmonics way out in
> frequency. We can then oversample the 8kHz alaw signal before PWM
> output. Oversampling can be a bit tricky, especially on a low CPU
> power device, but we can use tricks like linear or quadratic
> interpolation, or maybe an oversampling FIR filter.

Very good thing. My analog filter is taken from Atmel's sound recorder
appnote, but seems to have problems.

>
> 2/ I think also a good idea to sample the A/D as fast as possible
> (about 15kHz for me), to remove aliasing problems. We can have a
> digital LPF to remove some of the aliasing.

If it could be done with an AVR, that is a good idea. I don't have the
skills for this, so I skipped this.

>
> One problem - I would really like to get these oversampled signals to
> and from the PC at the higher sample rates, but I am not sure if RS232
> will be fast enough. It is much easier to prototype the signal
> processing on the PC than on the AVR. An alternative I guess is to
> program some sort of SPI or 4 bit parallel interface using the PC's
> parallel port and up/download samples that way.

There is nice USB stuff as well, but I don't know its speed.
http://www.obdev.at/products/avrusb/index.html

>
> > Meanwhile I did changed the Alaw converter. It now uses the ADC bits
> > as LSB bits and not as MSB bits of the audio input which seems to be
> > much better.
>
> Stefan - have you posted one of these new samples? Which wave file is
> it?

I've probably made some error and only uploaded the new ones and
cannot find the old ones on my machine either. I'm sorry. The
speech*.wav are done with connection to my pc's soundcard, working.wav
is a input test through a phone and playback.wav the same during
playback of the speech.

>
> Thanks,
>
> David

Sadly, now I don't have much time for this, but will try to follow the
development.

Reply all
Reply to author
Forward
0 new messages