Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Sample an Audio signal using 18F452 & send the samples to the computer

Status
Not open for further replies.

ranganafox

Newbie level 4
Joined
Aug 20, 2012
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,333
Hey PPL!

I'm having a problem with sampling a audio signal using 18F452 Microchip.I've written the mikroc program to sample the audio signal & send it to the computer as soon as PIC reads the sample value(It's been attached with this post).My problem is I tried simple sinusoidal wave of 50Hz to sample but the number of samples are very less As I wouldn't expected.Normally PIC18F452 is sampling a analog signal once a 1.9uS so there should be plenty of samples but what I'm getting is not much of samples/Please help me.

If I'm gonna use this for Audio signal The number of samples won't be enough to reconstruct the audio file again.

Thanx!!
 

Attachments

  • Circuit.JPG
    Circuit.JPG
    141.3 KB · Views: 75
  • Samples.TXT
    3 KB · Views: 65
  • MikroC Code.rar
    30.7 KB · Views: 48

hi in this you using sinusoidal waveform only.

For starters I used sinusoidal wave with very much less frequency as 50Hz.It is nothing compared to the ADC sampling rate of the PIC18F452 But the problem is it doesn't give much of samples.I used Serial communication with max232 & hyperterminal to watch the ADC values.

Afterwards I'm gonna use sound wave but first I should make sure the no of samples are enough So that's why I used basic input as Sin wave.
 

For 50Hz sin wave I got 10-15 Samples for a cycle(I've attached my samples,mikroC code & proteus drwaing of my cct please check it).If I'm gonna get that much of samples for 50Hz That's absurd.I expected much more than that.besides when it comes to sound signal it won't be definetly enough
 

If you can re produce the signal in the computer correctly that's it.Say If there is a sound signal of 2KHz what I do is I use PIC 18F452 to sample the signal & using serial communication I send it to the computer,After that computer take the values of ADC & Re construct the signal using matlab.So If I can do that.That's what i want.

Answer for ur question.If i use 50 Hz Sin wave which means it takes 20ms to complete a cycle.& the ADC rate is set in the 18F452 is 1.6uS say it's 2uS,Then there should be at least 10000 samples.but what i get is 10-15 samples.
 

you want to calculate the serial communication timing also.

you try it in interrupt.
 

1.9 us of sampling time? or TAD?
(remember, TAD should be greater than 1.6us)
a TAD of 1.9us (which is ok) will give a minimum of 23us of sampling time... (F_sample= 43 kHz)

any way at a 50Hz signal (T=20ms) it will give near 870 samples per cycle...

Which is apparently ok...

apparently...

Now, don't forget another issue.... the communication to the PC...

If you are communicating to the PC with a serial (USART) port via RS232, you are very limited by the communication baud rate...

for example... if you are communicating at 9600 bps
that's 104us per bit... Let's assume a common byte (8bits) with start bit, stop bit and no parity (total 10 bits)
that's 1.04ms per byte

and let's assume you sample 8 bits of your signal, and send them in binary(hex) directly to the port...

you can send Only one sample at every 1.04ms that's a F_sample= 961 Hz
that's almost 19 samples per cycle of a 50Hz signal...

but, let's face it... if you send continuous data stream at 9600bps you will have many sync errors... so your actual F_sample should be slower.... (minimallyIi would try sending 2 stop bits... so 1.114 ms per byte... F_sample=874 Hz and 17 samples per 50Hz cycle....) and it get's worse if you need/want 10 bits (or more) of data in the PC... (you can send only 8 bits so you will need 2 bytes per sample... so your F_sample halves itself!)


So, that's the figure...



Conclusion... It's a communication issue... do your work inside the micro or upgrade your communication (change to USB or something faster)

PD: I took a look at your code, still 57600bps isn't enough but you can do the numbers :)
 

1.9 us of sampling time? or TAD?
(remember, TAD should be greater than 1.6us)
a TAD of 1.9us (which is ok) will give a minimum of 23us of sampling time... (F_sample= 43 kHz)

any way at a 50Hz signal (T=20ms) it will give near 870 samples per cycle...

Which is apparently ok...

apparently...

Now, don't forget another issue.... the communication to the PC...

If you are communicating to the PC with a serial (USART) port via RS232, you are very limited by the communication baud rate...

for example... if you are communicating at 9600 bps
that's 104us per bit... Let's assume a common byte (8bits) with start bit, stop bit and no parity (total 10 bits)
that's 1.04ms per byte

and let's assume you sample 8 bits of your signal, and send them in binary(hex) directly to the port...

you can send Only one sample at every 1.04ms that's a F_sample= 961 Hz
that's almost 19 samples per cycle of a 50Hz signal...

but, let's face it... if you send continuous data stream at 9600bps you will have many sync errors... so your actual F_sample should be slower.... (minimallyIi would try sending 2 stop bits... so 1.114 ms per byte... F_sample=874 Hz and 17 samples per 50Hz cycle....) and it get's worse if you need/want 10 bits (or more) of data in the PC... (you can send only 8 bits so you will need 2 bytes per sample... so your F_sample halves itself!)


So, that's the figure...



Conclusion... It's a communication issue... do your work inside the micro or upgrade your communication (change to USB or something faster)

PD: I took a look at your code, still 57600bps isn't enough but you can do the numbers :)

Yeah!!I think u got ma point.Anyway I'm working with sound localization project.So i need to get this done somehow.Do u have any suggestions??How can i get this thing done??

I have an idea But don't know whether this will work.What if i use some external SD card & right whole bunch of samples to that & afterwards I can read from the SD card??It seems It's lil improbable to read the ADC value & send it at that speed.How ever I need to improve this amount of sample further.

So give me your suggestions!

Thanx!!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top