Some problem with ADC on MC9S08SH8

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Some problem with ADC on MC9S08SH8

2,920 Views
Gardo
Contributor I
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  
 
Labels (1)
0 Kudos
7 Replies

499 Views
Denn
Contributor I
Hello Gardo,
 
I have few questions.
1)Is  your Voltage Reference High (VREFH) source same as your Vdd source (any potential difference in between ??)  under question ?
2)Similarly Voltage Reference Low (VREFL) same as your Ground which you expect to be 0?
 
Any Voltage which is equal or greater than Voltage Reference High (VREFH) gives 1023(10 bit mode) or 255(8 bit mode).
 
Similarly Voltage equal to Voltage Reference Low (VREFL) yield 0000 .
 
 
Can you show us your MCU connections regarding VDD,VREFH,VDDAD,GND,VREFL and VSSAD?
 
 
Regards,
Denn.
0 Kudos

499 Views
fabio
Contributor IV
Hi Denn,

I think this is not the case because in the SH8, the VREFH and VDDAD are internally connected to VDD, the same is valid to VREFL and VSSAD, which are internally connected to VSS.

Best regards,
0 Kudos

499 Views
bigmac
Specialist III
Hello Gardo,
 
Did you correctly setup the APCTL1 register so as to disable GPIO operation on PTA0 and PTA2?
 
This does not affect your current problem, but the code might be simplied as follows -
 
bg_code = ADCR;
or
adc_T = ADCR;
 
There is no need to read the high and low registers separately to obtain the right-justified 10-bit result.
 
Regards,
Mac
 
0 Kudos

499 Views
fabio
Contributor IV
Hi Gardo,

Some comments:

1- Did you enabled the bandgap reference voltage ? This is done by the BGBE bit in SPMSC1 register.

2- You can read the ADC result using 16-bit variables, just write: Href_code = ADCR; or Lref_code = ADCR;

3- You will probably want do disable the digital input buffers on the pins operating in analog mode. You can do it setting the corresponding bit in APCTL1 register.

4- What is your ADC clock and sampling time? Maybe you are not sampling long enough.

Best regards,
0 Kudos

499 Views
Gardo
Contributor I
Hi  Fabio, I answer to your question:
 
1- Did you enabled the bandgap reference voltage ? This is done by the BGBE bit in SPMSC1 register.
 
Yes, I enable the Bandgap buffer
SPMSC1 = 0x1D; // BGBE = 1 from datasheet pag 121   Bandgap buffer enable
 
2- You can read the ADC result using 16-bit variables, just write: Href_code = ADCR; or Lref_code = ADCR;
 
Thanks for this suggestion; I don't know this. I always used 2 variable to read separately H. and L. ADC data register.
A question. If I want to work in this way it's necessary that I define result data format 10 bit when I define ADC result data format?

3- You will probably want do disable the digital input buffers on the pins operating in analog mode. You can do it setting the corresponding bit in APCTL1 register.
 
Excuse me but I have confusione. If I use a pin with analog input for ADC, this pin must to be enable or disable ( APCTL1_ADPCpin = 0 or 1) for  I/O control ?


4- What is your ADC clock and sampling time? Maybe you are not sampling long enough.
 
To define clock time I use devices Initialization tool and I have: 1152 KHz for frequency and 37,87us. 
 
--------------------------------------------------------------------------------------------------------------------------------
 
I try to change pin (pin1:smileytongue:TA1 or pin2:smileytongue:TA2) to sample a generical voltage but the result is not right.
 
But I realize that the result of the ADC conversion is always the same. I read always the same with GND (I dont't read 0) or Vdd (I don't read 1023) or a generical voltage with an external power supply(I don't read the right voltage conversion).
Why?
 
Thanks in advance for your help.
Gardo
0 Kudos

499 Views
fabio
Contributor IV
Hi Gardo,

Gardo wrote:
 
2- You can read the ADC result using 16-bit variables, just write: Href_code = ADCR; or Lref_code = ADCR;
 
Thanks for this suggestion; I don't know this. I always used 2 variable to read separately H. and L. ADC data register.
A question. If I want to work in this way it's necessary that I define result data format 10 bit when I define ADC result data format?

No,  this is not necessary as the not used bits in ADCRH reads as all zeroes. Anyway, you can always  mask the result:  result  =  ADCR &  1023.

3- You will probably want do disable the digital input buffers on the pins operating in analog mode. You can do it setting the corresponding bit in APCTL1 register.
 
Excuse me but I have confusione. If I use a pin with analog input for ADC, this pin must to be enable or disable ( APCTL1_ADPCpin = 0 or 1) for  I/O control ?

The APCTL bits when set disable the digital input buffers. So, you must set the APCTL bits corresponding to you analog inputs.

4- What is your ADC clock and sampling time? Maybe you are not sampling long enough.
 
To define clock time I use devices Initialization tool and I have: 1152 KHz for frequency and 37,87us. 
 
--------------------------------------------------------------------------------------------------------------------------------
 
I try to change pin (pin1:smileytongue:TA1 or pin2:smileytongue:TA2) to sample a generical voltage but the result is not right.
 
But I realize that the result of the ADC conversion is always the same. I read always the same with GND (I dont't read 0) or Vdd (I don't read 1023) or a generical voltage with an external power supply(I don't read the right voltage conversion).
Why?
 
I have no clue. All I can say is that I have used the ADC on many HCS08 devices and none of them showed any problem. However, I never tried the SH8.


Best regards,
0 Kudos

499 Views
JimDon
Senior Contributor III
Well, what do you have connected to the pin?
What is the voltage reading on that pin?
Did you by any chance set that pin to some other function?

0 Kudos