Page 1 of 1
ResetCounter function in Timer Module Not Working
Posted: Fri Oct 04, 2024 6:10 am
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
Re: ResetCounter function in Timer Module Not Working
Posted: Fri Oct 04, 2024 11:27 am
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.
Re: ResetCounter function in Timer Module Not Working
Posted: Tue Oct 08, 2024 5:29 pm
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.
Re: ResetCounter function in Timer Module Not Working
Posted: Tue Oct 08, 2024 5:37 pm
by Miker1595
Attached my latest file here, Martin. To go along with my reply to you about the ResetCounter function not working for me.
Re: ResetCounter function in Timer Module Not Working
Posted: Wed Oct 09, 2024 9:18 am
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 (11.15 KiB) Viewed 10905 times
Re: ResetCounter function in Timer Module Not Working
Posted: Wed Oct 09, 2024 10:06 am
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.
Re: ResetCounter function in Timer Module Not Working
Posted: Thu Oct 10, 2024 4:37 pm
by medelec35
Hi Mike.
Did you get a chance to test my modifications and any better?
Re: ResetCounter function in Timer Module Not Working
Posted: Tue Oct 15, 2024 8:57 pm
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