Skip to main content
Visitor II
July 24, 2008
Question

ADC problems with STR7

  • July 24, 2008
  • 4 replies
  • 1093 views
Posted on July 24, 2008 at 09:48

ADC problems with STR7

    This topic has been closed for replies.

    4 replies

    zaz426Author
    Visitor II
    January 30, 2007
    Posted on January 30, 2007 at 12:45

    I copied the program from the ST application note and I cannot get the ADC to give me a good reading. I basically have a DC voltage between 0.6 and 0.75 volts that I need to measure. I dont even need the 12 bit resolution, however when I run the ADC_12 I get a return value of either 0x95E or 0x6A1. Neither of which I believe since I change the input voltage and the results are the same. Additionally, the CSR reguister is always set as an overrun condition?

    My code is below I am using the IAR workbench.

    void ADC_init (void)

    {

    /* Configure the ADC analog input pin to High Impedance Analog Input */

    GPIO_Config (GPIO1, AIN0, GPIO_HI_AIN_TRI);

    /* Initialise the TIM0 registers */

    // TIM_Init ( TIM0 );

    /* Set TIM0 prescalar division factor to 0x0F */

    // TIM_PrescalerConfig (TIM0, 0x0F);

    /* Set the TIM0 counter to 0XFFFC */

    // TIM_CounterConfig (TIM0, TIM_CLEAR);

    /* Initialize the ADC Registers */

    ADC12_Init();

    /* Configure the ADC Prescaler */

    ADC12_PrescalerConfig(1000);

    }

    int ADC_Convert()

    {

    #ifdef ADC_SINGLE

    TIM_CounterConfig (TIM0, TIM_CLEAR);

    /* Select the Single mode of conversion */

    ADC12_ModeConfig (ADC12_SINGLE);

    /* Select the channel to be converted */

    ADC12_ChannelSelect(ADC12_CHANNEL0);

    /* Enable the converter */

    ADC12_ConversionStart();

    /* Repeat until end of conversion */

    ADC12_Clear();

    ADC12_ConversionStart();

    while (ADC12_FlagStatus (ADC12_DA0)==RESET);

    ADC12_ConversionStop();

    if( ADC12_FlagStatus (ADC12_OR) == RESET)

    {

    /* Get the Counter value */

    Counter = TIM0->CNTR;

    /* Read the conversion result*/

    Conv_Res = ADC12_ConversionValue(ADC12_CHANNEL0);

    }

    #endif

    /* Disable the Converter */

    ADC12_ConversionStop();

    return Conv_Res ;

    you can e-mail any suggestions to

    mailto:zaz426@yahoo.com

    thank you

    Visitor II
    January 31, 2007
    Posted on January 31, 2007 at 16:35

    Hello zaz426,

    Could you please inform me about your hardware environement ?

    Name of the board and its revision and if you have shematics of the ADC

    part.

    Before using the STR71x ADC you have to perform a calibration ( Hardware

    & Software ) providing a stable 2.5 volts and 0 level and use the Software calibration formula in ST Software library in order to linearise your converted data.

    I hope that this may help you :)

    Regards, :p

    rave

    Visitor II
    June 12, 2008
    Posted on June 12, 2008 at 13:18

    Hi,

    I am using the ST - C-library and would like to know how to calibrate the ADC - there is no command described!

    Visitor II
    July 24, 2008
    Posted on July 24, 2008 at 09:48

    Did you try to set the ports as analog input?

    BTW, the method for calibrating the adc is in the ADC section of the reference manual. However, there is no library or routine that makes the work for you. You'll have to do it yourself :-[