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
Solved! Go to Solution.
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
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
@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
@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.
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
Thank you, it worked