reading 8 channel adc, LPC1768, CMSIS

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

reading 8 channel adc, LPC1768, CMSIS

跳至解决方案
5,830 次查看
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 

标签 (1)
0 项奖励
回复
1 解答
5,771 次查看
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 项奖励
回复
5 回复数
5,824 次查看
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

5,780 次查看
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 项奖励
回复
5,815 次查看
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 项奖励
回复
5,772 次查看
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 项奖励
回复
5,748 次查看
Alexshea
Contributor III

Thank you, it worked

0 项奖励
回复