View previous topic :: View next topic |
Author |
Message |
churrinfunflais
Joined: 30 Sep 2011 Posts: 11
|
Problem with the analog ports in 18f14k50 |
Posted: Fri Sep 30, 2011 5:41 pm |
|
|
Hello friends ...
I have a little problem with the analog channels of the PIC 18f14k50 especially C2 (AN6) and the ADCON0, when i simulate in the Isis i get these annoying infinite alerts:
Code: | (PIC18 ADC)PC=0X0164. Write to ADCON0 register selects ADC channel 0 - there is no such channel on the PIC 18f14k50 device.
(PIC18)PC=0x048 PORTC<2> is not configured as a analog input. |
is this line been ignored?
Code: | setup_adc_ports(ALL_ANALOG); |
I hope anyone can help.
here is the code i am using:
Code: | #include <18F14K50.h>
#device adc=8
#fuses xt, nowdt
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=pin_b7, rcv=pin_b5, bits=8)
int acelerometro() {
int valor, x, y, z;
set_adc_channel(11);
delay_ms(10);
x = read_adc();
set_adc_channel(10);
delay_ms(10);
y = read_adc();
set_adc_channel(6);
delay_ms(10);
z = read_adc();
if (z < x && z < y && z < 60) {
valor = 1;
} else if (z > x && z > y && z > 160) {
valor = 2;
} else if (x < y && x < z && x < 60) {
valor = 3;
} else if (x > y && x > z && x > 160) {
valor = 4;
} else if (y < x && y < z && y < 60) {
valor = 5;
} else if (y > x && y > z && y > 160) {
valor = 6;
} else {
valor = 0;
}
return (valor);
}
void main(void) {
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_vref(VREF_OFF);
int valor = 1;
int flag = 0;
while (TRUE) {
while (valor != 0) {
if (flag != 0) {
putc(170);
delay_ms(10);
while (TRUE) {
valor = acelerometro();
if (valor == 0)
break;
putc(valor);
delay_ms(10);
}
putc(171);
delay_ms(10);
} else {
flag = 1;
valor = acelerometro();
}
}
valor = acelerometro();
}
putc(valor);
} |
Here are some images of the errors I am having in the ISIS
http://www.todopic.com.ar/foros/index.php?action=dlattach;topic=36157.0;attach=16810;image
thanks for the help. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Sep 30, 2011 6:25 pm |
|
|
On a question about compiler behavior, always post your compiler version.
You can find the version at the top of the .LST file, which will be in your
project directory after a successful compilation. It's a 4-digit number
like these:
http://www.ccsinfo.com/devices.php?page=versioninfo |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Sep 30, 2011 6:27 pm |
|
|
OK, first off ISIS, is full of bugs, errors and terrible DRCs.
How about compiling the program and downloading it into a real PIC ?
What version of compiler are you using?
Have you read the PIC's datasheet about the ADC section ?
Be sure to add 'errors' to the use rs232(...) pre processor directive.
10ms delay before reading the ADC seems excessive and wasteful of cpu resources.
You only have 2 fuses selected, are you sure the defaults (whatever they are) are suitable for your application?
The link you supplied didn't work for me |
|
|
churrinfunflais
Joined: 30 Sep 2011 Posts: 11
|
Update |
Posted: Mon Oct 03, 2011 11:52 am |
|
|
Thanks for the comments,,,
I haven't test the code in a real PIC but is a great idea, also I'm going to check the fuses for what i need, where can i find help or documentation about the fuses, in the datasheet?? I always put these two:
About to add 'errors' to the use rs232(...) pre processor directive, how can i do these??
The version of the compiler i'm using is the latest "4.120 "
The version of the ISIS is the "7.7 sp2" |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Oct 03, 2011 12:55 pm |
|
|
I looked at the ADC setup code in your version and I don't think I see
anything wrong. My advice is to write a test program that only tests
ADC channel 6. Put a trimpot on the AN6 pin and turn it from 0v to 5v
and watch the output of the ADC. Check if it produces the correct
output values.
Here is an example of an ADC test program for one channel:
http://www.ccsinfo.com/forum/viewtopic.php?t=44709&start=11 |
|
|
|