/**
* Init ADC1 to perform periodical reads on channels 0 and 1, whith threshold detection
*/
void ADC1_init( void )
{
/* --- ADC Init --- */
/* Setup ADC for 12-bit mode and normal power */
Chip_ADC_Init(ADC, 0);
/* Setup for maximum ADC clock rate */
Chip_ADC_SetClockRate(ADC, ADC_MAX_SAMPLE_RATE);
/* For ADC1, sequencer A will be used with threshold events.
It will run continuously in burst mode and will monitor the CH0 & CH1 input. */
Chip_ADC_SetupSequencer(ADC, ADC_SEQA_IDX,(ADC_SEQ_CTRL_CHANSEL(ADC1_VBUS_CH) |
ADC_SEQ_CTRL_CHANSEL(ADC1_IBUS_CH) |
ADC_SEQ_CTRL_BURST |
ADC_SEQ_CTRL_MODE_EOS));
/* Need to do a calibration after initialization and trim */
Chip_ADC_StartCalibration(ADC);
while (!(Chip_ADC_IsCalibrationDone(ADC))) {}
/* ACD clock must be set after calibration !! (bug in lib) */
Chip_ADC_SetClockRate(ADC, ADC_MAX_SAMPLE_RATE);
/* setup thresholds so that they are never crossed.
* They will be set by application, through ADC1_set_thr(...)
*/
// ch 0
Chip_ADC_SelectTH0Channels(ADC, ADC_SEQ_CTRL_CHANSEL(ADC1_VBUS_CH));
Chip_ADC_SetThrLowValue(ADC, 0, 0x000);
Chip_ADC_SetThrHighValue(ADC, 0, 0xFFF);
// ch 1
Chip_ADC_SelectTH1Channels(ADC, ADC_SEQ_CTRL_CHANSEL(ADC1_IBUS_CH));
Chip_ADC_SetThrLowValue(ADC, 1, 0x000);
Chip_ADC_SetThrHighValue(ADC, 1, 0xFFF);
/* Clear all pending interrupts */
Chip_ADC_ClearFlags(ADC, Chip_ADC_GetFlags(ADC));
/* Enable sequence A completion and threshold crossing interrupts for ADC1_0 and ADC 1_1 */
Chip_ADC_EnableInt(ADC, ADC_INTEN_CMP_ENABLE(ADC_INTEN_CMP_CROSSTH, ADC1_VBUS_CH) |
ADC_INTEN_CMP_ENABLE(ADC_INTEN_CMP_CROSSTH, ADC1_IBUS_CH) |
ADC_INTEN_SEQA_ENABLE);
Chip_ADC_SetThresholdInt(ADC, ADC1_VBUS_CH, ADC_INTEN_THCMP_CROSSING);
Chip_ADC_SetThresholdInt(ADC, ADC1_IBUS_CH, ADC_INTEN_THCMP_CROSSING);
// DO NOT ACTIVATE NVIC (for dma operation)
//_NVIC_ClearEnableIRQ(ADC1_SEQA_IRQn);
/* Enable sequencers */
Chip_ADC_EnableSequencer(ADC, ADC_SEQA_IDX);
}
/**
* ADC Mux PIN enable
*/
void ADC1_init_PinMux( void )
{
/* Disables pullups/pulldowns and disable digital mode */
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 9, (IOCON_MODE_INACT | IOCON_ADMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 32+1, (IOCON_MODE_INACT | IOCON_ADMODE_EN));
/* Assign ADC1_1 to PIO0_9 via SWM (fixed pin) */
Chip_SWM_EnableFixedPin(SWM_FIXED_ADC1_0);/*!< ADC0_0 fixed pin enable/disable on pin P1_1 */
Chip_SWM_EnableFixedPin(SWM_FIXED_ADC1_1);/*!< ADC0_1 fixed pin enable/disable on pin P0_9 */
}
|