Simon Bauernfeind

Stupid problem with ADC sampling

Discussion created by Simon Bauernfeind on Jul 15, 2010
Latest reply on Jul 19, 2010 by bigmac

Hello there,


I feel really like a noob, since I didn´t manage to get my HCS08DZ60 ADC running. I´m sure everythings set well, but

in debugging mode via PE micro dongle the COCO flag is never set. Here´s my Code. It would be great if someone can help me with that. Thank you guys in advance.


My init code:

 


void Adc_Init(void)
{

    /* ADCSC1: COCO=0,AIEN=0,ADCO=0,ADCH4=0,ADCH3=1,ADCH2=1,ADCH1=1,ADCH0=1 */
    /*setReg8(ADCSC1, 0x1F);               /* Disable the module */
    ADCSC1 = 0x1F;
    
    /* ADCSC2: ADACT=0,ADTRG=0,ACFE=0,ACFGT=0,??=0,??=0,??=0,??=0 */
    /*setReg8(ADCSC2, 0x00);               /* Disable HW trigger and autocompare */
    ADCSC2 = 0x00;
    
    /* ADCCFD: ADLCP=0,ADIV_h=,ADIV_l=,ADLSMP=0,MODE_h=,MODE_l=,ADICLK_h=,ADICLK_l= */
    /*setReg8(ADCCFG, 0x48);               /* Set prescaler bits */
    ADCCFG = 0x28;
    
    
    if( adc_driverStatus != STOP ) /* Set ADC to STOP mode if not set */
    {
        adc_driverStatus = STOP;
    }
    
    adc_driverInitialized = TRUE;    /* Set driver init status */
}

 

and here´s my polling function: 


Adc_ResultType Adc_Measure( Adc_ChannelType channel )
{
    volatile Adc_ResultType result = 0;

    unsigned int i; /* counter for ADC sample cycles */

   
    /* sampe ADC channels */
    for( i = 0; i < ADC_SAMPLE_CYCLES; i++)
    {
        ADCSC1 = channel;


        /* wait while conversion is in progress */
        while ( !(ADCSC1 & (1<<7) ) )
        {
            asm("nop");
        }

        /* make sum of ADC Register values */
        result += ( (ADCRH << 8) + ADCRL );
       
    }

   
    
    Adc_Stop();    /* stop ADC conversion by setting ADCSC1 = 0x1F */
    

    /* divide by number of samples for "low pass" filtering */
    return ( result >> ( ADC_SAMPLE_CYCLES >> 2 ) );
}

 

I´m really going crazy, since the ADCSC1 in hiwave shows a HI COCO bit when ADCSC1 is set with 0x01, but shows a LO COCO bit in the next step. ADACT flag in ADCSC2 never becomes 1.

 

Thank you guys.

 

Greets

 

Simon

Outcomes