11 years, 10 months ago.

MODDMA DAC and burst ADC

Hello, I would like to sample on two channels with mbed ADC the signal generated by this example http://mbed.org/users/AjK/code/MODDMA/file/cb10aec6feb1/example4.h therefore I added the following code:

int res[4004];
volatile int sc =0;
extern "C" void ADC_IRQHandler(void) __irq {
    uint32_t trash __attribute__((unused));
    switch(LPC_ADC->ADSTAT & 0xFF) {
        case 0x01:
            res[sc++] = LPC_ADC->ADDR0;
            led1=1;
            break;
        case 0x02:
            res[sc++] = LPC_ADC->ADDR1;
            led2=1;
            break;
        default: // Shouldn't happen but just in case handle unrecognised channel
            led3=1;
            trash = LPC_ADC->ADDR2;trash = LPC_ADC->ADDR3;trash = LPC_ADC->ADDR4;trash = LPC_ADC->ADDR5;trash = LPC_ADC->ADDR6;trash = LPC_ADC->ADDR7;
            break;
    }
}
int main() {
//...
//MODDMA DAC code
//...
// Power up the ADC and set PCLK
    LPC_SC->PCONP    |=  (1UL << 12);
    LPC_SC->PCLKSEL0 &= ~(3UL << 24); // PCLK = CCLK/4 96M/4 = 24MHz
    
    //LPC_ADC->ADCR  = (1UL << 21) | (1UL << 8) | (3UL << 0); 
    LPC_ADC->ADCR  = (3 << 0) | (1 <<  8) | (1 << 16) | (1 << 21) | (0 << 24);
    
    LPC_PINCON->PINSEL1 &= ~(3UL << 14);  /* P0.23, Mbed p15. */
    LPC_PINCON->PINSEL1 |=  (1UL << 14);
    LPC_PINCON->PINSEL1 &= ~(3UL << 16);  /* P0.24, Mbed p16. */
    LPC_PINCON->PINSEL1 |=  (1UL << 16);
    
    NVIC_SetVector(ADC_IRQn, (uint32_t)&ADC_IRQHandler);
    LPC_ADC->ADINTEN = 3;
    NVIC_EnableIRQ(ADC_IRQn);
    
    while (1) {    
        if (sc==4000) {NVIC_DisableIRQ(ADC_IRQn);break;}
    }
}

If I sample an external signal (with MODDMA DAC disabled) everything works OK: LED1 and LED2 turn on, LED3 remains OFF and program exits from the main loop... however... if I try to sample mbed's DAC with MODDMA DAC enabled the above code doesn't work (LED1, LED2 and LED3 turn ON and the program doesn't exit the main loop... Am I missing something? Is burst mode ADC supposed to work with MODDMA DAC?

Be the first to answer this question.