ResetCounter function in Timer Module Not Working

Use this section to discuss your embedded Flowcode projects.
Post Reply
Miker1595
Posts: 10
http://meble-kuchenne.info.pl
Joined: Fri Sep 13, 2024 9:07 pm
Has thanked: 2 times

ResetCounter function in Timer Module Not Working

Post by Miker1595 »

Hello,

Can anyone offer some guidance on reseting the Timer module? I can't seem to get the timer to reset back to zero short of stopping my program and running it again. Crazy.......... I want to count time between two events. Should be simple using the startcounter, stopcounter, and resetcounter functions in the Timer macro - yes? I can start and stop no problem. However the reset function does nothing. Once I start the timer again it just begins counting time where the previous counting left off.

I've tried everything I can think of to make this work. Hope someone can help. Thank You!!

In my attached file I use the push button to start and stop the timer.

-Mike
Attachments
Karl Usensor_MR.fcfx
(20.17 KiB) Downloaded 217 times

medelec35
Matrix Staff
Posts: 1913
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 619 times
Been thanked: 644 times

Re: ResetCounter function in Timer Module Not Working

Post by medelec35 »

Hello.
I have noticed in your project after printing the counter value, you don't clear the value before printing again.
What will happen is you will see a value e.g. 1234567
Then if the next value to be printed 765, the display will show 7654567
Therefore, it looks like the value is increasing as you will always see 7 digits unless the value increases above 7 digits.
I would suggest to clear line 2 before printing the next value so you are clearing unwanted digits.
Martin

Miker1595
Posts: 10
Joined: Fri Sep 13, 2024 9:07 pm
Has thanked: 2 times

Re: ResetCounter function in Timer Module Not Working

Post by Miker1595 »

Hi Martin,

Thank you for your help! I have added the "Clear" command and I now have the LCD (in simulation) printing the Timer value correctly. However.....I STILL cannot get the Timer value to reset using the ResetCounter command. I need to clear that value to start a new event. Can you please tell me what I may be doing wrong with that function? How can I reset that Timer value to zero? Thank You.

Miker1595
Posts: 10
Joined: Fri Sep 13, 2024 9:07 pm
Has thanked: 2 times

Re: ResetCounter function in Timer Module Not Working

Post by Miker1595 »

Karl Usensor_MR.fcfx
(20.39 KiB) Downloaded 186 times
Attached my latest file here, Martin. To go along with my reply to you about the ResetCounter function not working for me.

stefan.erni
Valued Contributor
Posts: 997
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 190 times
Been thanked: 217 times

Re: ResetCounter function in Timer Module Not Working

Post by stefan.erni »

Hi Miker, Hi Martin

Miker , can you check the Pin you used for the hardware ?

In the comment is D0 for the input but in the config from the switch it's B8.

regards


Stefan
2024-10-09_08-41-40.PNG
2024-10-09_08-41-40.PNG (11.15 KiB) Viewed 8992 times

medelec35
Matrix Staff
Posts: 1913
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 619 times
Been thanked: 644 times

Re: ResetCounter function in Timer Module Not Working

Post by medelec35 »

Hi Mike.
Before the timer component is investigated, your project requires changing so its set up to function correctly.
It's important to note you can't have the same component functions within an interrupt and within any other accessible user call macros, including Main.
Interrupts must kept as short as possible , e.g for calculations and to set/clear flags.

Can you try the attached and see if that works for you, clearing the reset counter.
Attachments
Karl Usensor_MR v2.fcfx
(21.96 KiB) Downloaded 164 times
Martin

medelec35
Matrix Staff
Posts: 1913
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 619 times
Been thanked: 644 times

Re: ResetCounter function in Timer Module Not Working

Post by medelec35 »

Hi Mike.
Did you get a chance to test my modifications and any better?
Martin

Miker1595
Posts: 10
Joined: Fri Sep 13, 2024 9:07 pm
Has thanked: 2 times

Re: ResetCounter function in Timer Module Not Working

Post by Miker1595 »

Hi Martin!

Sorry for the late response. I had to go out of town and could not reply to you. Back now.

I DID try your modifications. I am still not getting the operation I need. Simply put: My final program needs to start and stop a timer on a rising edge of an input signal. Hence, I need the ResetCounter function in the Timer macro to actually reset to zero to start timing a NEW event. If you could just answer this question to start:

Does the ResetCounter function in the Timer macro reset the count to ZERO? I don't see that it does anything. I have also tryed using the StartCounter(1) function. It also does not reset the counter to zero.

I have search the Wiki, forum, and YouTube channel for help, but have had to luck.

Have I explained this well enough? Thank You again for your help.

-Mike

Post Reply