1 #include <lpc21xx.h> // LPC21XX Peripheral Registers
7 #define ADCCH0 22 ///< ADC0 value for PINSEL
8 #define ADCCH1 24 ///< ADC1 value for PINSEL
9 #define ADCCH2 26 ///< ADC2 value for PINSEL
10 #define ADCCH3 28 ///< ADC3 value for PINSEL
13 * ADC ISR routine. This routine reads selected ADC value and
14 * multiplies it by #ADC_MUL and adds #ADC_OFFSET to calculate the
15 * volage (3.25mV/div). After this reading the next ADC channel is
16 * set up for measuring.
18 void adc_isr(void) __attribute__ ((interrupt));
21 unsigned char chan =0;
25 chan = (char) ((ADDR>>24) & 0x07);
26 val = (((((ADDR >> 6) & 0x3FF) * ADC_MUL + ADC_OFFSET) + adc_val[chan]) >> 1) ;
32 ADCR &= ~(ADC_CR_START_OFF_m);
38 ADCR = ((ADC_CR_ADC1_m) | (ADC_CR_CLKS_11_m) | (ADC_CR_PDN_ON_m) | (ADC_CR_START_NOW_m) | (20*ADC_CR_CLK_DIV_1_m));
42 ADCR = ((ADC_CR_ADC2_m) | (ADC_CR_CLKS_11_m) | (ADC_CR_PDN_ON_m) | (ADC_CR_START_NOW_m) | (20*ADC_CR_CLK_DIV_1_m));
46 ADCR = ((ADC_CR_ADC3_m) | (ADC_CR_CLKS_11_m) | (ADC_CR_PDN_ON_m) | (ADC_CR_START_NOW_m) | (20*ADC_CR_CLK_DIV_1_m));
50 ADCR = ((ADC_CR_ADC0_m) | (ADC_CR_CLKS_11_m) | (ADC_CR_PDN_ON_m) | (ADC_CR_START_NOW_m) | (20*ADC_CR_CLK_DIV_1_m));
59 * Inicializes ADC service for all ADC (4) channels and installs ISR routine to VIC.
60 * Automaticly starts the conversion of first channel on given conversion frequency.
62 void init_adc(unsigned rx_isr_vect)
65 PINSEL1 |= ((PINSEL_1 << ADCCH0) | (PINSEL_1 << ADCCH1) | (PINSEL_1 << ADCCH2) | (PINSEL_1 << ADCCH3));
67 ((uint32_t*)&VICVectCntl0)[rx_isr_vect] = 0x32;
68 ((uint32_t*)&VICVectAddr0)[rx_isr_vect] = (unsigned) adc_isr;
69 VICIntEnable = 0x40000;
71 ADCR = ((ADC_CR_ADC0_m) | (ADC_CR_CLKS_11_m) | (ADC_CR_PDN_ON_m) | (ADC_CR_START_NOW_m) | (ADC_VPB_DIV*ADC_CR_CLK_DIV_1_m));