cancel
Showing results for 
Search instead for 
Did you mean: 

ADC 1 problem with STM8S-Discovery

u23
Senior
Posted on May 26, 2015 at 11:57

Hi,

I have problem with ADC1 conversions on STM8S-Discovery.

I have configured the analogic inputs following:

PB4 - AN4

PB5 - AN5

PB6 - AN6

unsigned char ADC_Config_INT ( void )

{

    GPIO_Init(ADC_PORT,ADC_15V_PIN, GPIO_MODE_IN_FL_NO_IT);

    GPIO_Init(ADC_PORT,ADC_CURR_PIN, GPIO_MODE_IN_FL_NO_IT);

    GPIO_Init(ADC_PORT,ADC_5V_PIN, GPIO_MODE_IN_FL_NO_IT);

 

    /* De-Init ADC1 peripheral */

    ADC1_DeInit();

    

  /* Enable EOC interrupt */

  ADC1_ITConfig(ADC1_IT_EOCIE, ENABLE);

    

  /* Enable conversion data buffering */

  ADC1_DataBufferCmd(ENABLE);

    

  /* Enable scan mode conversion */

  ADC1_ScanModeCmd(ENABLE);

  /* Init ADC1 peripheral */

    /* ADC1 Channel 4 */

  ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_4, ADC1_PRESSEL_FCPU_D8, \

            ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL4,\

            DISABLE);

                        

    /* ADC1 Channel 5 */

  ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_5, ADC1_PRESSEL_FCPU_D8, \

            ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL5,\

            DISABLE);

                        

    /* ADC1 Channel 6 */

  ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_6, ADC1_PRESSEL_FCPU_D8, \

            ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL6,\

            DISABLE);                       

    

  /* Enable ADC1 */

  ADC1_Cmd(ENABLE);

      

    return 0;

}

the interrupt function code is:

#define ADC_SAMPLES 8

extern volatile uint16_t ValueCh4[ADC_SAMPLES];            

extern volatile uint16_t ValueCh5[ADC_SAMPLES];            

extern volatile uint16_t ValueCh6[ADC_SAMPLES];            

volatile uint8_t Index = 0;

extern uint8_t ArrayEmpty;

/**

  * @brief  ADC1 interrupt routine.

  * @param  None

  * @retval None

  */

 INTERRUPT_HANDLER(ADC1_IRQHandler, 22)

{

        if ( ADC1_GetFlagStatus(ADC1_FLAG_EOC) != RESET )

            {

                ValueCh4[Index] = ADC1_GetBufferValue(4);

                ValueCh5[Index] = ADC1_GetBufferValue(5);

                ValueCh6[Index] = ADC1_GetBufferValue(6);

                // Controlla se ho acquisito un numero sufficiente di campioni

                if( Index >= ADC_SAMPLES )

                        {

                            ArrayEmpty = 1;

                            Index = 0;

                        }    

                else{

                            Index++;

                        }

         

                ADC1_ClearFlag(ADC1_FLAG_EOC);

            }    

        

    return;

}

The ''ADC1_GetBufferValue'' function return the value correct the first time only.

If I modified the value on pin PB4 for example, continuos at read the previous value.

Any idea?

Thanks
2 REPLIES 2
AvaTar
Lead
Posted on May 26, 2015 at 12:11

ADC 1 problem with STM8S-Discovery

 

Are you sure you are in the right forum ?

u23
Senior
Posted on May 26, 2015 at 13:52

Sorry!

I was wrong forum!