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

ADC (audio sampling) and PWM (audio playback)

Discussion in 'Microcontrollers' started by MrNobody, Feb 13, 2008.

  1. MrNobody

    MrNobody New Member

    Joined:
    Aug 29, 2006
    Messages:
    251
    Likes:
    3
    I would love to get that chip.. but here in Malaysia, i dun think that chip is easily obtainable.. I may have to order it from overseas.. US$2 is equivalent to $7 and that is excluding the shipment cost.. Shipment itself is maybe $10 to $20 more so eventhough the chip is cheap, but the total cost is alot more expensive..
     
  2. MrNobody

    MrNobody New Member

    Joined:
    Aug 29, 2006
    Messages:
    251
    Likes:
    3
    Hmm.. i need some thoughts on buffer size..
    I mean.. lets say i build 2 modules (each module consist of PIC18F4620 with ENC28J60). One PIC (PIC_1) will capture voice data and then send it to another PIC (PIC_2) through ethernet and another PIC_2 will play the voice out.. At the same time, the other PIC_2 also capture a seperate voice data and send to PIC_1 to be played out.. Kind of like full duplex VoIP..
    Is there a general rule of calculating the buffer size or buffer time..? Is buffer time of 200ms ok for acceptable communication..?

    8 bits sampled at 8kHz = 64000 bits (per second)
    Buffer of 200ms --> 0.2 * 64000 = 12800 bits (per 0.2 seconds)

    Later, this module will also be communicating with a computer running the VoIP software which I will be writting..

    That wouldn't be heavy on PIC18F4620 running TCP/IP stack with other functions would it..?
     
    Last edited: Feb 17, 2008
  3. Oznog

    Oznog Active Member

    Joined:
    Apr 21, 2004
    Messages:
    2,879
    Likes:
    11
    Location:
    Austin, Tx
    Well, by 200msec the conversation might already be awkward, esp 200ms x2. Conversations are sensitive to delays, it gets weird when you say something and there's a delay in the answer.

    But you've probably noticed buffer underruns would suck, and starting with zero delay underrun may happen. And if we stall the DAC and extend the buffer to a "large" amount early on because of a temporary lag, can we ever get that buffer latency back down?
     
  4. dave

    Dave New Member

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


     
  5. MrNobody

    MrNobody New Member

    Joined:
    Aug 29, 2006
    Messages:
    251
    Likes:
    3

    Thanks Oznog.
    Sorry for the late reply.. Didnt realise that you have repled..
    Hmm.. why 200ms buffer will cause 200ms x2 delay..?

    If we stall the DAC and extend the buffer to a "large" amount early on, won't that cause the initial delay to be significantly larger than following delay..?

    As for the latency, if we decrease the buffer time, that would improve the latency right..?

    Hmm.. generally speaking, what is the prefered/allowable delay time..? 100ms..?
     
  6. amrish_deep

    amrish_deep New Member

    Joined:
    Nov 22, 2008
    Messages:
    4
    Likes:
    0
    How to acheive 10000samples/s

    Hi Nigel,

    We are using the following code to read the adc value from the PIC using Internal clock frequency.

    for(i=0;i<50000;i++)
    {
    a = read_adc();
    printf("%lu",a);
    }


    The above code snippet takes > 200s to execute and I am unable to acheive the sampling rate of around 10,000 samples/s. Is this the right way to sample analog signals using PIC?

    *** We are using PIC to perform ADC on sound waves sensed using microphone.

    -Amrish
     
  7. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,234
    Likes:
    641
    Location:
    Derbyshire, UK
    Using C is crippling your speed for a start - and where is printf sending the data, and how long does that take?. The problems aren't so much sampling time, but what you do with the data afterwards.
     
  8. amrish_deep

    amrish_deep New Member

    Joined:
    Nov 22, 2008
    Messages:
    4
    Likes:
    0
    Re How to acheive 10000samples/s

    To give a gist about our project,
    We are building a Motor Speed Detecting circuit using
    1. PIC - 16F877
    2. Microphone
    3. Matlab (Serial Interfacing PIC with PC)

    The Microphone is connected to the PIC through a differential amplifier. The noise from a motor is sensed using this microphone.PIC then serializes the data to my PC via a 'RS-232 USB Adapter'. We will be plotting a FFT based on the microphone output data in Matlab and after correlating the the dominant frequency to the Motor's angular velocity, we will send back the processed data to the Micro-controller which displays the data using the LCD.

    Using PIC is mandatory and the problem arises with the rate of sampling/transmission I guess. We need around 50,000 sample data at a sampling rate of at least > 5000hz .

    The Data Sheet of the PIC clearly indicates that this sampling rate is easily achievable. But when I transmit the data to the PC using printf as I had mentioned earlier, I am able to achieve a modest sampling rate of ~ 100 data/second.

    We assume that the slowness is because of the transmission between PIC and PC (RS232-USB Adapter). Is there any other efficient way to transmit the data (other than the printf?) is there any other suggestions which you can make in this regard?

    -Amrish
     
  9. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,234
    Likes:
    641
    Location:
    Derbyshire, UK
    printf seems the worst possible way you could try and transfer the data - you just need some serial output routines, preferably using the internal UART in the PIC. There are assembler examples in my tutorials (the last RS232 one uses the UART), it should be simple to convert to C if required (although the entire program would be trivial in assembler, as it's very simple).

    Do you have a real serial port you can use on the PC?, serial to USB conversion is often really, really slow - the USB overheads severely limit the data transfer speed. USB is designed for continuous data, not the byte at a time method that serial uses. Supposedly some modern ones are faster, but the older ones are limited to about 9600 baud by the USB overhead.
     
  10. kchriste

    kchriste New Member Forum Supporter

    Joined:
    Jul 23, 2006
    Messages:
    3,677
    Likes:
    47
    Location:
    Victoria BC, Canada
  11. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,234
    Likes:
    641
    Location:
    Derbyshire, UK
    If you check the PICList there's an audio spectrum analyser, and the article with it says the MicroChip routines don't work.

    Easier to do it on the PC, the PIC part then is trivial and easy.
     
    Last edited: Nov 24, 2008
  12. kchriste

    kchriste New Member Forum Supporter

    Joined:
    Jul 23, 2006
    Messages:
    3,677
    Likes:
    47
    Location:
    Victoria BC, Canada
    Funny, I got their code to work on a dsPIC running at 8Mhz. A 256 point FFT took 6ms to execute. I've never tried the non dsPIC (AN542) code though. Either way, the OP is going about sensing the motor speed the hard way. There are much easier ways, such as a shaft encoder, to determine motor speed.
     
    Last edited: Nov 24, 2008
  13. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,234
    Likes:
    641
    Location:
    Derbyshire, UK
    Presumably it's a school, project - so has to be done the most difficult way possible? :D
     
  14. kchriste

    kchriste New Member Forum Supporter

    Joined:
    Jul 23, 2006
    Messages:
    3,677
    Likes:
    47
    Location:
    Victoria BC, Canada
    Usually I sniff them out sooner. Maybe I'm coming down with something? :D
     

Share This Page