//initialize HSADC Clock
hsadc_init();
/* Show the actual HSADC clock rate */
freqHSADC = Chip_HSADC_GetBaseClockRate(LPC_ADCHS);
DEBUGOUT("HSADC sampling rate = %dKHz\r\n\n\n", freqHSADC / 1000);
//disable attenuator on AI_1
SET_PIN(PIN_ATT_AI1_5K,0);
SET_PIN(PIN_ATT_AI1_10K,0);
//Reset all Interrupts
NVIC_DisableIRQ(ADCHS_IRQn);
LPC_ADCHS->INTS[0].CLR_EN = 0x7f; // disable Interrupt0
LPC_ADCHS->INTS[0].CLR_STAT = 0x7f; // clear Interrupt-Status
while(LPC_ADCHS->INTS[0].STATUS & 0x7d); // wait for status to clear, have to exclude FIFO_EMPTY (bit 1)
LPC_ADCHS->INTS[1].CLR_EN = 0x7f;
LPC_ADCHS->INTS[1].CLR_STAT = 0x7f;
while(LPC_ADCHS->INTS[1].STATUS & 0x7d); // wait for status to clear, have to exclude FIFO_EMPTY (bit 1)
// Make sure the HSADC is not powered down
LPC_ADCHS->POWER_DOWN = (0<<0); /* PD_CTRL: 0=disable power down, 1=enable power down */
// Clear FIFO
LPC_ADCHS->FLUSH = 1;
// FIFO Settings 0= 1 sample packed into 32 bit, 1= 2 samples packed into 32 bit */
LPC_ADCHS->FIFO_CFG =
(0x0<<0) | /* UNPACKED */
(0x8<<1); /* FIFO_LEVEL */
LPC_ADCHS->DSCR_STS =
(0<<0) | /* ACT_TABLE: 0=table 0 is active, 1=table 1 is active */
(0<<1); /* ACT_DESCRIPTOR: ID of the descriptor that is active */
// Select both positive and negative DC biasing for input 2
Chip_HSADC_SetACDCBias(LPC_ADCHS, 2, HSADC_CHANNEL_DCBIAS, HSADC_CHANNEL_NODCBIAS);
LPC_ADCHS->THR[0] = 0x000 << 0 | 0xFFF << 16;//Default
LPC_ADCHS->THR[1] = 0x000 << 0 | 0xFFF << 16;//Default
LPC_ADCHS->CONFIG = /* configuration register */
(1<<0) | /* TRIGGER_MASK: 0=triggers off, 1=SW trigger, 2=EXT trigger, 3=both triggers */
(0<<2) | /* TRIGGER_MODE: 0=rising, 1=falling, 2=low, 3=high external trigger */
(0<<4) | /* TRIGGER_SYNC: 0=no sync, 1=sync external trigger input */
(0<<5) | /* CHANNEL_ID_EN: 0=don't add, 1=add channel id to FIFO output data */
(0x90<<6); /* RECOVERY_TIME: ADC recovery time from power down, default is 0x90 */
/* Setup data format for 2's complement and update clock settings. This function
should be called whenever a clock change is made to the HSADC */
Chip_HSADC_SetPowerSpeed(LPC_ADCHS, false);
LPC_ADCHS->DESCRIPTOR[0][0] =
(2<<0) | /* CHANNEL_NR: 0=convert input 0, 1=convert input 1, ..., 5=convert input 5 */
(0<<3) | /* HALT: 0=continue with next descriptor after this one, 1=halt after this and restart at a new trigger */
(0<4) | /* INTERRUPT: 1=raise interrupt when ADC result is available */
(0<<5) | /* POWER_DOWN: 1=power down after this conversion */
(1<<6) | /* BRANCH: 0=continue with next descriptor (wraps around after top) */
/* 1=branch to the first descriptor in this table */
/* 2=swap tables and branch to the first descriptor of the new table */
/* 3=reserved (do not store sample). continue with next descriptor (wraps around the top) */
(0x95<<8) | /* MATCH_VALUE: Evaluate this descriptor when descriptor timer value is equal to match value */
(0<<22) | /* THRESHOLD_SEL: 0=no comparison, 1=THR_A, 2=THR_B */
(1<<24) | /* RESET_TIME: 1=reset descriptor timer */
(0<<31); /* UPDATE_TABLE: 1=update table with all 8 descriptors of this table */
//Enable HSADC power
Chip_HSADC_EnablePower(LPC_ADCHS);
// Enable interrupts
NVIC_EnableIRQ(ADCHS_IRQn);
Chip_HSADC_UpdateDescTable(LPC_ADCHS, 0);
//clear interrupt stats
Chip_HSADC_ClearIntStatus(LPC_ADCHS, 0, Chip_HSADC_GetEnabledInts(LPC_ADCHS, 0));
Chip_HSADC_EnableInts(LPC_ADCHS, 0 ,(HSADC_INT0_DSCR_DONE | HSADC_INT0_FIFO_FULL));
//start HSADC
Chip_HSADC_SWTrigger(LPC_ADCHS);
|