#include "chip.h" #include <cr_section_macros.h> void SysTick_Handler(void) { LPC_GPIO_PORT->NOT[0] = (1<<15);// Toggle PIO0_15 Chip_ADC_StartSequencer(LPC_ADC, ADC_SEQA_IDX);// manual start for ADC conversion sequence A } int main(void) { uint32_t rawSample, ADC_result; Chip_SystemInit();// setup system clocking SystemCoreClockUpdate();// Read clock settings and update SystemCoreClock variable SysTick_Config(SystemCoreClock / 5);// Systick is reloading 1/5 of a second = 200ms... LPC_GPIO_PORT->DIR[0] |= (1<<15); // Set direction of PIO0_15 to output Chip_ADC_Init(LPC_ADC,0);// setup ADC 12-bit mode, normal power Chip_ADC_StartCalibration(LPC_ADC);// calibration after ADC initialization while (!(Chip_ADC_IsCalibrationDone(LPC_ADC))) {} Chip_ADC_SetClockRate(LPC_ADC, ADC_MAX_SAMPLE_RATE); Chip_ADC_SetupSequencer(LPC_ADC, ADC_SEQA_IDX, (ADC_SEQ_CTRL_CHANSEL(2) | ADC_SEQ_CTRL_MODE_EOS)); // setup SEQA, ADC_CH2 Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); // enable the clock to the switch matrix Chip_SWM_EnableFixedPin(SWM_FIXED_ADC2);// config the switch matrix for PIO0_14 as the input for ADC_2 Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM); // disable the clock to the switch matrix to save power Chip_ADC_EnableSequencer(LPC_ADC, ADC_SEQA_IDX);// enable sequencer while(1) { rawSample = Chip_ADC_GetDataReg(LPC_ADC, 2);// read ADC data register of ADC channel 2 ADC_result = (rawSample >> 4) & 0xFFF; // getting adc converted result from 4th to 15th bit of DR } return 0 ; } |