![]() SMasterConfig. HAL_TIM_IC_ConfigChannel(&htim1, &sConfigIC, TIM_CHANNEL_2) SConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI SConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING HAL_TIM_IC_ConfigChannel(&htim1, &sConfigIC, TIM_CHANNEL_1) SConfigIC.ICSelection = TIM_ICSELECTION_INDIRECTTI SConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING HAL_TIM_SlaveConfigSynchronization(&htim1, &sSlaveConfig) To generate a fixed duty cycle PWM signal I added HALTIMBaseStart (&htim1) //Starts the TIM Base generation and HALTIMPWMStart (&htim1, TIMCHANNEL1)//Starts the PWM signal generation to the Timer initialization function as shown below. ![]() SSlaveConfig.TriggerPrescaler = TIM_ICPSC_DIV1 I used the STM32Cube initialization code generator to generate an initialized Timer function. SSlaveConfig.TriggerPolarity = TIM_INPUTCHANNELPOLARITY_RISING SSlaveConfig.InputTrigger = TIM_TS_TI2FP2 SSlaveConfig.SlaveMode = TIM_SLAVEMODE_RESET Basically, the first channel will give you the period and the second channel will give you the pulse. This way, 2 channels are used (but you have only one physical connection). But while implementing, we need to take care of few things and we will see them along this explanation.You need to setup your timer as PWM input and not capture input (TIM1 for example can do it). Yeah I know it's not that hard to understand it. (4) Now the frequency can be calculated by first finding the difference between these 2 captured values and than dividing the timer clock by this difference. (3) On detecting the second rising edge, another TIMESTAMP will be captured and stored (2) Here we are going to capture the TIMESTAMP and store it in some variable (1) Whenever a rising edge is detected, a callback function is called. Input capture works in the following way:. In this tutorial, I will only cover the frequency part and the pulse width will be covered in next one where we will use PWM Input to do that. ![]() Im trying to measure time passed between two external interrupts generated by. So today We are going to use one of the functionality of STM32 Timers i.e Input Capture.Īs the name implies, Input capture is used to capture the input signal given to the microcontroller and measures its frequency and pulse width. Electrical STM32 Input capture PWM frequency measurement problem using HAL. Timers are and always have been one of the most challenging topic in any microcontroller. Today I have finally decided to write on this topic. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |