1. 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.
    Dismiss Notice

High ADC sampling rate PIC, 18F needed?

Discussion in 'Microcontrollers' started by bananasiong, Sep 29, 2007.

  1. bananasiong

    bananasiong New Member

    Joined:
    Mar 7, 2006
    Messages:
    1,893
    Likes:
    7
    Location:
    Malaysia
    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
     
  2. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,323
    Likes:
    653
    Location:
    Derbyshire, UK
    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.
     
  3. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,233
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi,
    Are you aware of the 18F templates in the Microchip/Templates files??

    They will assist with the CONFIG.:)
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Papabravo

    Papabravo Well-Known Member

    Joined:
    Mar 9, 2006
    Messages:
    2,889
    Likes:
    25
    Location:
    Michigan, USA (GMT-5)

    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
     
  6. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia
    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.
     
  7. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    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.
     
  8. bananasiong

    bananasiong New Member

    Joined:
    Mar 7, 2006
    Messages:
    1,893
    Likes:
    7
    Location:
    Malaysia
    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
     
  9. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,233
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi,

    Which 18F series PIC are you planning to use?
     
  10. bananasiong

    bananasiong New Member

    Joined:
    Mar 7, 2006
    Messages:
    1,893
    Likes:
    7
    Location:
    Malaysia
    It will either be 18F4331 or 2331.
     
  11. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,233
    Likes:
    645
    Location:
    Ex Yorks' Hants UK
    hi,
    Attached the two 18F... templates. In case you dont have them?
     
    Last edited: Jul 7, 2008
  12. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    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.
     
  13. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,323
    Likes:
    653
    Location:
    Derbyshire, UK
    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?.
     
  14. bananasiong

    bananasiong New Member

    Joined:
    Mar 7, 2006
    Messages:
    1,893
    Likes:
    7
    Location:
    Malaysia
    What I have is different to yours :O
    Code (text):

    ;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
     

    Attached Files:

  15. bananasiong

    bananasiong New Member

    Joined:
    Mar 7, 2006
    Messages:
    1,893
    Likes:
    7
    Location:
    Malaysia
    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?
    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
     
  16. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,323
    Likes:
    653
    Location:
    Derbyshire, UK
    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!.
     
  17. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    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.
     
  18. bananasiong

    bananasiong New Member

    Joined:
    Mar 7, 2006
    Messages:
    1,893
    Likes:
    7
    Location:
    Malaysia
    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.
     
  19. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,323
    Likes:
    653
    Location:
    Derbyshire, UK
    What speed serial transmission are you planning?.
     
  20. bananasiong

    bananasiong New Member

    Joined:
    Mar 7, 2006
    Messages:
    1,893
    Likes:
    7
    Location:
    Malaysia
    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.
     
  21. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,323
    Likes:
    653
    Location:
    Derbyshire, UK
    You need to work it out first - and seriously need a hardware UART, as your timing requirements are so tight.
     

Share This Page