2015-05-26 01:36 PM
Hi
I cannot find the STM32F10xxx firmware library as described here: http://read.pudn.com/downloads106/sourcecode/embed/437624/stm32/STM32F%20Documents/Application%20Note/STM32F10xxx%20TIM%20application%20examples.pdf
I am searching for the ''TIM example 6'' to run STM32F10xxx TIMx PWM input mode.
Could you please post my the direct link to that file?
Thank you
2015-05-26 02:04 PM
It's an 8 year old document, would suggest you go to the ''Design Resources'' for your part, and download the Standard Peripheral Library (v3.5.0 for the F1)
This has at least one TIM PWM Input example, and there's got to be a few posted here to the forum if you dig a bit.STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\TIM\PWM_Input2015-05-26 03:04 PM
hi
thank you for your quick response, the directory works well.do you know the directory link to the STM32F4 series as well?2015-05-26 03:30 PM
STM32F4-Discovery_FW_v1.1.0\Project\Peripheral_Examples\TIM_PWM_Input
STM32F4xx_DSP_StdPeriph_Lib_V1.3.0\Project\STM32F4xx_StdPeriph_Examples\TIM\TIM_PWMInput About 75% down this thread is a Servo example using PWM Input2015-05-27 08:37 AM
I am now working with the timer example for PWM in.
although i do not programm microcontrollers that often and could use some help, how can i now read the duty cycle or frequency in the pre setup programm within the while loop?/** ****************************************************************************** * @file TIM/TIM_PWMInput/main.c * @author MCD Application Team * @version V1.1.0 * @date 18-January-2013 * @brief Main program body ****************************************************************************** * @path STM32F4xx_StdPeriph_Examples TIM_PWMInput ****************************************************************************** *//* Includes ------------------------------------------------------------------*/#include ''stm32f4xx.h''/* Private typedef -----------------------------------------------------------*//* Private define ------------------------------------------------------------*//* Private macro -------------------------------------------------------------*//* Private variables ---------------------------------------------------------*/TIM_ICInitTypeDef TIM_ICInitStructure;/* Private function prototypes -----------------------------------------------*/void TIM_Config(void);/* Private functions ---------------------------------------------------------*/// ==============================================================================// MAIN// ==============================================================================/** * @brief Main program * @param None * @retval None */int main(void){ /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f40xx.s/startup_stm32f427x.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* TIM Configuration */ TIM_Config(); /* --------------------------------------------------------------------------- TIM4 configuration: PWM Input mode In this example TIM4 input clock (TIM4CLK) is set to 2 * APB1 clock (PCLK1), since APB1 prescaler is different from 1. TIM4CLK = 2 * PCLK1 PCLK1 = HCLK / 4 => TIM4CLK = HCLK / 2 = SystemCoreClock /2 External Signal Frequency = TIM4 counter clock / TIM4_CCR2 in Hz. External Signal DutyCycle = (TIM4_CCR1*100)/(TIM4_CCR2) in %. --------------------------------------------------------------------------- */ TIM_ICInitStructure.TIM_Channel = TIM_Channel_2; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0x0; TIM_PWMIConfig(TIM4, &TIM_ICInitStructure); /* Select the TIM4 Input Trigger: TI2FP2 */ TIM_SelectInputTrigger(TIM4, TIM_TS_TI2FP2); /* Select the slave Mode: Reset Mode */ TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_Reset); TIM_SelectMasterSlaveMode(TIM4,TIM_MasterSlaveMode_Enable); /* TIM enable counter */ TIM_Cmd(TIM4, ENABLE); /* Enable the CC2 Interrupt Request */ TIM_ITConfig(TIM4, TIM_IT_CC2, ENABLE); while (1);}// ==============================================================================// ==============================================================================// TIM_CONFIG// ==============================================================================/** * @brief Configure the TIM4 Pins. * @param None * @retval None */void TIM_Config(void){ GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* TIM4 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); /* GPIOB clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); /* TIM4 chennel2 configuration : PB.07 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Connect TIM pin to AF2 */ GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_TIM4); /* Enable the TIM4 global Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);}// ==============================================================================// ==============================================================================// USE FULL ASSERT// ==============================================================================#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// ==============================================================================2015-05-27 08:43 AM
You'd either have to get the interrupt handler to load the values into variables you could read later, or spin in your while() loop waiting for the appropriate CC1/CC2 event to flag, and reading the CCR1/CCR2 register then.
2015-05-27 10:14 AM
thank you for always answering that fast. i'd prefer the former solution processing the values through the interrupt handler. could you refer to an example of such coding?
2015-05-27 11:19 AM
i'd prefer the former solution processing the values through the interrupt handler. could you refer to an example of such coding?
Please review the thread cited earlier.2015-05-31 08:35 AM
2015-05-31 08:51 AM
There are some assorted references to TIM3 still.
All peripheral pins (TIM, USART) need to be in AF mode (PP and AF) , and associated with a specific peripheral with a GPIO_PinAFConfig(). It's important to look at F4 code examples, the F1 configured pins slightly differently.