Connect with us

PIC A/D sampling help

Discussion in 'Microcontrollers, Programming and IoT' started by Rajinder, Jun 17, 2018.

  1. Rajinder

    Rajinder

    408
    7
    Jan 30, 2016
    Hi
    I have attached two waveforms that are going into a PIC18F4520 micro A/D pin.
    The PIC is powered from 3V using the VDD (3V) as the internal reference voltage.

    Waveform 2 should be easy to measure, it settles at 900mV.

    I am struggling with waveform 1, which cycles through 1.3V and 800mV.

    I need to differentiate between the two waveforms.

    The only pin available is the A/D. However i am not sure how to sample the waveform for say 5 samples and then take the average to perform my measurement and then comparison. Waveform 2 i think could be tricky.

    Can anyone advise please.
     

    Attached Files:

  2. BobK

    BobK

    7,642
    1,662
    Jan 5, 2010
    Sampling for a while and keeping track of the max and min readings should be easy and reliable.

    Bib
     
    Rajinder likes this.
  3. Harald Kapp

    Harald Kapp Moderator Moderator

    9,366
    1,901
    Nov 17, 2011
    Keep in mind that the sampling rate needs to be at least twice the signal frequency to avoid aliasing.

    If you're only interested in distinguishing the two signals, you could also use a peak detector circuit made from a diode a capacitor and a large bleeder resistor. Assuming a silicon diode (Vf = 0.7 V) the upper waveform will result in ~0.6 V at the ADC input, the lower waveform in ~0.2 V.
     
    Rajinder likes this.
  4. Rajinder

    Rajinder

    408
    7
    Jan 30, 2016
    Hi
    Thanks for the replies.
    This is the output that i get from the hardware. It is 4KHz, signal.
    So i should sample at least at 8KHz.
    I can't change the hardware, as PCBs are already done.
    Hence this is why i asked about using software. All i want is to distinguish between the two waveforms.
    The dc level should be fine..i was going to sample and then take an average and see if it is a certain range.
    I wasn't sure on the other waveform as it oscillates, how can i measure the oscillations using the A/D? Would i just sample then read and see if i get a few 'dips' in voltage from 1.3V to 0.8V?
    Thanks in advance.
     
  5. Harald Kapp

    Harald Kapp Moderator Moderator

    9,366
    1,901
    Nov 17, 2011
    One should consider such issues before laying out the PCB. Planning to do "everything" later in software is not without problems, as you can easily see taking the example of this design.

    Especially not if you have no idea what to do in software.
    That is one possibolity, among others.
     
  6. BobK

    BobK

    7,642
    1,662
    Jan 5, 2010
    It looks like the second waveform never gets above it steady state of 900 mV, so just detecting a peak of over, say, 1.1 V should be enough. You need to try it and see if it works reliably. For a 4 KHz waveform, if you sample at 8KHz you might always sample the zero crossing, If you know it is always close to 4 KHz, sample at 5KHz for about 10 cycles and you can be certain of hitting somewhere near a peak. If the frequency ranges widely, you would need to sample at 10 times the highest frequency.

    Bob
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-