cancel
Showing results for 
Search instead for 
Did you mean: 

How make for Stm32F407G-DISC1 with Tim

Pogomo
Associate

I try make"design system that sets outputPin (should be digital gpio output ) high for 0.25 secs,and low for 0.25 secs."
and i use  GPIOA_PIN4(input) and   GPIOB_PIN0(output), I'm new to stm32, I'm having trouble with the timer.
I try use tim, how can I do it (high for 0.25 secs,and low for 0.25 secs.) 

Pogomo_0-1687702071371.png

 

5 REPLIES 5
Pavel A.
Evangelist III
KDJEM.1
ST Employee

Hello @Pogomo and welcome to the Community :),

Besides, the "General-purpose timer cookbook for STM32 microcontrollers" shared by @Pavel A. , I advise you to get inspired from the available TIM_TimeBase example in the STM32CubeF4 MCU package. This example may help you to configure the timer by following the instructions in the readme file.

I hope this help you!

Kaouthar

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.

for something like this, I would:

FOREVER {
   HAL_Delay(250);
   HAL_GPIO_WritePin(GPIO_Output_Port, GPIO_Output_Pin, GPIO_PIN_SET);
   HAL_Delay(250);
   HAL_GPIO_WritePin(GPIO_Output_Port, GPIO_Output_Pin, GPIO_PIN_RESET);
}

Unless you really need to use a TIM timer. You already have the SYSTICK timer active anyway, you might as well get some use out of it.

Using a TIM timer, on a 407VGT, pin PB0 can be TIM1 channel 2N, TIM3 channel 3, or TIM8 channel 2N. I'd go with TIM3 channel 3 so you don't have to worry about the weirdness of the inverted output channels (ending in N).

Set up TIM3 to generate a 50% PWM with a frequency of 2Hz. This will involve taking your base processor frequency, figure out what the frequency of the APB1 timer bus is (TIM3 is on APB1), then configure TIM3 with an internal clock source, set the prescaler and counter period to generate 2Hz, channel 3 to generate PWM on CH3, set the Pulse count to be 1/2 of what the counter period is, then start the timer in PWM mode.

This is a very coarse overview, you'll have to figure out the details for your board and what the appropriate code sequence is to set up the timer. I use CubeIDE and HAL, you may want to stuff values into registers (like an animal), but the code will vary depending on your board and code proclivities. 

MM..1
Chief III

And on start ask self , how precise 0,25 sec you require.