@xiangjun_rong Hello, now thanks to you my code works with all adc channels, however when I used interrupt I used a function to calculate the mid values of 200 samples of my sensors, but now I don't use adc interrupt and I don't know how can I use the function to calculate the mid value.
So as you can see I used to calculate the mid value when I used adc interrupt, but now I don't know how properly can I use calcTemp function. I once again added the intact project
Thanks in advance,
Alex
void calcTemp(uint16_t voltage, float temp) {
calcVolt=(volatge*3.6F)/4096;
temp=(calcVolt*1000.0F);
total+=temp;
countOfSum++;
if(countOfSum==200)
{
countOfSum=0;
realTemp=total/200.0F;
total=0;
flagOfTemp=1;
}
else
ADC_StartCmd(LPC_ADC,ADC_START_NOW);
}
void ADC_IRQHandler()
{
if(ADC_ChannelGetStatus(LPC_ADC,ADC_CHANNEL_0,ADC_DATA_DONE)==0)
{
float temp;
volatge=ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_0);
/*
3 4096
x volt
x=volt*3/4096
*/
calcTemp(volatge,temp);
}
if(ADC_ChannelGetStatus(LPC_ADC,ADC_CHANNEL_1,ADC_DATA_DONE)==0)
{
float temp;
volatge=ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_1);
calcTemp(volatge,temp);
}
}
Hi,
void main()
{
......................
Pls try to modify your code like:
#define TOTAL_AVERAGE_NUMBER 200
uint16_t uivoltage;
float temp, totalTemp;
//channel 0 average temperature
//uint16_t temp1=HW_ADC_Read(0);
totalTemp=0;
for (uint16_t i=0; i<TOTAL_AVERAGE_NUMBER; i++)
{
uivoltage=HW_ADC_Read(0);
temp=calcTemp(uivoltage);
totalTemp+=temp;
}
temp=totalTemp/TOTAL_AVERAGE_NUMBER; //the temp is the average temperature in float format.
//channel 1 average temperature
//uint16_t temp1=HW_ADC_Read(1);
totalTemp=0;
for (uint16_t i=0; i<TOTAL_AVERAGE_NUMBER; i++)
{
uivoltage=HW_ADC_Read(1);
temp=calcTemp(uivoltage);
totalTemp+=temp;
}
temp=totalTemp/TOTAL_AVERAGE_NUMBER; //the temp is the average temperature in float format.
.........
}
float calcTemp(uint16_t voltage)
{
float temp;
temp=(volatge*3.6F)/4.096;
return temp;
}
Hope it can help you
BR
XiangJun Rong
@xiangjun_rong Hi, I used the code that you recommended, but it doesn't work and I don't receive any temperature. Could you please check the code once again. I added the whole project as you asked
Thank you so much. Will try that