Timer or interupt?

For general Flowcode discussion that does not belong in the other sections.
hippalator
Posts: 30
http://meble-kuchenne.info.pl
Joined: Tue Jul 15, 2025 9:05 pm
Has thanked: 5 times

Re: Timer or interupt?

Post by hippalator »

medelec35 wrote:
Sat Nov 22, 2025 5:21 pm
An easy way of setting a timer interrupt up is by using the Timed Interval component (Component Libraries > Math > Timing)
No calculations are necessary :-)
All you need to do is first add a new User Macro for the timer to call when interrupt is triggered.
Then within properties, select the time unit (Days, Hours, Minutes. Seconds, Milliseconds, or Microseconds)
Enter Time Period then finally Use the Callback Macro to select the new User Macro that was created.

Finally Drag the StartTimerInterval component function on to the start of Main (or anywhere suitable).
Timers are apparently my kriptonite.
I tried your advice using the Timed Interval component with no avail.
Timer is set to Milliseconds with 500 as the period.
In the user macro I simply added an output to an LED to toggle with a "!1".
The LED turns on and stays on.
Was hoping it would blink every second.
Any clue what I'm doing wrong?

LeighM
Valued Contributor
Posts: 521
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 89 times
Been thanked: 277 times

Re: Timer or interupt?

Post by LeighM »

"!1" ?
That won't toggle.
As usual, it's best if you can attach your program file, then we can see what exactly you are doing.

hippalator
Posts: 30
Joined: Tue Jul 15, 2025 9:05 pm
Has thanked: 5 times

Re: Timer or interupt?

Post by hippalator »

"!1" ?
That won't toggle.
As usual, it's best if you can attach your program file, then we can see what exactly you are doing.
[/quote]
Screenshot (7).png
Screenshot (7).png (243.41 KiB) Viewed 141 times
LeighM wrote:
Thu Dec 11, 2025 10:11 pm

The idea here is to set up a timer to overflow every half second to trigger a user macro that will toggle an LED.

chipfryer27
Valued Contributor
Posts: 1777
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 396 times
Been thanked: 607 times

Re: Timer or interupt?

Post by chipfryer27 »

Hi

Following on from the posts above, there are indeed countless ways to achieve what you want to do, each with their own merits.

Medelec35 suggested the Timer Interval component and I have attached an example of how it could be used to toggle an LED attached to pin C0 of a PIC16F18877.

You will see that there are two components, an LED on Port C0 and the Timer Interval component set for 500mS to call a UserMacro called Timer.

Main loop enables the Timer and then enters an endless loop which could and should be doing something useful.

Every 500mS the Timer Interval will trigger and the program will branch to the UserMacro Timer.

In here there is a calculation box that sets the value of variable "led". We then output this value to Port C0.

In simulation you will see the led flash, but depending on your simulation speed and of course speed of you PC it may be faster or slower than you expect, and don't forget your PC is doing other things too.

This is just a brief example and it could be done differently.

Regards
Attachments
Example.fcfx
(12.04 KiB) Downloaded 8 times

jgu1
Posts: 880
Joined: Thu Dec 03, 2020 8:25 pm
Location: Denmark
Has thanked: 766 times
Been thanked: 189 times

Flowcode v11 Re: Timer or interupt?

Post by jgu1 »

Thank you Laim, really a usefull examble how the intervaal timer work :D

Jorgen

hippalator
Posts: 30
Joined: Tue Jul 15, 2025 9:05 pm
Has thanked: 5 times

Re: Timer or interupt?

Post by hippalator »

jgu1 wrote:
Fri Dec 12, 2025 6:03 pm
Thank you Laim, really a usefull examble how the intervaal timer work :D

Jorgen
I'm new to the coding world and up until I came across TIMERS I haven't had much difficulty. Nothing I'm doing with the 16f18877 is difficult to begin with.
I have an electronics back ground education since before micro controllers became the main stay. Components and circuits are not a problem for me.
I'll admit defeat, this coding stuff is levels above the learning curve of electronics..... and I'm having a blast learning FC.
This timer stuff is making me scratch my head getting it working.
Sometimes I think I'm over thinking this stuff, especially when someone comes along and makes it look as easy as it really is....lol!

