# Convert an analog audio signal to digital with a PIC and send the data through serial to a PC

I want to convert an analog audio signal to digital signal and send it to serial input in my computer. How can I do this?

Microcontroller used: PIC18f452

-
Please be more specific, which microcontroller you want to use, because we can't choose it for you. Update your question with those specific details. Otherwise I have to vote this for deletion. – sandun dhammika Aug 18 '12 at 14:08
@sandun - You mean when you'll have 3000 rep, I guess ;-) (just teasing! I also started at 101.) – stevenvh Aug 18 '12 at 14:15
im going to use PIC18f452 microcontroller – Thulana Vimukthi Aug 18 '12 at 14:15
@ThulanaVimukthi just wondering and by computer do you mean to your PC, so have the PIC capture the analog signal and send it to the your PC via a serial bus? Or you want to use a serial Analog to Digital Convertor aka an ADC to the PIC – kenny Aug 18 '12 at 14:17
@sandun - I said I was just teasing :-)! Don't take it badly. – stevenvh Aug 18 '12 at 14:23

That PIC can do 50 ksps, which is good for a 20 kHz bandwidth, though the 10 bit limitation won't give you HiFi quality, of course. 50 ksps $\times$ 10 bit is an output of 500 kbps, or 800 kbps if you send each sample in 2 bytes.

You don't want to go via EIA-232 to your PC. Many PCs don't even have EIA-232 anymore. The standard nowadays is USB. The PIC18F452 doesn't have USB on board, but luckily there's FTDI :-). FTDI's ICs have become the de facto standard for easily connecting microcontrollers to USB. All you need is this (or something similar):

At the left you can see RxD, TxD and GND connections which go to the PIC's UART, the connector goes to the PC. The IC is an FT232R, which supports data rates up to 3 Mbps, so that's enough for your application.

If you tell us what the audio signal looks like (particularly level) we can tell you how to hook that up to the PIC.

And then it's just sampling, and upon each EOC (End of Conversion) send two bytes to the UART.

-
 any suggestion of inexpensive chips than this,if just serial port then MAX3232 – sandun dhammika Aug 18 '12 at 15:11 @sandun - But MAX3232 is only good if the PC has an EIA232 (aka RS232) port, and like I said in my answer, many don't. It's also possible that the port, if present, doesn't support 3 Mbps data rate. Also the IC costs only 4.50 dollars, and you only have to add the connector. – stevenvh Aug 18 '12 at 15:17 thanks sir I am giving audio signal from mic. can you tel me how pic output set tothe FT232R IC – Thulana Vimukthi Aug 18 '12 at 15:45 No something is messy, I'll met the guy who did that and update all that info, there's a chip. Neither MAX2323 nor MAX3232 they are just level converters. – sandun dhammika Aug 18 '12 at 15:51 @Thulana - [You don't have to call me sir, I'm Steven.] Page 5 of the datasheet shows the pinning for the DIP package (I'll assume you want that one). Pins 25 and 26 are Tx and Rx resp. You simply connect those to Tx and Rx on the breakout board. That board is set for 3.3 V. If your PIC runs at 5 V you'll have to delete a solder bridge. – stevenvh Aug 18 '12 at 15:53

Your question is not specific enough to give details, but to answer simply:

• Pick a PIC with ADC and USART peripherals (pretty much any PIC aside from the low end PIC10F and possibly some PIC12F) Anything from PIC16F upwards should be suitable (exactly which would depend on what resolution and sample rate you need, but you didn't include that info)

• Write some code to sample at desired rate using the ADC and store in a buffer

• Send contents of buffer to PC using USART (will need something like Max232 to shift PIC levels to RS232 levels)

-
 actualy i want to convert analog audio signal to digital by using PIC18f452 microcontroller – Thulana Vimukthi Aug 18 '12 at 14:24 @ThulanaVimukthi if you use microc then it have a fancy library, you just only need to call a function. – sandun dhammika Aug 18 '12 at 14:27 mikroe.com/download/eng/documents/compilers/mikroc/pro/pic/help/… – sandun dhammika Aug 18 '12 at 14:28 @ThulanaVimukthi - yes I understand that, the PIC you mention will do this fine. What more do you need help with though? If you can be specific in your question about what you need to know then we can be more specific with answers. For instance, do you need help with the code? If so which part of it? Do you need help setting up the hardware? Have you used a microcontroller/PIC before? – Oli Glaser Aug 18 '12 at 15:03 Also as Steven mentions, RS232 (aka EIA232) is obsolete, so unless you have good reason for using it then USB or a USB to serial converter (e.g. FT232) would be better. – Oli Glaser Aug 18 '12 at 15:04