Marco Facchini

Some problem with ADC on MC9S08SH8

Discussion created by Marco Facchini on Apr 1, 2008
Latest reply on Apr 8, 2008 by Fabio Pereira
Hi,
I'm Gardo a new entry in this forum. I work with a 8bit MCU MC9S08SH8.
I've some problem with internal ADC for MCU.
I want measure ambient temperature with MCU. In the first step of my project I try to use internal temperature sensor but I've not enough accuracy so I try to use an external temp. sensor ( TC1047A) and I measure its analog output .
With this sensor I work so good ( I read 146 = 0.727 V = > 23°C )  but at the same time if  I measure Power Supply of my devices I want to see Vdd=5V=1023 because I use internal ADC with 10 bit; instead I read less ( about 931 = 4,64V).
My code is:
 
 
void main(void) {
MCU_init(); /* call Device Initialization */
 
  ADCSC1_ADCH = 0x1D;        // set reading channel 29 high reference (this is right 1023)
  while(!ADCSC1_COCO);      //  ADC conversion complete? 
  b_h = ADCRH;
  b_l = ADCRL;
  Href_code += b_l;
  Href_code += b_h * 256;    // shift  8 step
 
  ADCSC1_ADCH = 0x1E;       // set reading channel 30 low reference (this is right 0)
  while(!ADCSC1_COCO);      // ADC conversion complete?
  b_h = ADCRH;
  b_l = ADCRL;
  Lref_code += b_l;
  Lref_code += b_h * 256;     // shift  8 step
  
  ADCSC1_ADCH = 0x1B;        // set reading channel 27 Bandgap voltage 
  while(!ADCSC1_COCO);       // ADC conversion complete?
  b_h = ADCRH;
  b_l = ADCRL;
  Bg_code += b_l;
  Bg_code += b_h * 256;      // shift  8 step
  
  //   Bandgape voltage is right about 1,2V
  
  Vdd = 12276 / Bg_code;      //    ( 1023 * 1,2 * 10 ) / ADC bg  = 10 * Vdd
  
  ADCSC1_ADCH = 0x00;       // set rading channel 00 = PTA0 with Temp. sensor 
  while(ADCSC2_ADACT);
  while(!ADCSC1_COCO);      // ADC conversion complete?
  b_h = ADCRH;
  b_l = ADCRL;
  adc_T += b_l;
  adc_T += b_h * 256;        // reading on channel 00 is right ( about 146 = 27°C)
    
  ADCSC1_ADCH = 0x02;       // set rading channel 02 = PTA0 with Vdd = 5V
   while(ADCSC2_ADACT);
  while(!ADCSC1_COCO);      // ADC conversion complete?
  b_h = ADCRH;
  b_l = ADCRL;
 
  adc_V += b_l;
  adc_V += b_h * 256;
  
 
 On this reading I have to obtain adc_T = 1023 instead I have more less, about 930 . 
 
WHY??
 
Someone can help me?
Thanks in advance.
 
Gardo  
 

Outcomes