ADC on a pic 18f

Thread Starter

chaosenvoy

Joined Aug 6, 2017
49
Hello i have been trying to lean how to do ADC on PIC i have which is 18F2550, after watching many tutorials & reading the data sheet i came up with this C source code. i have been on & off pic programming for a while. i was able to blink a Led & create an interrupt on the pic i have,
I'm a bit confuse about the Tad setting & the Vref setting i don't understand how it really works.
I played around with the Tad & Fosc setting just to see the how much an effect it has on the output, i don't have a scope so i'm flying blind.
I had a DS212 pocket scope but it just stop working.
I have a 500k potentiometer on AN0 & a led on PORT7, any explanation on Tad & Vref, & help with the code will be greatly appreciated thank you in advance. my code is attach below.
 

Attachments

MaxHeadRoom

Joined Jul 18, 2013
20,405
Also

Example using a pic16F877

Per the datasheet, A/D clock period minimum is at 0.7us and maximum is at 25us.

This is telling you the requirement in microseconds, but the PIC works in clock cycles.

using an 8MHz crystal oscillator.

So "Fosc/16" would be 8MHz/16 = 0.5MHz.
Each individual cycle is 1/0.5MHz = 2us
So, that fits right into the allowed range.

TAD is the time taken for one cycle of the ADC conversion. It takes 11 of these cycles to do a complete conversion.
You have no control over how MANY cycles are taken.
All you control is how long a single TAD cycle is, which you control by how many clock cycles each one is.
If you select "Fosc/16", then each TAD cycle is one sixteenth of your main clock cycle.

If the 2us is already at 16TOSC. So to select 12TAD that would be. 12 x 2us = 24us. If it needs to be shorter, 2TAD = 2 x 2us will give a 4us.
Max.
 
Top