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.
Timer Counter in Sim
Moderator: Benj
-
- Valued Contributor
- Posts: 786
- Joined: Fri Jun 06, 2014 3:53 pm
- Has thanked: 187 times
- Been thanked: 205 times
Re: Timer Counter in Sim
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
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
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Timer Counter in Sim
I would never recommend screen captures.
We can't get the full picture from them.
can you post flowchart please.
We can't get the full picture from them.
can you post flowchart please.
Martin
-
- Posts: 67
- Joined: Tue Sep 16, 2008 2:09 pm
- Location: Minnesota USA
- Has thanked: 4 times
- Been thanked: 17 times
- Contact:
Re: Timer Counter in Sim
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?
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?
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Timer Counter in Sim
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.
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.
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times