AnsweredAssumed Answered

ADuC7061 - right way to channel switching

Question asked by Dimion on Mar 2, 2011
Latest reply on Mar 7, 2011 by MikeL

Hello!

I'm want to measure 4 channels at secondary ADC and one channel at first ADC. Right now I switching channels for secondary ADC after ADC1 ready flag is set. But it looks like this method is change ADC0 measuring period. Please look at source bellow. Question - what is right way to switch channel at secondary ADC?

 

void    adc_init(void) {

    unsigned int    temp;

 

    // common settings for ADC0 and ADC1:

    ADCFLT = 0x0003;                                            // Chop off, 2Khz samping rate, SF = 3.    No averaging

    //ADCMDE = 0x0080 | 0x0003;                            // 512KHz clock source to ADC, Idle mode

    ADCMDE = 0x0080 | 0x0000;                            // 512KHz clock source to ADC, Power down

 

    // Configure ADC1 for continuous conversions

    ADC1CON =                                                        //Internal reference Gain = 1

        0x0400 | 0x0100 |                                    // bits{10:7} = [1010] = ADC9/ADC5 (single-ended mode).

        0x8000;                                                        // Enable Auxiliary ADC

 

    // Configure ADC0 for continuous conversions

    ADC0CON =                                                        //Internal reference Gain = 1

        0x0140 |                                                    // bits{9:6} = [0101] = ADC2/ADC3 (differential mode)

        0x8000;                                                        // Enable Primary ADC

 

    ADCCFG = 0;

 

    //ADCMSKI    = 0x0001 | 0x0002;                    // Enable ADC0 and ADC1 result ready interrupt source

    FIQEN     |= 0x0400;                                    // Enable ADC interrupt

 

    // Start ADCs

    temp = ADC1DAT;

    temp = ADC0DAT;                                            // Read ADC0DAT, clear both ADCSTA.0 and ADCSTA.1 bits

    ADCMDE = 0x0001 | 0x0080;                        // Continious Conversion mode, 512KHz clock source to ADC.

 

    ADCMSKI    = 0x0001 | 0x0002;                    // Enable ADC0 and ADC1 result ready interrupt source

};

 

__arm void fiq_handler(void){
    static    unsigned int    adc1_ch = 0;
    const        unsigned int    adc1_channels[] = {(0x04<<7), (0x05<<7), (0x06<<7)};
    int    temp, have_ch1 =0;
   
    /* Check for ADC interrupt */
    if((FIQSTA & 0x0400) == 0) {       // Read  IRQSTA register and check for valid mask
    //    debug_pin_0_set();
        return;
    }
   
    switch(ADCSTA & 0x0003){
        case    0x0003:                            // Check for ADC1 and ADC0 ready
            debug_pin_1_togle();
            debug_pin_0_togle();
            temp = ADC1DAT;
            have_ch1 =1;
            break;
        case    0x0002:                            // Check for ADC1 ready
            debug_pin_0_togle();
            temp = ADC1DAT;
            have_ch1 =1;
            break;
        case    0x0001:                         // Check for ADC0 ready
            debug_pin_1_togle();
            break;
    }
   
    temp = ADC0DAT;                                    // Read ADC0DAT, clear both ADCSTA.0 and ADCSTA.1 bits
    // Change channel
    if(have_ch1) {
        temp = ADC1CON;
        ADC1CON = (temp & (~(0x0FU<<7)) | adc1_channels[++adc1_ch]);
        if(adc1_ch == 2)
            adc1_ch = 0;
    }
    return;
};

Outcomes