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.

Setting up ADC in PIC16F684 (2)

Status
Not open for further replies.

Wingmax

New Member
Please refer cct diagram:

**broken link removed**

This is an example program to test the ADC function.

Continue from last discussion:

We have to calculate the Acquistion Time.
TACQ= Tamp + Tc + Tcoff
Tamp and Tcoff can be found from the data manual.
Tc can also be found from the manual, but varies by the analogue input source resistance.
We use 10K POT, so max Rs= 10k.
TACQ= 19.72 uS (20 uS approx) (Refer manual).

The conversion time is 11 TAD cycles. Last time we calculated the TAD= 2 uS. So
Conversion time= 11x 2= 22 uS.

We have to allow minimum of 20 + 22= 42 uS for each ADC sample.

In our example we use VDD as voltage reference. The conversion result is in 10 bits, so there are
1024 values (0 to 1023). Each value is equiv to VDD/ 1024= 0.0048828125v.

If we are using 10 LEDs, each one should come on at the increase voltage of 5/10= 0.5v .
The first one should come on at 0.5v (LSB), the third one at 1.5v, and the last one should come on
at 5v(MSB).

Since we only use 8 LEDs and left justified. So the first LED that comes on is the second bit of the conversion result but the 0 bit of ADRESH.

Here is the program code:

View attachment ADC test prog.txt


https://s271.photobucket.com/albums/jj148/wingmax2/?action=view&current=IMGP1430.flv

URL=http://s271.photobucket.com/albums/jj148/wingmax2/?action=view&current=IMGP1430.flv]**broken link removed**[/URL]
 
Last edited:
Thanks for this. I tried it and added the files 'delay.c','delay.h' and 'always.c' to the 'adctest.mcp'. Is this the correct way of doing it? When I tried to build the 'adctest.mcp' it gave some errors.

Cheers

Tom
 
tomskj said:
Thanks for this. I tried it and added the files 'delay.c','delay.h' and 'always.c' to the 'adctest.mcp'. Is this the correct way of doing it? When I tried to build the 'adctest.mcp' it gave some errors.

Cheers

Tom

Hi Tom,
After downloading the delay routines, copy the delay.c and delay.h files into the same directory where you store your main source program, then in you main program put in #include "delay.c
#include "delay.h

just like what I did in my example program. No need to use 'always.c'
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top