ARM STR71x wrong ADC-Measurement

Hello people,

I have a small problem with the internal AD converter on my

STR711-EvalBoard (PDFs to the controller:

http://www.st.com/mcu/devicedocs-STR711FR2.html).

This is my hardwaresetup: AVDD is connected to 3.3 V, AVSS with GND

and I am using channels 0-2 of internal 12-bit AD converter.

PCLK2 is initialized as the following:

RCCU_Div2Config (DISABLE);
RCCU_PLL1Config (RCCU_PLL1_Mul_16, RCCU_Div_1);
RCCU_RCLKSourceConfig (RCCU_PLL1_Output);
RCCU_MCLKConfig (RCCU_DEFAULT);
RCCU_FCLKConfig (RCCU_RCLK_4);
RCCU_PCLKConfig (RCCU_RCLK_4);

The clock of PCLK2 is at 16Mhz because I have connected a 4Mhz crystall.

This is the initialization of the ADC:

ADC12_Init ()
ADC12_PrescalerConfig (100);
ADC12_ModeConfig (ADC12_ROUND);
ADC12_ConversionStart ();

And this is how I read out the Measurement and transmit it via the UART

to the computer:

ADC_Value = ADC12_ConversionValue (ADC12_CHANNEL0);
sprintf (buffer, "Ch 0:% i", ADC_Value);
UART_StringSend (UART0, Buffer);

ADC_Value = ADC12_ConversionValue (ADC12_CHANNEL1);
sprintf (buffer, "Ch 1:% i", ADC_Value);
UART_StringSend (UART0, Buffer);
  
ADC_Value = ADC12_ConversionValue (ADC12_CHANNEL2);
sprintf (buffer, "Ch 2:% i", ADC_Value);
UART_StringSend (UART0, Buffer);

The following problem arises now: Although I can measure 1.65 V at the input, on the PC always arrives a value of about 410, which is wrong:

12-bit: 0 - 4095

Range: 0 - 2.5 V

2.5 V / 4096 * 410 = 0.25 V

What could be the reason? In the firmware Library of ST I have

seen nothing about how to calibrate the ADC!

Hi,

These might help:

http://www.st.com/stonline/books/pdf/docs/10341.pdf

http://www.st.com/stonline/products/sup … an1798.zip

This is a simple routine taken from the str7 adc example

#define referencemv 2500
#define offset 0x9ab   // digital value for the 0 volt
#define vref 0x5f1  // digital value for the 2.5 volt

// using calibration offer the possibility to have the value of the tension conversted.
u32 ADC12_Calib(u16 Conv_Res)
{
  if ((Conv_Res>offset)&&(Conv_Res<=0xfff))
    return referencemv*(Conv_Res-offset)/(0xfff-offset+vref);
  else
  if (Conv_Res<0x7ff)
    return referencemv*(0xfff+Conv_Res-offset)/(0xfff-offset+vref);
  else return 0;
}

Cheers

Spen

Thank you very much - it was about the two’s complement - now it works!

[>> EDIT: Moved, because the new problem doesn’t hit the topic anymore >>](http://forum.sparkfun.com/viewtopic.php?p=51035#51035)