jgu1
Posts: 880
Joined: Thu Dec 03, 2020 8:25 pm
Location: Denmark
Has thanked: 766 times
Been thanked: 189 times

Flowcode v11 Re: Timer or interupt?

Post by jgu1 »

Hi Hippalator!

First of all, I don’t want to hijack the ongoing topic – I just briefly wanted to thank Laim for the excellent example he provided using the timer function. :D
When it comes to programming, I am far from being an expert – especially in C programming. That is exactly why I have been using Flowcode since version 3.0, and I have always been very happy with it.
Once you find the “red thread”, Flowcode is a really great program with many powerful features, especially for those of us who are not hardcore programmers. There are so many well-designed components that make it easy and quick to create programs, even complex ones, and it supports almost all devices. I have created many project with Flowcode.

On top of that, there are many skilled and helpful people in this forum who are always willing to assist.

Even though I have used Flowcode for many years, I still discover new possibilities and still learning, so please keep developing Flowcode – it is truly a pleasure to work with. Hope you see the "ligth" in Laim´s examble too ;)

Br Jorgen

chipfryer27
Valued Contributor
Posts: 1777
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 396 times
Been thanked: 607 times

Re: Timer or interupt?

Post by chipfryer27 »

Hi

I think we have similar backgrounds to an extent. I built my first computer (a kit) back in 77 when about 14 and a few years later progressed to Z80 processor based computers. I programmed in Basic with some assembler / machine code but I was far more interested in getting the computer to interact with the outside world. Why mess with machine code when I could use "Out" and "In" and just decode eight bits of data bus instead of the full address and data busses :)

Around late 90's early 00's microcontrollers were everywhere and I thought best to learn. Flowcode version 3 was out and I took the plunge. Didn't do much other than "play" till v5, when full of bravado I put code into chips (PICs). Without Flowcode I probably would still have entered the world of microcontrollers, via the Arduino route, but I'm glad I didn't. FC is far superior in my opinion and allows me to use different targets with the same code, more-or-less.

The simulation is a great feature. If bored I sometimes open up the laptop and create a "what if" scenario to see if it would work. Very handy if trying to get comms running, such as connecting to wherever for whatever.

There are many tutorials and the Wiki usually has good examples, not forgetting the forums. This one and the "old" one are great resources and a quick search within usually throws some light on a subject. I have to admit though that personally I am no fan of video tutorials as I can read faster than presenter can talk, and life is too short to listen to blah-blah for twenty minutes to either get the snippet you need to know, or realise you have just wasted your time :lol:

Sometimes I will pick a component, make it do something in simulation, then look at doing it a different way...... other people may do crosswords...

If you get stuck with something then the forum usually offers good support. It's a very friendly place and nobody is going to judge anyone for asking a question or doing something in a certain way.

Hope you have success with your timers.

Regards

medelec35
Valued Contributor
Posts: 2205
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 672 times
Been thanked: 751 times

Re: Timer or interupt?

Post by medelec35 »

chipfryer27 wrote:
Fri Dec 12, 2025 3:46 am

Medelec35 suggested the Timer Interval component and I have attached an example of how it could be used to toggle an LED attached to pin C0 of a PIC16F18877.
Thank you for the example.
You can have the simulation speed set to either of the fast options and set the Timer interval simulation delay speed to 500 as that is in milliseconds.
Timer Interval simulation delay.png
Timer Interval simulation delay.png (40.41 KiB) Viewed 52 times
Martin

jgu1
Posts: 880
Joined: Thu Dec 03, 2020 8:25 pm
Location: Denmark
Has thanked: 766 times
Been thanked: 189 times

Flowcode v11 Re: Timer or interupt?

Post by jgu1 »

Thank you Martin, perfect ;)

Post Reply