reading 8 channel adc, LPC1768, CMSIS

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

reading 8 channel adc, LPC1768, CMSIS

Jump to solution
2,186 Views
Alexshea
Contributor III

Hello everyone, I'm trying to read 8 adc channels, but I can only read 3 channels and the moment I add the 4th channel the code locks and stops and other lines don't implement the moment read_adc function is called and I don't recieve any data from any of the channels. I added my code here. 

Thanks in advance,

Alex

@xiangjun_rong 

Labels (1)
0 Kudos
1 Solution
2,127 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I have downloaded the all project, and checked the code, I think you can change the code like:

uint16_t HW_ADC_Read(uint8_t channel_num)
{
uint16_t voltage;
//disable all channels
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_0,DISABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_1,DISABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_2,DISABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_3,DISABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_4,DISABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_5,DISABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_6,DISABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_7,DISABLE);
//enable the sampled channel
ADC_ChannelCmd(LPC_ADC,channel_num,ENABLE);
ADC_StartCmd(LPC_ADC,ADC_START_NOW);
while(ADC_ChannelGetStatus(LPC_ADC,channel_num,ADC_DATA_DONE)!=SET) {}
voltage=ADC_ChannelGetData(LPC_ADC,channel_num);
calcVolt=(voltage*3.6F)/4096;
temp=(calcVolt*1000.0F);

return voltage;
}

Pls have a try.

I am sorry for the delay. Previously, I could not see the api function body, I guess the body, so there was error in the code.

BR

XiangJun Rong

View solution in original post

0 Kudos
5 Replies
2,180 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Alex,

I hope you can provide us the intact project so that we can know all the api function definition. Your api function does not appear from LPCOpen package, where did you get it.

BR

XiangJun Rong

2,136 Views
Alexshea
Contributor III

@xiangjun_rong I uploaded the intact project. Does it help to figure out what is the problem? I was wondering if you check the project and help me solve this problem.

BR,

Alex

0 Kudos
2,171 Views
Alexshea
Contributor III

@xiangjun_rong Hi, here is the intact project. I use keil and don't know much about LPCopen and the api that isn't in the code.

0 Kudos
2,128 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I have downloaded the all project, and checked the code, I think you can change the code like:

uint16_t HW_ADC_Read(uint8_t channel_num)
{
uint16_t voltage;
//disable all channels
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_0,DISABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_1,DISABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_2,DISABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_3,DISABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_4,DISABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_5,DISABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_6,DISABLE);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_7,DISABLE);
//enable the sampled channel
ADC_ChannelCmd(LPC_ADC,channel_num,ENABLE);
ADC_StartCmd(LPC_ADC,ADC_START_NOW);
while(ADC_ChannelGetStatus(LPC_ADC,channel_num,ADC_DATA_DONE)!=SET) {}
voltage=ADC_ChannelGetData(LPC_ADC,channel_num);
calcVolt=(voltage*3.6F)/4096;
temp=(calcVolt*1000.0F);

return voltage;
}

Pls have a try.

I am sorry for the delay. Previously, I could not see the api function body, I guess the body, so there was error in the code.

BR

XiangJun Rong

0 Kudos
2,104 Views
Alexshea
Contributor III

Thank you, it worked

0 Kudos