AnsweredAssumed Answered

STM32F4 Discovery Analogue Input Counting

Question asked by Stevo on Mar 19, 2015
Latest reply on Mar 28, 2015 by Stevo
Hi Im new to programming and therefore new to the ST Board.

I am trying to hold open an output while  a sensor counts a passing objects. Once the objects have passed 10 times I want to close the output. 

My problem comes when I'm trying to distinguish the input impulses from the sensor. When the sensor is giving an input the program is seeing that it is above the 2000 value and is counting 10 instantly and then closing the output.

How do I get it to only recognise the rising edge of the input and not count again until there is a consecutive rising edge from the next passing input?

Your help will be much appreciated.

int main(void)
{
     int sensor_count = 0;
     int ConvertedValue = 0; //Converted value read from ADC

     PA0_button_setup();
     GPIO_ResetBits(GPIOB, GPIO_Pin_1 );
     adc_configure();                                                  //Start configuration
     PB1_Pin_Setup();

     while (1)
     {
          if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0))
          {
               sensor_count = 0;
               GPIO_SetBits(GPIOB, GPIO_Pin_1);

               while (! (sensor_count >= 10))
               {
                    ConvertedValue = adc_convert();//Read the ADC converted value

                    if (ConvertedValue > 2000)
                    {
                    sensor_count++;
                    }
                    if (sensor_count == 10)
                    {
                    GPIO_ResetBits(GPIOB, GPIO_Pin_1);
                    }
               }
          }
          else
          {
          GPIO_ResetBits(GPIOB, GPIO_Pin_1);
          }
     }
}

Outcomes