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

Need help on ADC Voltage Reference?

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



Joined: 07 Sep 2003
Posts: 51

View user's profile Send private message Yahoo Messenger

Need help on ADC Voltage Reference?
PostPosted: Wed Feb 18, 2004 10:29 pm     Reply with quote

Mabuhay!

I need your help with my code below... I use an external reference for my ADC at AN3 of the PIC18F452 (pin #5). I attach a 5V power supply to AN3 that will act as a reference voltage for my ADC and another 5V power supply for my main power of the entire circuits.

My concern is... is that my ADC doesn't capture any data but when I use only one(1) power supply with ADC reference to VDD, my ADC works.

I need your comments please.

Thanx

The Code:
Code:

/////////////////////////////////////
//  Interrupt Service Routines     //
/////////////////////////////////////
/*
 The data sheet says there must be a delay of 2 x Tad
 after a conversion. Since we're using a Tad of 3.2 usec,
 this delay must be 2 x 3.2 = 6.4 usec. But we know that the
 CCS interrupt handler takes at least that long to go in
 and out of this interrupt routine (with our 20 MHz crystal),
 so we don't need to put in a line of code to do the delay.
*/
#int_ad  // ADC interrupt service routine
void adc_isr()
{
   // read the 10-bit ADC result
   gi16ADCresult = read_adc(ADC_READ_ONLY);

   glADCdone = 1;       // ADC conversion complete
}

/////////////////////////////////////
//  End Interrupt Service Routines //
/////////////////////////////////////

///////////////////////////////////
//  MCU Initialization Routines  //
///////////////////////////////////

//************************************************************************
void init_chip() {   // Initialize the MCU Chip

   lcd_init();       // LCD should be initialized first
   delay_ms(100);
   lcd_init();       // Init LCD again, coz sometimes can't initialize LCD
   delay_ms(100);
   lcd_init();       // Once more, to be sure LCD gets initialized

   setup_adc_ports(RA0_RA1_ANALOG_RA3_REF);   // setup the ADC analog pins
   // with a 20MHz clock, we divide the oscillator by 64
   // to get an ADC clock of 312.5KHz, so Tad=3.2usec
   setup_adc(ADC_CLOCK_DIV_64);  // configure the ADC clock to 3.2usec
   set_adc_channel(0);  // specify ADC channel to use (PortA0)

   // the default is to right justify
   enable_interrupts(int_ad);    // enable ADC interrupt
   enable_interrupts(global);    // enable global interrupt
}

///////////////////////////////////
//End MCU Initialization Routines//
///////////////////////////////////


//************************************************************************
// Main Program
//************************************************************************
main()
{
   init_chip();      // Initialize the MCU Chip

   lcd_putc("\fADC Demo");

   gi16ADCresult = 0;   // initialize the ADC result variable to zero
   delay_us(20);        // wait for ADC aquisition time

   read_adc(ADC_START_ONLY);  // start an ADC conversion

   while (TRUE)
   {
      if (glADCdone) // ADC conversion completed
      {
         glADCdone = 0; // prevent multi-trigger of ADC conversion
         printf("ADC Result = %lx  ADC Steps = %lu\n\r",gi16ADCresult,gi16ADCresult);   // print the result
         // for demo purpose delay 1sec. for screen updating with
         // the new ADC result
         delay_ms(1000);
         read_adc(ADC_START_ONLY);  // start another ADC conversion
      }
   }
}

//************************************************************************
// End Program
//************************************************************************

Ttelmah
Guest







PostPosted: Thu Feb 19, 2004 6:08 am     Reply with quote

Obvious questions Have you checked with a voltmeter that you do have 5v on the reference pin when running with the seperate supply?. What is the source impedance of the second source?.

Best Wishes
ac9z



Joined: 03 Feb 2004
Posts: 2
Location: Wheeling, IL USA

View user's profile Send private message

PostPosted: Thu Feb 19, 2004 7:09 am     Reply with quote

If the ADC works with one supply and not both, the problem would appear to involve the dual supply. Are both supplies connected to the same ground? The grounds need to be tied together at one point.

Regards
_________________
Marty L
ac9z



Joined: 03 Feb 2004
Posts: 2
Location: Wheeling, IL USA

View user's profile Send private message

PostPosted: Thu Feb 19, 2004 7:09 am     Reply with quote

If the ADC works with one supply and not both, the problem would appear to involve the dual supply. Are both supplies connected to the same ground? The grounds need to be tied together at one point.

Regards
_________________
Marty L
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