cancel
Showing results for 
Search instead for 
Did you mean: 

Calculation Adc value based on CubeMx

jjj0214
Associate II
Posted on March 16, 2016 at 02:42

Hello guys.

I am using STM32F051K8 with CubeMX. While using ADC conversion, the adc value is working weird.

The value I measured is adc value from position sensor. the range is from 0 to 2.9V(measured with Oscilloscope).

When the value is reached in 2.9v, the measured ad value is 3600 which is correct(3600/4095 * 3.3v). However the ad value became 0 when it measured below than 0.7v.

Is there any calculation that I missed?

For example, if 1v is measured, I think the ad value should be 1240 (1v/3.3v*4095(12bits)) but the real ad value is 280.

Please help me with this. Thank you for reading guys.

#adc #stm32cube #bug
4 REPLIES 4
raptorhal2
Lead
Posted on March 16, 2016 at 03:07

Try setting the sampling time to max cycles. If that substantially improves the result, your position sensor probably has a high output impedance.

If increasing the sampling time is not the answer, provide more details on the sensor, adc channel and your code.

Cheers, Hal

jjj0214
Associate II
Posted on March 16, 2016 at 03:38

I tried to increase the sampling but it wont help neither :(

I am using the 357 potentionmeter from Vishay.

I attached a datasheet in pdf.

Here is thecircuit diagram

0690X00000604ttQAA.png

And, for the source code, I didnt do anything.

What I put is only

__IO uint16_t ADC_val[2]=0;

HAL_ADC_Start_DMA(&hadc,(uint32_t*)&ADC_val, 2);

and for Adc Init()

ADC_ChannelConfTypeDef sConfig;

/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)

*/

hadc.Instance = ADC1;

hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;

hadc.Init.Resolution = ADC_RESOLUTION12b;

hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;

hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;

hadc.Init.EOCSelection = EOC_SINGLE_CONV;

hadc.Init.LowPowerAutoWait = DISABLE;

hadc.Init.LowPowerAutoPowerOff = DISABLE;

hadc.Init.ContinuousConvMode = ENABLE;

hadc.Init.DiscontinuousConvMode = DISABLE;

hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

hadc.Init.DMAContinuousRequests = ENABLE;

hadc.Init.Overrun = OVR_DATA_PRESERVED;

HAL_ADC_Init(&hadc);

/**Configure for the selected ADC regular channel to be converted.

*/

sConfig.Channel = ADC_CHANNEL_7;

sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;

sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;

HAL_ADC_ConfigChannel(&hadc, &sConfig);

/**Configure for the selected ADC regular channel to be converted.

*/

sConfig.Channel = ADC_CHANNEL_VREFINT;

HAL_ADC_ConfigChannel(&hadc, &sConfig);

I hope it can be fixable..

________________

Attachments :

potentionmeter-357.pdf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HthB&d=%2Fa%2F0X0000000aVr%2F0IlA_P6gKwMQoP54t7SoTQsgk9304.OEx78P_DKmUVM&asPdf=false
jjj0214
Associate II
Posted on March 16, 2016 at 08:45

Self Answer:

I figured that it occurs because of the potentiometer.

in 360 degrees, this potentiometer can use only 250~260 degrees.

because of the high resistance, around 100~110 degrees are not usable.

and calculation of ad value is different with normal ad calculation.

In this situation, I am just using ad value to get degree not voltage value.

Thanks for Hal to answer my question, anyway it was helpful for me too.

raptorhal2
Lead
Posted on March 16, 2016 at 18:27

The ADC sampling circuit has a 1K input resistance in series with the 470 Ohm and pot resistance. This causes the mysterious 0.7V drop.

When using a resistive signal source, a buffer amplifier to the ADC channel is recommended.

Cheers, Hal