reading 8 channel adc, LPC1768, CMSIS

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

reading 8 channel adc, LPC1768, CMSIS

ソリューションへジャンプ
2,262件の閲覧回数
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 解決策
2,203件の閲覧回数
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 返答(返信)
2,256件の閲覧回数
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,212件の閲覧回数
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 件の賞賛
2,247件の閲覧回数
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 件の賞賛
2,204件の閲覧回数
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 件の賞賛
2,180件の閲覧回数
Alexshea
Contributor III

Thank you, it worked

0 件の賞賛