2015-08-11 05:22 AM
Can anyone help me in understanding difference between HAL and firmware,
I can find plenty of examples useful for starter as complete project in HAL related stuff, while no such thing available for firmware stuff (at least to my limited knowledge)If there is any, please share for me, I am interested in some project like inputcapture, (project of HAL, available online) in firmware, also please tell me equivalent to this instruction for HALTIM_TIxExternalClockConfig(TIM3, TIM_TIxExternalCLK1Source_TI1, TIM_ICPolarity_Rising, 0);
Thanks in Advance2015-08-11 05:47 AM
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2015-08-11 08:58 AM
STM32F4xx_DSP_StdPeriph_Lib_V1.5.1\Project\STM32F4xx_StdPeriph_Examples\TIM\TIM_InputCapture
2015-08-11 06:45 PM
thanks rrom,
2015-08-11 06:46 PM
2015-08-11 08:01 PM
Is there any project available which can count external pulses (not the frequency) JUST NO OF EXTERNAL PULSES in HAL or firmware? if any one know this please guide me.
Thanks in advance2015-08-11 09:17 PM
I'm only working with the SPL (Standard Peripheral Library)
For setting up the external count we have The current count being visible in TIMx->CNT, now you could probably augment that by latching the content into one of the capture registers, periodically, at a defined integration period that works for the frequency being used, and the width of the counter (16/32-bit). Perhaps every 1ms or 10ms.http://www.st.com/web/en/resource/technical/document/application_note/DM000425pdf
2015-08-11 09:55 PM
Some goods examples to watch on F0 device.
https://www.youtube.com/watch?v=R8UwAboFQGA
https://www.youtube.com/watch?v=_wE7tbilca4
Easily to use with others seriesTo give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2015-08-12 07:33 AM
Thanks for the replies
I am trying to use TIM1 in external counting mode, but some how the count is changing even I have not connected any signal to PE9 (even not to any pin). can any one tell me whats going on with the code? I am using STM32F4 DiscoveryI am pasting my program: /******************************************** * main.c * ************************** */#include ''main.h''TIM_HandleTypeDef TimHandle;TIM_ClockConfigTypeDef sClockSourceConfig;TIM_MasterConfigTypeDef sMasterConfig;uint32_t uwIC2Value1 = 0;uint32_t uwIC2Value2 = 0;uint32_t uwDiffCapture = 0;uint16_t uhCaptureIndex = 0;uint32_t uwFrequency = 0;uint32_t uwFrequency1 = 0;uint32_t uwFrequency2 = 0;uint32_t uwFrequency3 = 0;uint32_t uw = 0;uint32_t uw2 = 0;static void SystemClock_Config(void);void MX_TIM1_Init(void);void MX_GPIO_Init(void);int main(void){ HAL_Init(); SystemClock_Config(); MX_TIM1_Init();MX_GPIO_Init(); while (1) { if(uhCaptureIndex == 0) { /* Get the 1st Input Capture value */ uw=TIM1->CNT; uhCaptureIndex = 1; } else if(uhCaptureIndex == 1) { /* Get the 2nd Input Capture value */ uw2=TIM1->CNT; if (uw2 > uw) { uwDiffCapture = (uw2 - uw); } else /* (uwIC2Value2 <= uwIC2Value1) */ { uwDiffCapture = ((0xFFFF - uw) + uw2); } uw=uw2; uwFrequency=uwDiffCapture; } }}static void SystemClock_Config(void){ RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct; /* Enable Power Control clock */ __HAL_RCC_PWR_CLK_ENABLE();__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; /*RCC_OscInitStruct.PLL.PLLM = 25;*/ RCC_OscInitStruct.PLL.PLLM = 8; /*RCC_OscInitStruct.PLL.PLLN = 360;*/ RCC_OscInitStruct.PLL.PLLN = 336; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 7; HAL_RCC_OscConfig(&RCC_OscInitStruct); /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);}void MX_TIM1_Init(void){ /*##-1- Configure the TIM peripheral #########*/ TimHandle.Instance = TIMx; TimHandle.Init.Period = 0xFFFF; TimHandle.Init.Prescaler = 0; TimHandle.Init.ClockDivision= TIM_CLOCKDIVISION_DIV1; TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; TimHandle.Init.RepetitionCounter = 0; HAL_TIM_Base_Init(&TimHandle); sClockSourceConfig.ClockSource=TIM_CLOCKSOURCE_ETRMODE2;sClockSourceConfig.ClockPolarity = TIM_CLOCKPOLARITY_NONINVERTED;sClockSourceConfig.ClockPrescaler = TIM_CLOCKPRESCALER_DIV1;sClockSourceConfig.ClockFilter = 0;HAL_TIM_ConfigClockSource(&TimHandle, &sClockSourceConfig);sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;HAL_TIMEx_MasterConfigSynchronization(&TimHandle, &sMasterConfig); __TIM1_CLK_ENABLE(); TIM1->CNT=0; // TIM1->CR1|=0x0001; } void MX_GPIO_Init(void){ GPIO_InitTypeDef GPIO_InitStruct; /*##-1- Enable peripherals and GPIO Clocks ####*/ /* TIMx Peripheral clock enable */ TIMx_CLK_ENABLE(); // TIM 1 clc enable /* Enable GPIO channels Clock */ TIMx_CHANNEL_GPIO_PORT(); // Port E enable /* Configure (TIMx_Channel) in Alternate function, push-pull and 100MHz speed */ GPIO_InitStruct.Pin = GPIO_PIN_CHANNEL2; //GPIO_PIN_CHANNEL2 GPIO_PIN_11 // GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; // GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = GPIO_AF_TIMx; HAL_GPIO_Init(GPIO_PORT, &GPIO_InitStruct); /*##-2- Configure the NVIC for TIMx ############*/ /* Sets the priority grouping field */ HAL_NVIC_SetPriority(TIMx_IRQn, 0, 1); //# TIMx_IRQn TIM1_CC_IRQn /* Enable the TIM4 global Interrupt */ HAL_NVIC_EnableIRQ(TIMx_IRQn); // TIMx_IRQHandler TIM1_CC_IRQHandler}