Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

High ADC sampling rate PIC, 18F needed?

Status
Not open for further replies.

bananasiong

New Member
Hi,
I'm using PIC to digitize/sample the audio signal, then send to another PIC and a D/A converter to get back the audio.
Currently I'm testing with only a single PIC, sample and D/A. I've just tested with PIC16F88, I found that the quality of the D/Aed output is not that good at 2 kHz and above, around 10 kHz and above, aliasing happened.
Then I found from Microchip site that the maximum sampling rate of 16F is only 30 ksps, while a few 18F PIC can be up to 200 ksps.
As a first time user of 18F PIC, I write my first 18F program in MPLAB. There are so many configuration settings!! And the format of the configuration is different from 16F as well.
The datasheet of the 18F PIC is really complicated, the opcode is also more :'(.

Is there any solution for using 16F PIC? Or I should start using 18F?

Thanks
 
If the 18F series has the faster analogue conversion time you may as well move to that. However, if you're getting anti-aliasing problems, it's because you're not bandwidth limiting the input (and the output?) correctly.
 
hi,
Are you aware of the 18F templates in the Microchip/Templates files??

They will assist with the CONFIG.:)
 
bananasiong said:
Hi,
I'm using PIC to digitize/sample the audio signal, then send to another PIC and a D/A converter to get back the audio.
Currently I'm testing with only a single PIC, sample and D/A. I've just tested with PIC16F88, I found that the quality of the D/Aed output is not that good at 2 kHz and above, around 10 kHz and above, aliasing happened.
Then I found from Microchip site that the maximum sampling rate of 16F is only 30 ksps, while a few 18F PIC can be up to 200 ksps.
As a first time user of 18F PIC, I write my first 18F program in MPLAB. There are so many configuration settings!! And the format of the configuration is different from 16F as well.
The datasheet of the 18F PIC is really complicated, the opcode is also more :'(.

Is there any solution for using 16F PIC? Or I should start using 18F?

Thanks
You're not likely to produce much in the way of pleasing audio results with ROTM* components. High end audio equipment is expensive for a reason. Do the initial experiments with the PIC and then switch to a 56000 series, or a Blackfin, or a TMS320. A PIC just doesn't have the schtuts for audio processing.

*ROTM - run of the mill
 
I agree with Nigel, you need to filter your input signal. When I programmed SNES games we sampled most instruments at 8kHz and filtered anything above half the sample frequency. The only thing we ever had problems with was hihats and snare drums. If we were doing speech then we sampled at 1kHz. If you filter your input signal at half your sampling frequency then the noise should disappear. Please note that the filtering has to be done analogue wise unless you have very good software and can sample at 30kHz before digitally filtering and re-sampling at the lower frequency.

Mike.
 
The ADC's on micro controllers are really more for analog control use not high quality high speed sampling for audio or precision applications. If you want higher quality you should probably use an external ADC, then you can use a cheap PIC and a decent inexpensive dedicated ADC to get great results.
 
Hi all,
Thanks for all the responses, I appreciate that :)
This is still the beginning plan, I have not decided which method to be used yet. But I know, experiments have to be done.
If I want to sample the audio signal as high as 20 kHz, then the sampling rate should at least be 40 kHz. But I'm not sure why the low pass is needed, because the input is coming from the audio source (20 Hz to 20 kHz). The filter is needed at the DAC output because of the "staircase smoothening".

Thanks eric for the info, but there is only one example in the templates. It seems _CONFIG1 type is no longer being used. How if I want to set the configuration setting by hexadecimal instead of setting one feature followed by another?

Thanks
 
bananasiong said:
Thanks eric for the info, but there is only one example in the templates. It seems _CONFIG1 type is no longer being used. How if I want to set the configuration setting by hexadecimal instead of setting one feature followed by another?

Thanks
hi,

Which 18F series PIC are you planning to use?
 
bananasiong said:
It will either be 18F4331 or 2331.

hi,
Attached the two 18F... templates. In case you dont have them?
 
