cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F107VCT6 ADC Problem

Mohan Aithal
Associate
Posted on June 09, 2017 at 15:48

Hello All,

I am working on a development board with the MCU STM32107VCT6. I am trying to store the values from two Analog sensors and use these values to do some task. However, I am facing a problem with the ADC coversion. Say, the value stored is 2.5V, but the controller is doing the task at a different voltage. You can review my code below. It would be a great help if any of you can guide me where have I gone wrong.

Thank You.

/* This is how I am storing the value. The sensor is connected to PA5*/

if

(GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_4) == TRUE)

{

ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 1, ADC_SampleTime_41Cycles5);

ADC_Cmd(ADC1,

ENABLE

);

ADC_ResetCalibration(ADC1);

while

(ADC_GetResetCalibrationStatus(ADC1));

ADC_StartCalibration(ADC1);

while

(ADC_GetCalibrationStatus(ADC1) ==

SET

);

ADC_SoftwareStartConvCmd(ADC1,

ENABLE

);

while

(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)){}

value_Sensor1 = ADC_GetConversionValue(ADC1) * (3.3 / 4095); // value_Sensor1 is defined as static float

 }

/*This is the code to detect the stored value. Until the stored value is detected, I want to keep the PD10 high*/

if

(GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_4) ==

Bit_SET

)      // detecting should start when I press PD4

{

temp = 0;

ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 1, ADC_SampleTime_41Cycles5);

ADC_Cmd(ADC1,

ENABLE

);

ADC_ResetCalibration(ADC1);

while

(ADC_GetResetCalibrationStatus(ADC1));

ADC_StartCalibration(ADC1);

while

(ADC_GetCalibrationStatus(ADC1));

GPIO_WriteBit(GPIOD, GPIO_Pin_10,

Bit_SET

);

do

{

ADC_SoftwareStartConvCmd(ADC1,

ENABLE

);

while

(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)){}

temp = ADC_GetConversionValue(ADC1) * (3.3 / 4095);

}

while

(temp != value_Sensor1);

GPIO_WriteBit(GPIOD, GPIO_Pin_10,

Bit_RESET

);

}

0 REPLIES 0