Posted on April 15, 2016 at 21:26hello,
I want to count the input signal (PA1) in a period of 10 second.
The PA1 can have two state:
state1 :-connected to 5v
state2: not connected to anything.
So I want that the variable impulsion be incremented (+1) for each translation from state 2 to state 1.
So I use the sysTick to configure a period of 10 second, in each I incremente the varibale impulsion. But this variable it's not well incremented. can you help me to solve this problem please.
#include ''stm32f4xx.h''
__IO uint32_t TimmingDelay;
uint64_t revolution_period;
int impulsion=0;
/**************************************************************************/
/**************************************************************************/
/**************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GpioConfiguration;
GpioConfiguration.GPIO_Pin =GPIO_Pin_1;
GpioConfiguration.GPIO_Mode = GPIO_Mode_IN;
GpioConfiguration.GPIO_OType = GPIO_OType_PP;
GpioConfiguration.GPIO_Speed = GPIO_Speed_50MHz;
GpioConfiguration.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA,&GpioConfiguration);
}
/**************************************************************************/
void SysTick_Handler(void)
{
if(TimmingDelay !=0)
{
TimmingDelay --;
}
}
/**************************************************************************/
void count_pulse(__IO uint32_t time)
{
TimmingDelay = time;
while(TimmingDelay !=0)
{
if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1)==Bit_SET)
{
impulsion=impulsion + 1;
}
}
}
/**************************************************************************/
int main(void)
{
//Enable the GPIOD Clock
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
// GPIOA Configuration
GPIO_Configuration();
//Systick Configuration
NVIC_SetPriority (SysTick_IRQn, 0);
SysTick_Config(SystemCoreClock/1000);
while(1)
{
// insert a delay of 10s
count_pulse(10000);
revolution_period= 10000/impulsion;
}
}
/**************************************************************************/
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf(''Wrong parameters value: file %s on line %d\r\n'', file, line) */
while (1)
{}
}
#endif