Multiple adc channel interrupt problem, LPC1768

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

Multiple adc channel interrupt problem, LPC1768

8,757 次查看
Alexshea
Contributor III

Hello everyone, I used to read temperatures of two LM35 sensors using adc. I used two channels and interrupt too. My code works fine when I read two channels and I want to add two more sensors and read temperatures of 4 LM35 sensors, however when I add channels in adc interrupt my code locks when adc read function is called. For example my adc channel 0 and channel 1 are active when I add if(ADC_ChannelGetStatus(LPC_ADC,ADC_CHANNEL_2,ADC_DATA_DONE)==0) in interrupt when adc_read() function is called the code stops and in debugger it stops moving forward and executing other lines of the code. I added my code and I hope I managed to explain my problem well enough. My chip is LPC1768.

Thanks in advance,

Alex

标签 (1)
0 项奖励
回复
8 回复数

8,673 次查看
Alexshea
Contributor III

@xiangjun_rong It seems like the code is stuck in adc interrupt when I have more than 2 channels

0 项奖励
回复

8,743 次查看
Alexshea
Contributor III

@xiangjun_rong What do you think? I remember once I had one adc and when I wanted to add another one had a similar problem and you helped me. Thought, I won't have any similar problem, since if it works with 2 channels, should work with 3 or more channels as well

0 项奖励
回复

8,660 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I will answer you at the end of the week, today, I am a bit busy.

BR

XiangJun Rong

8,643 次查看
Alexshea
Contributor III

@xiangjun_rong Hi, it's already Saturday! I was wondering if you check my code today or maybe tomorrow and by the way I need to work with all the 8 adc channels already not with 4 channels. Now I can work with 2 adcs and can't read other channels in adc interrupt

0 项奖励
回复

8,627 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Alex,

I do not use the Keil, I have checked the LPCOpen package, it appears that you do not use the lpcOpen package api function.

Because the conversion time is not a problem, you can use the polling mode as the following code. I suggest you disable all channel interrupt

I do not compile the code, pls have a try yourself.

BR

XiangJun Rong

 

//disable all channel interrupt

void HW_Init()
{
PINSEL_CFG_Type adcpinsel;
PINSEL_CFG_Type uartPinSel;
UART_CFG_Type uartConfig;


NVIC_SetPriorityGrouping(0x07);

adcpinsel.Funcnum=PINSEL_FUNC_1;
adcpinsel.OpenDrain=PINSEL_PINMODE_NORMAL;
adcpinsel.Pinmode=PINSEL_PINMODE_TRISTATE;
adcpinsel.Pinnum=24;
adcpinsel.Portnum=0;

PINSEL_ConfigPin(&adcpinsel);
adcpinsel.Pinnum=23;
PINSEL_ConfigPin(&adcpinsel);
adcpinsel.Pinnum=25;
PINSEL_ConfigPin(&adcpinsel);
//adcpinsel.Pinnum=26;
//PINSEL_ConfigPin(&adcpinsel);


ADC_Init(LPC_ADC,200000);

ADC_IntConfig(LPC_ADC,ADC_ADINTEN1,DISABLE);
ADC_IntConfig(LPC_ADC,ADC_ADINTEN0,DISABLE);
ADC_IntConfig(LPC_ADC,ADC_ADINTEN2,DISABLE);
ADC_IntConfig(LPC_ADC,ADC_ADINTEN3,DISABLE);
ADC_IntConfig(LPC_ADC,ADC_ADINTEN4,DISABLE);
ADC_IntConfig(LPC_ADC,ADC_ADINTEN5,DISABLE);
ADC_IntConfig(LPC_ADC,ADC_ADINTEN6,DISABLE);
ADC_IntConfig(LPC_ADC,ADC_ADINTEN7,DISABLE);
//ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_1,ENABLE);
//ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_0,ENABLE);
//ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_2,ENABLE);
//ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_3,ENABLE);


//NVIC_SetPriority(ADC_IRQn,NVIC_EncodePriority(0x07,0,1));
//NVIC_EnableIRQ(ADC_IRQn);

............

}

 

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,1<<channel_num,ENABLE);
ADC_StartCmd(LPC_ADC,ADC_START_NOW);
while(ADC_ChannelGetStatus(LPC_ADC,1<<channel_num,ADC_DATA_DONE)==0) {}
voltage=ADC_ChannelGetData(LPC_ADC,1<<channel_num);
return voltage;
}

8,600 次查看
Alexshea
Contributor III

@xiangjun_rong  Hi, I tried what you recommended now it works with 3 channels only. The moment I add adc0[3] the previous problem appears.It seems like the code is stuck at while(ADC_ChannelGetStatus(LPC_ADC,1<<channel_num,ADC_DATA_DONE)==0) {}. I've also noticed that the problem is with ADC0[3] and not the number of channels, since when I use this channel only the code gets stuck, whereas when channels 0,1,2 can work together without any problem when channel 3 isn't enabled.  I made the changes and added my code here again. I was wondering if you help me solve this problem

0 项奖励
回复

8,619 次查看
Alexshea
Contributor III

Hi, thank you very much for your recommendation. I'll try what you said and compile the code. Hope it helps. Interesting, haven't heard anything about lpcopen

0 项奖励
回复

8,658 次查看
Alexshea
Contributor III

Awesome! thank you so much. I'll wait for your answer

0 项奖励
回复