STM32 Timer Problem

Discuss with MikroElektronika software developers about current library development.
Post Reply
Author
Message
semmoor
Posts: 107
Joined: 09 Mar 2012 16:49

STM32 Timer Problem

#1 Post by semmoor » 29 Jul 2018 20:41

Hello ,

I have a problem in timer , how can i calculate the time in seconds from the timer register?

for example this is my program:

Code: Select all


if(first_rising_edge == 1)
{
  start_timer_3;
}
if(second_rising_edge == 1)
{
  stop_timer_3;
 time_elapsed = ?

 frequency = 1/ time_elapsed;
}


the idea is to start timer 3 if first rising edge is detected and stop it if second rising edge is detected then
calculate the period in seconds from the value in timer 3.

i tried many times but i keep getting wrong values.

this is the configurations of my MCU MINI-M4 for STM32 :

MCU: STM32F415RG

MCU running: 60Mhz
timer_3 prescalar is : 1
timer_3 generates an interrupt every : 65535

Best,
Sameer

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: STM32 Timer Problem

#2 Post by filip » 03 Aug 2018 07:33

Hi,

Have you tried using Timer Calculator for the correct timer calculations ?
https://www.mikroe.com/timer-calculator

Regards,
Filip.

semmoor
Posts: 107
Joined: 09 Mar 2012 16:49

Re: STM32 Timer Problem

#3 Post by semmoor » 03 Aug 2018 21:37

I used timer calculator but the result is not correct it takes longer time than
What i need for the toggling an LED.

I'm using mikroprogrmmer for stm32. What is the correct scheme for editing the settings?
Because i think the problem is in configurations of the mcu.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: STM32 Timer Problem

#4 Post by filip » 07 Aug 2018 14:49

Hi,

Please find the config scheme in the attachment.

Regards,
Filip.
Attachments
MINI-M4_STM32.rar
(881 Bytes) Downloaded 176 times

semmoor
Posts: 107
Joined: 09 Mar 2012 16:49

Re: STM32 Timer Problem

#5 Post by semmoor » 07 Aug 2018 18:40

Thank ,

So how can i get the time from the 16bit register?

Best,
Sameer

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: STM32 Timer Problem

#6 Post by filip » 09 Aug 2018 13:20

Hi,

you can set up a timer that will be triggered upon desired amount of time (e.g. 1 second) and then increment a variable so you know that 1 second has passed.

Regards,
Filip.

Post Reply

Return to “Library Development Discussion”