2023-06-25 07:13 AM - last edited on 2023-09-01 09:44 AM by Amel NASRI
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.)
2023-06-25 07:31 AM
2023-06-27 02:19 AM
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.
2023-06-30 09:40 AM
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.
2023-06-30 09:53 AM
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.
2023-06-30 10:17 AM
And on start ask self , how precise 0,25 sec you require.