|
|
View previous topic :: View next topic |
Author |
Message |
No_Fear Guest
|
What is the problem? |
Posted: Mon Jun 23, 2003 3:56 pm |
|
|
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
|
Re: What is the problem? |
Posted: Mon Jun 23, 2003 5:04 pm |
|
|
:=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? |
Posted: Tue Jun 24, 2003 1:45 am |
|
|
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 |
|
|
|
|
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
|