CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

HELP on 16f877 ADC, MSB not changing

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
elijah



Joined: 30 May 2005
Posts: 0

View user's profile Send private message

HELP on 16f877 ADC, MSB not changing
PostPosted: Mon May 30, 2005 3:41 am     Reply with quote

Hello, I'm using the ADC of 16F877 and I set it to 10 bits.
I want to see what value pops out everytime I read the analog port, the problem is I cant somehow get the MPLAB ICD2 debugger to work on this chip so I decided to just convert the value into its binary equivalent and output it to another port..

The problem is the the MSB (the 10th bit) seems to be not changing whether the value is in the upper half of the analog input or the lower half of the analog input. For example: I'm inputting 0-5Volts in the analog pin.
so for ranges 5 to about 2.5 the MSB should be high, and for about 2.499 to 0 the MSB should be low..The problem is it isnt changing, its always high which means the value just repeats (5V = 2.4999V).

pls help me!!!!! THANKS

here is my code..sorry if it's too long


#include "D:\my files\shigoto\new upconverter\feedback test kiban\program\test.h"


void send(int16 index,unsigned int16 reg,unsigned int16 comp)
{
int counter,n;

output_low(PIN_D4); //CS low
delay_ms(1);
//output_low(PIN_A1); //FS low
//delay_ms(1);


for(n=0;n<index;n++)
{

output_high(PIN_D5); //clk high
delay_ms(2);

if((reg&comp)!=0) //bit 15
{
output_high(PIN_D7); //data high
}
else
{
output_low(PIN_D7); //data low
}

delay_ms(2);
output_low(PIN_D5); //clk low
delay_ms(4);
reg<<=1;
}

//output_high(PIN_A1); //FS high
delay_ms(1);
output_high(PIN_D4); //CS
output_low(PIN_D7); //data low


}



void main()
{
unsigned int16 value;


output_high(PIN_A1); //FS high
output_high(PIN_D4); //CS low
output_low(PIN_D5); //CLK low
output_low(PIN_D7); //data low

setup_adc_ports(A0);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);

value=0;
delay_ms(100);


while(1){


value = read_adc();
send(10,value,512); //10 bits
delay_ms(400);

}



}
Ttelmah
Guest







PostPosted: Mon May 30, 2005 5:10 am     Reply with quote

Couple of comments, without looking deeply:
1), what is 'A0' equal to. The value for 'setup_adc_ports' for AN0 as an input, is 'AN0' not 'A0' (or RA0, on a much older compiler version). If A0, does not equal the right value, the ADC, might be getting it's reference voltage from somewhere else, or be misconfigured in some other similar way.
2) What is the clock rate?. Using clock/8 to feed the ADC, implies your crystal should not be above 5Mhz.
3) What is the compiler version?. This is something that should always be included in this sort of question, because of known problems, and changes in the compiler.

Best Wishes
JohnKennedy



Joined: 12 May 2004
Posts: 38

View user's profile Send private message

PostPosted: Tue May 31, 2005 1:38 am     Reply with quote

I'm sure you have to add this line in your beginning of your program as the A/D defaults to 8 bit mode Exclamation Can't do any harm to try it

Code:
#device ADC=10


JFK
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group