Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

A/D 10 bit conversion 16f877

Status
Not open for further replies.

maria258

Member level 2
Joined
Feb 10, 2011
Messages
42
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,577
I have already saw my code working with an 8 bit adc but i just dont know how to make it 10 bit. here is apart of my code that i tried to do for a 10 bit. i added PORTC for the extra 2 bits, now i want PORTB for ADRESH and PORTC for ADRESL but dont know how to combine them in z.

thanks
maria

Code:
TRISB=0x00; //output
 TRISC=0x00;    //output
 TRISA=0xFF;    //inputs
 LEDS_8=0xFF;    //clear/switch off LEDS
 LEDS_2=0xFF;    //clear/switch off LEDS

Code:
GODONE=1;
 //wait end-of-conversion (conversion complete)
 while(GODONE==1);
 x=ADRESL; //store low byte
 x=x;    //shift 1 bit to the right
 y=ADRESH;    //store high byte
 y=y<<8;    //shift left 7 bit position
 z=x|y; //combine together
 LEDS=~z; //output on leds
 

can you post the code what LEDS does?

and what does x=x does?
 
here is the full code:

Code:
#include<pic.h>

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

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
TRISC=0b00111111;	
TRISA=0xFF;	//inputs
LEDS_8=0xFF;	//clear/switch off LEDS
LEDS_2=0xFF;

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_8=~z;
}
}

void delay(unsigned char itime)
{
unsigned char i,j;
for(i=0;i<itime;i++)
for(j=0;j<1;j++);
}

as you can see it is oonly being shown on PORTB cos of LEDS_8.
 

Simply, you want to shift the whole 10-bit result, such that the 8 msb's are on PORTB and the 2 lsb's on PORTC.

So, I suggest you simply use a temporary variable for shifting it around,

Code:
x=ADRESL; //store low byte
temp = 0x03 & x; // separate the 2 lsb's
x >>= 2;     // removing 2 lsb's
y=ADRESH;	//store high byte
y <<= 6;	//shift left 6 bit position
PORTB =x|y; //combine together
PORTC.6 = 0x01 & temp;
PORTC.7 = 0x02 & temp;
 
i tried this your method but did not work. PORTC is showing nothing.
I decalred PORTC as 0b0011 1111 that is, the first two bits as output.
do you have any other method please?
i really appreciate your help and your time sir.

regards
maria
 

are you sure PORTC has to show something? I mean, its possible that the ADRESH maybe zero, so you wouldnt see anything for PORTC.

And first two bits of PORTC, you mean the teo most significant bits of the PORTC, right?
 
since i need it as a 10 bit ADC i need PORTC to show that a signal is getting in. and yes since i have set PORTC as 0b0011 1111 the signal should be on RC0 and RC1.
 

So simply change PORTC.6 and PORTC.7 to RC0 and RC1 in my code.

And I think you configured PORTC wrongly, as 0b0011 1111 would keep RC0 and RC1 as inputs.
It should be 0b1111 1100.
 
yes thank you. i did the wiring wrongly. thank you for your help and time. it was appreciated.

regards
maria
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top