Maker Pro
Maker Pro

PIC A/D sampling help

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
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.
 

Attachments

  • 20180617_220216.jpg
    20180617_220216.jpg
    107.2 KB · Views: 46

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
Sampling for a while and keeping track of the max and min readings should be easy and reliable.

Bib
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
Sampling for a while
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

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
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.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
I can't change the hardware, as PCBs are already done.
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.
Would i just sample then read and see if i get a few 'dips' in voltage from 1.3V to 0.8V?
That is one possibolity, among others.
 

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
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
 
Top