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

What is the problem?

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







What is the problem?
PostPosted: Mon Jun 23, 2003 3:56 pm     Reply with quote

Hi,
I wrote a code and it worked well(related with adc).Now i upgraded my code for 16 bit adc and it behaves weird.

#include <16F877A.h>
#include <string.h>
#use delay(clock=4000000)
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)


void main() {

int v1;
char ON;

setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
set_tris_d(0x00);
ON = 1;

while (1)
{

delay_ms(500);

set_adc_channel( 0 );delay_us(50);v1 = read_adc();delay_us(50);
printf("Value:\%2X!",v1);

if (ON == 1) {output_high(PIN_D2);ON = 0;} else {output_low(PIN_D2);ON = 1;}

v1=0;
}

}
This works fine but when i load this, sometimes adc results shows different values than zero when no voltage on pin.When no voltage, it gives 64-128-96 (integer values). What is wrong? / Should i research fault in my circuit?

#include <16F877A.h>
#device adc=16 // !!! I Added tihs
#include <string.h>
#use delay(clock=4000000)
#fuses XT, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)


void main() {

int16 v1;
char ON;

setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
set_tris_d(0x00);
ON = 1;

while (1)
{

delay_ms(500);

set_adc_channel( 0 );delay_us(50);v1 = read_adc();delay_us(50);

printf("Value:\%4X!",v1);

if (ON == 1) {output_high(PIN_D2);ON = 0;} else {output_low(PIN_D2);ON = 1;}

v1=0;
}

}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515488
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: What is the problem?
PostPosted: Mon Jun 23, 2003 5:04 pm     Reply with quote

:=Hi,
:=I wrote a code and it worked well(related with adc).Now i upgraded my code for 16 bit adc and it behaves weird.
:=
---------------------------------------------------------
It's behaving pretty much according to the chart in the
CCS manual, in the read_adc() section. (Page 130 of the
manual, or page 142 in the Acrobat reader).

If you take a chip with a 10-bit ADC and set it for 16-bit
mode, CCS will left-justify the result. You don't like that,
so you need to set the compiler for 10-bit mode, which will
right-justify the result.

Remove this line:
#device adc=16

Use this line instead:
#device adc=10
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515491
No_Fear
Guest







Re: What is the problem?
PostPosted: Tue Jun 24, 2003 1:45 am     Reply with quote

Hmm, I can understand now.Thank you very much for your help

No_Fear


:=:=Hi,
:=:=I wrote a code and it worked well(related with adc).Now i upgraded my code for 16 bit adc and it behaves weird.
:=:=
:=---------------------------------------------------------
:=It's behaving pretty much according to the chart in the
:=CCS manual, in the read_adc() section. (Page 130 of the
:=manual, or page 142 in the Acrobat reader).
:=
:=If you take a chip with a 10-bit ADC and set it for 16-bit
:=mode, CCS will left-justify the result. You don't like that,
:=so you need to set the compiler for 10-bit mode, which will
:=right-justify the result.
:=
:=Remove this line:
:=#device adc=16
:=
:=Use this line instead:
:=#device adc=10
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515507
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