Knife
Member level 2
- Joined
- Apr 26, 2009
- Messages
- 43
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,288
- Activity points
- 1,593
Hi All
I want to read 2 channel ADC from ADC1 library. You can see my code below. I used scan mode and conversation mode single. I take 4 samples in interrupt and used average of them in my main code. My problem is sometimes ADC1_GetBufferValue(1) or ADC1_GetBufferValue(0) returns bigger than 1023. For example 20000, 40000 or something like that. Could you have any opinion for this issue ?
I want to read 2 channel ADC from ADC1 library. You can see my code below. I used scan mode and conversation mode single. I take 4 samples in interrupt and used average of them in my main code. My problem is sometimes ADC1_GetBufferValue(1) or ADC1_GetBufferValue(0) returns bigger than 1023. For example 20000, 40000 or something like that. Could you have any opinion for this issue ?
Code:
void ADC_Configuration(void)
{
ADC1_DeInit();
ADC1_Cmd(ENABLE);
ADC1_Init(ADC1_CONVERSIONMODE_SINGLE, ADC1_CHANNEL_1, ADC1_PRESSEL_FCPU_D18, \
ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_ALL, DISABLE);
ADC1_ScanModeCmd(ENABLE);
ADC1_ITConfig(ADC1_IT_EOCIE, ENABLE);
ADC1_DataBufferCmd(ENABLE);
ADC1_StartConversion();
}
Code:
INTERRUPT_HANDLER(ADC1_IRQHandler, 22)
{
ADC1_ClearITPendingBit(ADC1_IT_EOC);
//ADC1_ClearFlag(ADC1_FLAG_EOC);
wBATTERY_VOLTAGE_SUM = wBATTERY_VOLTAGE_SUM + ADC1_GetBufferValue(1);
byBATTERY_VOLTAGE_SAMPLE_COUNT++;
if(byBATTERY_VOLTAGE_SAMPLE_COUNT > 3)
{
wBATTERY_VOLTAGE = wBATTERY_VOLTAGE_SUM>>2;
wBATTERY_VOLTAGE_SUM = 0;
byBATTERY_VOLTAGE_SAMPLE_COUNT = 0;
}
wBOOST_VOLTAGE_SUM = wBOOST_VOLTAGE_SUM + ADC1_GetConversionValue();
byBOOST_VOLTAGE_SAMPLE_COUNT++;
if(byBOOST_VOLTAGE_SAMPLE_COUNT > 3)
{
wBOOST_VOLTAGE = wBOOST_VOLTAGE_SUM>>2;
wBOOST_VOLTAGE_SUM = 0;
byBOOST_VOLTAGE_SAMPLE_COUNT = 0;
}
}