Francois DUGUE

ADC on MC9S08 : 8bits; Hight speed; single conversion

Discussion created by Francois DUGUE on Apr 22, 2010
Latest reply on Apr 24, 2010 by Francois DUGUE

Hi all i'll try to do this way. Could you confirm that this work?

 

First, i made an init:

 

 

static void adc_init(void)   {#ifndef FAKEDEV   APCTL1 = 0x0F ;  // Desable buffers I/O  for pins:   APCTL2 = 0x8F ;  // ADP 0->3;8->11;15;16->19; et 21->23   APCTL3 = 0xEF ;  // Pin PORT A;B and C   ADCSC2 = 0x00 ;  //raz & config reg SC2 . Start convertion by write on ADCSC1;   ADCCV  = 0x00 ;   //No save of compared value   ADCCFG = 0x00 ;  //Full power (hight speed)                    //Clock divide by 1                    //Standard sampling time (3.5 adc clocks)                    //8 bits operations                    //Bus clk selected   ADCSC1 = 0x1F ;  //Clear Flag conversion Complet (COCO)                    //NO Interrupt                    //Single conversion Mode                    //ADC DISABLE => ADCH = 11111;#endif   }

 

 

during my program, i call a simple function with channel parameter "voie"

 

 

static U8 adc_lecture(U8 voie)   {   U8 value = 0 ; //U8 is define as unsigned char#ifndef FAKEDEV   ADCSC1 = voie ;   while (! ADCSC1_COCO)      {      ;      }   value = ADCRL;   ADCSC1 = 0x1F ;#endif   return value ;   }

 

 

Do you think it's a good way?

ty in advance...

Outcomes