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.

Adc 16f877 8 bit to 10 bit

Status
Not open for further replies.

maria258

New Member
I have already done an 8 bit mode adc but would like to change it to 10 bit. How can this code be altered to make it a 10 bit?

thanks
maria

Code:
#include<htc.h>

__CONFIG (0x3F72); //configured fuses
//define ports for easier reading
#define LEDS PORTB

void delay(unsigned char itime);

void main(void)
{
//8bit data-type variables
unsigned char x;	//ADC low byte
unsigned char y;	//ADC high byte
unsigned int z;	//final result

TRISB=0x00; //output
TRISA=0xFF;	//inputs
LEDS=0xFF;	//clear/switch off LEDS

while(1)
{
//ADFM=1, all i/ps analog, +VREF enabled
//Configure the functions of the Port bits
ADCON1=0b10000001;
//clock/channel select & enable bits
//controls the operation of the A/D module
ADCON0=0b11000001;


delay(1);
//Start a2d conversion
//Set GO bit (ADCON0=ADCON0|1;)
GODONE=1;
//wait end-of-conversion (conversion complete)
while(GODONE==1);
x=ADRESL; //store low byte
x=x>>1;	//shift 1 bit to the right
y=ADRESH;	//store high byte
y=y<<7;	//shift left 7 bit position
z=x|y; //combine together
LEDS=~z; //output on leds
}
}

void delay(unsigned char itime)
{
unsigned char i,j;
for(i=0;i<itime;i++)
for(j=0;j<1;j++);
}
 
I have already done an 8 bit mode adc but would like to change it to 10 bit. How can this code be altered to make it a 10 bit?
Doesn't the ADC work in 10 bit mode only?

Also, why are you shifting the x & y values in your code - to remove the bottom & top bits?

The following simple code should get the full 10 bits into the z var:
Code:
z = ADRESL | (ADRESH<<8);
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top