Analog to digital convertion

Go To Last Post
25 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is the mean of this"ADC Speed (ksps):15 "?
I am using atmega 128.I want to record 16kHz and 44.1kHz audio with this. Can I use atmega 128 for this purpose?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nope. If you want to record 10bits then the ADC cannot be clocked at more than 200MHz and it takes 13 ADC clocks to make a conversion. 200 / 13 = 15.3 ksps.

If you want a faster sample rate or more accuracy then you need an external ADC. If however you are willing to accept just 8 bit samples you can run the ADC at more than 200kHz so get more than 15.3 ksps.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
200MHz

Mistype

Quote:
If however you are willing to accept just 8 bit samples you can run the ADC at more than 200kHz

According to the datasheet spec up to about 1MHz (~77Ksps)

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Mistype

Once again I blame this bloody tablet. I thought that switching from my wife's iPad to this Galaxy Note 10.1 so I could use my favourite SwiftKey 3 keyboard would make typing "technical text" easier. But it doesn't help that much!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

According to the datasheet spec up to about 1MHz (~77Ksps)

Let's say you can get ample sample rate, and of good quality. Let's say that 8 bits/sample works great. then we are done, right?

Well, let's say we have 1KB of '128 SRAM to buffer 1000 8-bit samples. At 40kHz, that would be 2.5ms, right? That would be two SD card buffers.

So, steady-state, are you going to be able to service a new sample every 25us (interrupt or not) and an SD card block every 1.25ms? I think not.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
If however you are willing to accept just 8 bit samples you can run the ADC at more than 200kHz so get more than 15.3 ksps.

Atmega 128 originally have 10bit conversion.So how can I use the 8 bit conversion mechanism(Procedure to use the 8 bit convertion)?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I betcha its a bit in the a/d control register. I betcha the datasheet tells ya what EVERY BIT does in the register. Want me to cut n paste it back to ya?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How to determine the end of a wav file?
The c function

"while((x=getc(f))!=EOF){}"

is not working for wav files..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Left adjust the result

ADCMUX |= (1 << ADLAR);

and read only the "ADCH" register.

Changed ADCL to ADCH... My bad.. :(

Last Edited: Sun. Jan 20, 2013 - 05:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Milprasad wrote:
Atmega 128 originally have 10bit conversion.So how can I use the 8 bit conversion mechanism(Procedure to use the 8 bit convertion)?

Nothing changes in the result, the ADC still returns 10bits but you can consider the two least significant bits useless, this can be accomplished with shift right two times so that the 10bit value becomes 8bit but there is a better mechanism in AVR to get an 8bit result, you can left adjust the result (check the ADLAR bit functionality) and just read the ADCH for the 8bit result.

Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
So how can I use the 8 bit conversion
Set bit ADLAR and read only ADCH.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lee,

We know from other threads he's using SD/MMC so I guess the next question is "what's really the bandwidth limit: ADC sampling or sector/file write speed?"

As for detecting file end doesn't FatFs have the equivalent of feof() that POSIX has?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

cooluser wrote:
Left adjust the result

ADCMUX |= (1 << ADLAR);

and read only the ADCL register.

Are you sure?

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We seem to be Slowly Converging on the block diagram of an AVR wav file player that will play 16bit mono straight pcm at 44.1KHz using two pwms mixed together. Three minutes after we read the message that says "Cool! Thanx Freaks! It works great" we will read this message: "I have a doubt. How may I decode MP3 compressed files? Is it possible?".

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

cooluser wrote:
Left adjust the result
Code:

ADCMUX |= (1 << ADLAR);

and read only the ADCL register.

Are you sure?


Yeah!! Sure that it is wrong!.. Corrected on the Original post also *apologies*

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
"I have a doubt. How may I decode MP3 compressed files? Is it possible?".

MP3 decoding is very complex, and can be implemented only on DSP (at least real time). The AVR has limited resources for that, and is quite slow, even for the data transfer of high bitrate mp3s (256, 320kbps). So you need at least an AVR microcontroller and an mp3 decoder chip.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do any body know how to determine the end of a wav file?
The c function

"while((x=getc(f))!=EOF){}"

is not working for wav files..

I made the simple wave player.But after playing all the wav samples it will generate "ssh...ssh.." sound.So I need to determine the end of a wav file..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think you read the length when you open the file, then loop until the length is counted down.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok.. Thanks bobgardner.First of all I need to read the wav file into a structure and find the data length...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Milprasad wrote:
What is the mean of this"ADC Speed (ksps):15 "?
I am using atmega 128.I want to record 16kHz and 44.1kHz audio with this. Can I use atmega 128 for this purpose?

Tip.
The AT90PWM3xx have faster ADCs. (2MHz, 8usec)

RES

Last Edited: Sun. Jan 20, 2013 - 07:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is a call in the sd file system for length.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am still struggling to find the length of a wav file.
Somebody please help me...
I found this equation from the web.

Subchunk2Size == NumSamples * NumChannels * BitsPerSample/8

I read the Subchunk2Size and it is 62.
NumChannels =1
BitsPerSample=8
So from this equation I got NumSamples=62

Which is wrong .Please help me..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
There is a call in the sd file system for length.

I can't understand what do u mean?
please explain me again.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I found this equation from the web.

Presumably this page:

https://ccrma.stanford.edu/cours...

I have a WAV file that on disk is 14KB (13965 bytes in fact which is 0x0000368D bytes). If I look at this with a hex editor I see:

Offset      0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F

00000000   52 49 46 46 85 36 00 00  57 41 56 45 66 6D 74 20   RIFF…6  WAVEfmt 
00000010   10 00 00 00 01 00 01 00  40 1F 00 00 40 1F 00 00           @   @   
00000020   01 00 08 00 64 61 74 61  61 36 00 00                   dataa6  

That web page tells us that the first 12 bytes are going to be:

typdef struct {
  char riff_text[4];
  uint32_t length;
  char wav_text[4];
} wav_header_t;

So if I read 12 bytes from the file and cast that interpretation on to it then I find riff_text="RIFF", wav_text = "WAVE" and length = 0x00003685. 0x3685 is 13,957. So this is the file length minus 8.

Alternatively you could find the "data" text at offset 0x24 and at offset 0x28 you have 0x00003661 which is 13,921 which is the number of data bytes that follow the header. That is file size minus 44.

==============================================================================

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks clawson....