zach_blader
New Member
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
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