Page 1 of 1

Timer Counter in Sim

Posted: Thu Jul 02, 2020 2:56 am
by alanwms
Hello Ben - Just doing a simple test to understand the timer capabilities, and can't get the Ulong_timer variable to update. It's always at zero- am I missing something?
I did try enabling the timer interrupt to no avail.

Re: Timer Counter in Sim

Posted: Sat Jul 11, 2020 1:58 pm
by chipfryer27
Hi

Have you had a look here?

https://www.matrixtsl.com/wiki/index.ph ... Properties

Each properties box in FC has a little help icon in bottom left that leads to their wiki which is usually very helpful.

The timer interrupt will generate an interrupt at whatever frequency you have set (say for example 2000Hz). So 2000 times a second it will automatically call whatever Macro you have set in the properties box of the Enable Interrupt icon. You do not need any further call to such.

In the "Interrupt Macro" that you create and call via the Interrup, have a calculation box that increments your variable (e.g. count = count + 1), then in your main program you could have a decision / action based on count, perhaps zeroing count after action completes e.g. :-

if count >= 2000 then "xyz"
count = 0

would call / do "xyz" every second.

Hope this helps.

Regards

Re: Timer Counter in Sim

Posted: Sat Jul 11, 2020 5:35 pm
by medelec35
I would never recommend screen captures.
We can't get the full picture from them.
can you post flowchart please.

Re: Timer Counter in Sim

Posted: Sun Jul 12, 2020 5:21 pm
by alanwms
Thanks - I do understand interrupts. What I am attempting to do is count hardware pulses into the timer. I'm not sure how to do that in sim. I have:
1. Attempted to setup the timer 0 interrupt with a transition on T0CK1 pin and connect a simulator switch to that pin. Regardless, the interrupt happens in sim no matter the clock source select setting.
2. The interrupt properties dialog box indicates a clock speed and interrupt frequency even after I select a hardware input transition (Interrupt frequency is hardware dependent of course). That issue is a Flowcode issue and I understand that it has no bearing on the frequency if interruption

I guess my question is - Can I simulate a counter counting with a simulated hardware switch?

Re: Timer Counter in Sim

Posted: Mon Jul 13, 2020 11:06 am
by medelec35
Hi alanwms,
Timer 0 will not simulate external input using T0CKI
Also Timer 1 will not simulate external input using T1CKI
Simulation only, whether T0CKI, T1CKI or internal is selected, Flowcode will treat the interrupt as internal and will continue to count.
Should work OK on hardware.
Timer component (within data menu) simulates for me OK.
If you want to see the value changing, then you will need to slow the simulation down.
50Hz should be fine.

Re: Timer Counter in Sim

Posted: Mon Jul 13, 2020 3:11 pm
by alanwms
Thanks - That helps a lot.

Re: Timer Counter in Sim

Posted: Mon Jul 13, 2020 7:22 pm
by medelec35
You're welcome.
Thanks for letting us know.