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...
Hello,
It is unclear to me why your functions might be "static".
While it will do no harm, the writing of the value 0x1F to ADCSC1 after each conversion is probably unnecessary since the ADC should automatically enter a lower power mode on completion of each conversion.
For your wait loop, the following code would suffice -
while (!ADCSC1_COCO);
Regards,
Mac
Hi big mac ^^
Ty for this answer.
I hadn't see that it go to low power after each conversion....
In addition, you write "should" (scuse i'm french ^^).
To be sure that it stop, i prefer write 0x1F to disable ADC...
TY ^^