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

Problem with the analog ports in 18f14k50

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



Joined: 30 Sep 2011
Posts: 11

View user's profile Send private message

Problem with the analog ports in 18f14k50
PostPosted: Fri Sep 30, 2011 5:41 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Sep 30, 2011 6:25 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Sep 30, 2011 6:27 pm     Reply with quote

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

View user's profile Send private message

Update
PostPosted: Mon Oct 03, 2011 11:52 am     Reply with quote

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:

Code:
#fuses xt, nowdt


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

View user's profile Send private message

PostPosted: Mon Oct 03, 2011 12:55 pm     Reply with quote

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
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