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 support@ccsinfo.com

18F6527 Internal A/D converters

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 20, 2006 12:30 pm     Reply with quote

Your test program is too complicated. Try this simple program
and see if it works.
Code:

#include <18F6527.h>
#device adc=10
#fuses HS, NOWDT, PUT ,BROWNOUT, NOLVP
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//===================================
void main()
{
int16 result;

setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
delay_us(20);

while(1)
  {
   result = read_adc(); 
   printf("%lx \n\r",result);
   delay_ms(500);
  }

}
Ttelmah
Guest







PostPosted: Mon Nov 20, 2006 3:30 pm     Reply with quote

You have a huge amount of stuff in your code, that has been remarked out. Remove this, and repost, _showing the declarations of the variables used to hold the ADC valuea_. Also use the 'code' buttons to post.
Also, consider using an array, or struture to allow the whole thing to be done with one loop. Something like:
Code:

structure values {
    int16 threeDC;
    int16 fiveVDC;
    int16 fiveVRef;
    int16 fortyeightVDC;
    int16 PPDDetect;
    int16 OpAmpPwr;
}

union {
    int16 readings[6];
    stucture values ADC;
} VIN;

void read_volts(void) {
    int8 ctr;
    for (ctr=0;ctr<7;ctr++) {
       set_adc_channel(ctr);
       delay_us(20);
       VIN.readings[ctr]=read_adc();
    }
}

//Then in your main:
while (true) {
    read_volts();
    printf("Three V line is at %d\n\r",VIN.ADC.threeDC);
    delay_ms(500);
}

Just showing how this would work for one value (but reading six).
A lot smaller, simpler to read etc. etc..

Best Wishes
bill conley
Guest







PostPosted: Mon Nov 20, 2006 9:17 pm     Reply with quote

Thanks Guys...I think I have it working. It wasn't the firmware, it was the hardware.

-
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