lpcware

LPC11C24 ADC channels 5-7 not working

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by over9k on Fri Aug 28 08:29:43 MST 2015
I am writing a program for LPCXpresso LPC11C24 that uses ADC to measure 3 voltages. I want to use ADC channels 2, 3, 7. But channels 0-4 work properly while 5-7 behave in a weird way. Here are the results I get:


Chan | GND | 3,3V | Not Connected
0-4  |  0  | 1023 | ~200
5-7  |  0  | ~5   | 0


And I checked with an oscilloscope, the voltage is really 3,3V there when I measure it, so there is no unexpected drain during measurement. I also have the same problem with one other board, so it's unlikely to be a manufacturing error. I looked at the documentation and there was no hint about why channels 5-7 would be different from 0-4, but maybe I missed something.

Am I doing something wrong? How do I make it work?

Here is my code (I'm using LPCOpen libraries):



#include "board.h"

#include <cr_section_macros.h>

#include <string.h>
#include <stdlib.h>
#include <stdio.h>

static ADC_CLOCK_SETUP_T ADCSetup;
Status status;

int adc(char *param1){
uint8_t channel;
uint16_t dataADC = 0;

if(strcmp("2", param1) == 0){
channel = ADC_CH2;
}else if(strcmp("3", param1) == 0){
channel = ADC_CH3;
}else if(strcmp("7", param1) == 0){
channel = ADC_CH7;
}

Chip_ADC_EnableChannel(LPC_ADC, channel, ENABLE);

Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING);

/* Waiting for A/D conversion complete or timeout */
for (int i = 0; i < 500000; i++) {
if (Chip_ADC_ReadStatus(LPC_ADC, channel, ADC_DR_DONE_STAT) == SET) {
break;
}
}

status = Chip_ADC_ReadValue(LPC_ADC, channel, &dataADC);

Chip_ADC_EnableChannel(LPC_ADC, channel, DISABLE);

return (int)dataADC;
}

int main(void) {

SystemCoreClockUpdate();
Board_Init();

//Configuring ADC pins.
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO1_1, FUNC2); //ADC2
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO1_2, FUNC2); //ADC3
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO1_11, FUNC2); //ADC7

/* ADC Init */
Chip_ADC_Init(LPC_ADC, &ADCSetup);

int measurement2, measurement3, measurement7;
while(1){
measurement2 = adc("2"); //1023 at 3,3V, around 200 when not connected, 0 when connected to GND.
measurement3 = adc("3"); //1023 at 3,3V, around 200 when not connected, 0 when connected to GND.
measurement7 = adc("7"); //between 4 and 6 at 3,3V, 0 when not connected, 0 when connected to GND.
}//Debug breakpoint here to read the values.

return 0 ;
}

Outcomes