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.

PIC A/D Converter

Status
Not open for further replies.

mikeOJ

Member
Hi i want to use the A/D converter to compare voltages received against a set reference. I am writing a short program which if the value received is above a predetermined binary number (representing the voltage reference), the micro will branch to execute a short sequence. if it is below it will discard the reading and wait for the next input.

However i am having trouble setting up the register. i want the A/D converter to sample every 0.12 seconds (Max), and my micro has a clock frequency of 8MHz. How does that relate to the

"TAD"
and
"ADCS" bits shown in the attached file (data sheet screen shot).

I just need a bit of clarification with regard to Acquisition time, thanks.
(I have also added a link to a microchip doc i have been reading to shed more light on the situation)


Screen Shot 2013-06-02 at 09.25.01.png
https://www.electro-tech-online.com/custompdfs/2013/06/adc.pdf
 
It all depends on the input impedance of the voltage you need to sample, and the speed you need to sample at..

Higher impedance generally means slower sampling, so if you have an 8Mhz clock you really have only one option fosc/32 according to table 9-1 in the datasheet.
However you can select a faster conversion if your impedance is low enough.... The quicker you read the ADC sample the less accurate it will be.

If you have a really high impedance you can still take a sample, but you start getting sampling errors...

Equation 9-3 in the datasheet is the best read on this subject.

PS sorry the more TAD cycles you can get away with the better... Normally I use 11... Same as the datasheet...
 
am i able to use an operational amplifier as a buffer on the input so that the impedance is constant and consistent
 
If your voltage isn't changing quickly then you can use a capacitor on the input (between pin and gnd) and that will act as a buffer and effectively reduce the input impedance. Something like a 100nF ceramic should work well.

Mike.
 
Think of it this way.... If you a sampling a frequency of 6Khz and you want to keep it as true as the original you'll want to sample as fast as you possibly can..

But if you are sampling a constant voltage ie.. a sensor then you can sample as long as is necessary to achieve the result...

Set your TAD to 20 and set your ADCS to FOSC/64... then you will have the best you can get for that crystal..
 
its going to be connected to the output of a filter circuit used as ECG the (R-region) of the wave is going to be the peak that is sampled and averaged to determine heart rate so i will be using the output impedance of the op amp as the input impedance
 
I know, i need to sample fast enough not to miss a beat but slow enough so that i don't sample the same peak twice, hence 0.12 seconds is just longer than the duration of the 'r-region' that i am sampling.
 
Personally I would just sample 8 times a second then you get a enough data... I take it you are going to draw the wave onto a LCD screen??

I have a simple oscilloscope program for the pic18f460 with a KS0107 LCD screen I include it here so you can see...
 

Attachments

  • osc.zip
    41.3 KB · Views: 134
Im actually not recreating the the original wave pattern on an LCD (although that makes for an interesting project i will do as an extension to this activity).Im actually just using the A/D input to determine every time i receive an input larger than say 2v (which would indicate the main peak in the waveform). if 2v is represented by the number 50, then everytime i get a number above 50 i count it as a heartbeat and increment a register, everytime i get something below 50 i ignore it and clear the A/D results registers and re sample. if i repeat this for 15 seconds and multiply the result by 4 i can have the heart rate of the user. this will be displayed probably on a 7seg.

i read that the average duration of a peak is recognised to be between 0.8 and 0.12 seconds, therefore 8 times a second will probably be too much as its likely i will over sample and record the peak of one wave more than once. so i guess 8 times a sec is a good rate.

so with reference to TAD and ADCS how would i go about this?
 
was planning to use a timer with overflow interrupt to for the 15sec timer. how would int0 help with the rate of sampling?
 
Personally I would just sample 8 times a second then you get a enough data... I take it you are going to draw the wave onto a LCD screen??

I have a simple oscilloscope program for the pic18f460 with a KS0107 LCD screen I include it here so you can see...

nice,
can share here its circuit diagram ?
 
my task now is to determine what value of TAD will give a 1/8=0.125s rate of sampling given an 8MHz oscillator frequency an 2MHz instruction cycle how do i go about this, im a little confused because values for acquisition time are given as arbitrary values (12 TAD, 8 TAD, 20 TAD) not actual frequencies
 
was planning to use a timer with overflow interrupt to for the 15sec timer. how would int0 help with the rate of sampling?

You aren't sampling though.. You are just counting above 2V
 
So therefore there is no acquisition/ conversion time considerations? Especially since the signal I am considering is going to be received at such a slow interval (with respect to microcontroller speed)

Forgive all my questions Ian and thanks. I'm used to pics, just this is my first time using the A/D I came up with this idea which seems feasible but implementing it is beyond my scope of experience
 
Hi Mike,

The acquisition time is explained in section 20 and 20.1 https://www.electro-tech-online.com/custompdfs/2013/06/39932b.pdf

When you change the ADC channel that you will be sampling, you need to worry about the acquisition time. If you're just using the same channel for each sample, then you don't have to worry about it for any conversion except the first. The acquisition time is the time for the internal hold capacitor to charge, and not the time between samples as I think you may have believed.

So the simplest (not requiring thought) setup is to use the internal AD clock (which means that your fosc frequency doesn't matter), and you can set max acq time if you're changing channels.
 
If you just want to check above a certain level then you may want to consider using a comparator. The built in ones will allow you to set a level and even some hysteresis to prevent false readings. You may find this document useful.

Mike.
 
Thanks guys,

Pommie ive actually tried with the comparator and its lead me here, the hysteresis on the comparator is not suitable for this application because while each transition of the comparator output increments the register, the comparator was experiencing multiple transitions for each input above the specified voltage, so the register increment would be way in excess of what was expected. the result was better with hysteresis than without but still not sufficient or even a consistent value that could be adjusted through software.

The transient analysis i with the comparator values calculated using the formulas in the document that u uploaded provided showed me that theoretically the hysteresis should have worked but, the practical outcome was not the same.

Thanks dougie, you're right, i was of the opinion that acquisition time was for time between samples. things are a bit clearer now
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top