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.

Using the ADC on the PIC16F871

Status
Not open for further replies.

zach_blader

New Member
Sorry I am new to this so I didn't really think of it plus my design is very much in the early stages at the minute.
I'm looking to use the PIC16F871 to work as an ADC as it already has a sample and hold circuit contained within it. I think I have the basics in place for my programme well the idea of how to use the ADC I am just a bit unsure about the acquisition time and how I can control the sampling frequency etc.
I need to have a sampling frequency of 40Khz, so I can sample audio. I need to be able to output the 10 bit ADC conversion to the rest of my circuit also.
So far I haven't written any code but my ideas are;

In ADCON1 Register, Set the bits 0-3 as 1110, (To give 7 digital I/O and 1 Analog Input)
In ADCON0 Register, Set the bits 3-5 as 000, (To select RA0/AN0 as the analog input)
I then need to select the A/D Conversion clock which I am unsure about.
In ADCON0 Register, Set bit 0 to 1, (To turn on the module)
Then I could use the A/D interrupt feature but I don't understand this.
Wait the required Acquisition Time given as 19.72us in the data-sheet
In ADCON0 Register, Set bit 2 to logic 1, (Start the conversion)
In ADCON0 Register, Test bit 2 for a logic 0, (Conversion complete)
Read A/D Result register pair (ADRESH:ADRESL)
Return To the beginning
Wait at least 2TAD (2 x Time to convert 1 bit)

This could be horrifically wrong, I am new to PIC programming and tried to follow the data-sheet but there were a few things I couldn't get my head around.
As if I have to wait 19.72us for the acquisition time, It doesn't leave a lot of time for the conversion and everything before the next sample. Because at 40Khz each sample is at 25us. So how do i set the sampling clock and the conversion clock in the PIC?? Thanks if anyone can shed any light onto my situation.
Many Thanks
P.s sorry if I am being stupid and have missed something completely obvious :)
 
Move the post to the PIC forum.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top