Last edited:
Noise comes from a plethora of sources, not just the signal source. For the ADC on a PIC I'm sure it's not listed on the white paper but the digital components near the ADC unit have a cross talk to the ADC, above it's maximum sampling rate and then some. Any frequency above the Nyquist rate inverts itself after cutoff at half the power unless its filtered, beyond that the harmonics continue to compound. Filtering is a must.
 
bananasiong said:
Hi all,
Thanks for all the responses, I appreciate that :)
This is still the beginning plan, I have not decided which method to be used yet. But I know, experiments have to be done.
If I want to sample the audio signal as high as 20 kHz, then the sampling rate should at least be 40 kHz. But I'm not sure why the low pass is needed,

The input filter is probably even more important?, otherwise you can end up with a completely different sound being recorded. It's not just 'important' it's absolutely 'essential' that you don't provide any frequencies higher than double the sampling frequency, and preferably less than that.

The sampling frequency of CD is 44.1KHz to give 20KHz bandwidth, and recordings are bandwidth limited to 20KHz to prevent aliasing problems.

If you sample a 20KHz sinewave at 44.1KHz, it comes out looking something like a sinewave (due to the output filtering), if you sample a 20KHz sinewave at only 30KHz it will come out looking nothing like 20KHz, more likely a MUCH, MUCH lower frequency. Try it with a piece of graph paper, draw a sinewave, then draw sample points at only 1.5 times the frequency - then joint the points together and see what you get.

Doing 40KHz sampling and processing with a PIC seems to be pushing thinks rather?, you've only got 25uS to read the sample, and process it however you're wanting to do it.

Perhaps you might like to tell us EXACTLY what you're trying to do, and what you're hoping to achieve?.
 
ericgibbs said:
hi,
Attached the two 18F... templates. In case you dont have them?
What I have is different to yours :O
Code:
;Configuration bits
;Microchip has changed the format for defining the configuration bits, please 
;see the .inc file for futher details on notation.  Below are a few examples.



;   Oscillator Selection:
    CONFIG	OSC = LP             ;LP
 

Attachments

  • 4331temp.asm
    5.4 KB · Views: 396
Nigel Goodwin said:
Doing 40KHz sampling and processing with a PIC seems to be pushing thinks rather?, you've only got 25uS to read the sample, and process it however you're wanting to do it.
That is for 16F devices, isn't that?
I see the datasheet of 18F4331, only 0.62 us is needed for the acquisition time, and the process of sampling takes only 5 us. That should be enough for 25 us?
Perhaps you might like to tell us EXACTLY what you're trying to do, and what you're hoping to achieve?.
I'm trying to digitize the audio signal, either A/D from PIC or from other A/D conversion IC. Then the data is sent to another PIC serially and there is another D/A converter at the receiver PIC to get back the audio signal.

Thanks
 
It doesn't matter what device it is, you've only got 25uS between samples, and you've got to send the data out before the next one is due - so you're talking about some pretty speedy serial!.
 
This is why you use an external ADC. You then don't have to worry about high frequency noise quiet as much as the ADC unit isn't on the same die as the digital portions. If this is for basic audio try closer to 8khz. Only hi-fi music needs the higher sampling rates.
 
That's not for hi-fi music, just simply the audio output from the MP3 player.
Even I can lower the sampling rate, but I think the speed of the PIC need to be fast enough to perform faster serial transmission.
 
bananasiong said:
That's not for hi-fi music, just simply the audio output from the MP3 player.
Even I can lower the sampling rate, but I think the speed of the PIC need to be fast enough to perform faster serial transmission.

What speed serial transmission are you planning?.
 
I have not decided yet. I'm hoping to send out the serial data before the second data being sampled so that I have enough time to do something else. Maybe UART will be used for the transmission, I'm still doing research on that.
 
bananasiong said:
I have not decided yet. I'm hoping to send out the serial data before the second data being sampled so that I have enough time to do something else. Maybe UART will be used for the transmission, I'm still doing research on that.

You need to work it out first - and seriously need a hardware UART, as your timing requirements are so tight.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top