Implementing a non blocking delay

For general Flowcode discussion that does not belong in the other sections.
mnfisher
Valued Contributor
Posts: 1812
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 152 times
Been thanked: 853 times

Re: Implementing a non blocking delay

Post by mnfisher »

Very quick change to no components - use View->Digital pins and change A4 to 1 to start the timer - B5 will change to 1 after delay then revert to 0....

As mentioned above - it would be better to make the pins properties.. But no timer before work :-(

Mqrtin
Attachments
non_blocking.fcfx
(10.69 KiB) Downloaded 29 times

mnfisher
Valued Contributor
Posts: 1812
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 152 times
Been thanked: 853 times

Re: Implementing a non blocking delay

Post by mnfisher »

The input should just be A4 - not sure I saved it with this?

mvictor
Posts: 24
Joined: Thu Aug 25, 2022 7:46 am
Has thanked: 3 times
Been thanked: 1 time

Re: Implementing a non blocking delay

Post by mvictor »

Thermaltimingjan26_v9_2.fcfx
(31.4 KiB) Downloaded 33 times
I gave my program a try referring to Mar tin's, although I got the interrupt to work for one condition. What I am trying to do is when my A4 goes high, output port B5 should go high after 2 seconds. I have three inputs A4, A0 and A1 which i need to configure to make B5, B6 and B7 go high at respective seconds, say 2,3 and 4 seconds without blocking the program since it needs to check input ports for high trigger. I think I am missing something somewhere, could anyone help me figure out what it is? SInce my output B5 is giving not a pulse signal.

mnfisher
Valued Contributor
Posts: 1812
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 152 times
Been thanked: 853 times

Re: Implementing a non blocking delay

Post by mnfisher »

What did you try - my code as is, or something changed?

If we can get it to work for one input/output - the other two are just a cut and paste operation (and two new variables per LED)

Martin

mvictor
Posts: 24
Joined: Thu Aug 25, 2022 7:46 am
Has thanked: 3 times
Been thanked: 1 time

Re: Implementing a non blocking delay

Post by mvictor »

I tried my own program referring to yours. I am a bit confused with the ISR part since I know I must not use a delay in that macro. The challenge is how do I make it count that many seconds and how to give a pulse output signal at B ports without the delay. In usual cases I use Output block as B5 to 1, a delay of 300ms and then Output block as B5 to 0.

mvictor
Posts: 24
Joined: Thu Aug 25, 2022 7:46 am
Has thanked: 3 times
Been thanked: 1 time

Re: Implementing a non blocking delay

Post by mvictor »

Thermaltimingjan26_v9_2.fcfx
(31.8 KiB) Downloaded 33 times
Attaching my latest program attempt, please have a look and let me know. Ive set my timer to 75Hz.

mnfisher
Valued Contributor
Posts: 1812
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 152 times
Been thanked: 853 times

Re: Implementing a non blocking delay

Post by mnfisher »

My code has a 'count' of interrupts for on (set in main) and then to turn off (set in the ISR) - I used arbitrary times (a count of 10) - to allow simulation.

ie:

Pin HIGH - starts timing (sets count to '10') (note ISR runs continually) The time should be as required.
ISR counts down - the ISR toggles the output (it handles on and off) - so if it has turned the LED on (led_state) then it sets an 'off' timer.

Can you post your code again - and we can take look - whilst I was typing you did :-)

mvictor
Posts: 24
Joined: Thu Aug 25, 2022 7:46 am
Has thanked: 3 times
Been thanked: 1 time

Re: Implementing a non blocking delay

Post by mvictor »

Reposting my program again :)
Could you take a look and lemme know what is missing? You are free to make changes and corrections as needed.... that'd really help :D
Thermaltimingjan26_v9_2.fcfx
(31.8 KiB) Downloaded 34 times

chipfryer27
Valued Contributor
Posts: 1861
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 407 times
Been thanked: 632 times

Re: Implementing a non blocking delay

Post by chipfryer27 »

Hi

Martin beat me to a reply.

Attached is a far less elegant example, which I hope sort of explains the "thought".

In this:-

We have three Counters 1 - 3. These increment at 75Hz
We have three Switch states 1-3, Status of the three switches
We have three Trigger states 1 - 3. These indicate if the Switch has been triggered / already triggered.

We have a main loop.

Before the loop we enable a Timer (75Hz). In the ISR we increment three counters (Count1 / Count2 / Count3)

In the Main loop we test for each switch being active.

If Switch1 is active AND Trigger 1 is inactive we branch

When we branch we reset Counter1 and set Trigger 1 as active

Later we test Counter 1 to be a value (multiples of 75 for each second) and if the value is reached (or exceeded) AND Trigger 1 is active we branch to illuminate the LED.

We use Trigger 1 variable to both Stop multiple resets of the counter and also to stop the counter illuminating the LED if the switch hasn't been triggered,

Same for 2 and 3

Clearly not a finished product but hopefully explains the thought behind it. Many ways to do as you are after so maybe this and Martin's will give you some ideas. Martin's will be better than mine for sure.... :lol:

Regards
Attachments
Thermaltimingjan_Example.fcfx
(21.47 KiB) Downloaded 35 times

mvictor
Posts: 24
Joined: Thu Aug 25, 2022 7:46 am
Has thanked: 3 times
Been thanked: 1 time

Re: Implementing a non blocking delay

Post by mvictor »

Hi,

Tried fryer's example and applied my logic of switching, i mean turn on say port B5 when A4 is given a high trigger. But when I give high trigger to A0 and A1, it is interfering with my B5 (the corresponding port which it is not linked to). What I am trying to do is, when A4 is given high trigger, B5 will momentarily turn on and after a 300ms delay it will turn off. The same goes for ports B6 and B7 on getting high trigger from A0 and A1.

The thing is output ports B5, B6 and B7 need to work independently. Like say,
A4 is given high, then after 2 seconds B5 is momentarily high n turns off.
A0 is given high, then after 3 seconds B6 is momentarily high n turns off.
A1 is given high, then after 4 seconds B7 is momentarily high n turns off.

But in my case the Port B outputs are continuously turning on and off in simulation.

Uploading my code for guidance. Thank you for all the help.
Thermaltimingjan_Example1.fcfx
(23.14 KiB) Downloaded 29 times

Post Reply