Page 4 of 6

Re: Implementing a non blocking delay

Posted: Thu Jan 22, 2026 3:26 pm
by chipfryer27
Hi

I had to delete all your 3D panel components as they were confusing, being duplicates of 2D.

I am not at a PC, but easy to implement switch off by having counter one test. It switches on at 150 (2 seconds) so test again for 175 (OK so that is around an extra 333mS) and switch off.

I can modify my example but not until later.

Regards

Re: Implementing a non blocking delay

Posted: Thu Jan 22, 2026 4:10 pm
by mvictor
I put a test condition at 175 and gave a switch off. But the outputs (LEDs in this program's case) continously keep turning off and on.

Regards

Re: Implementing a non blocking delay

Posted: Thu Jan 22, 2026 4:55 pm
by chipfryer27
Hi

Are you using AND in your decision (&&) icon?

Regards

Re: Implementing a non blocking delay

Posted: Thu Jan 22, 2026 5:05 pm
by mvictor
Hi

No. I haven't used AND in my decision icon, to what am I supposed to AND it with?

Re: Implementing a non blocking delay

Posted: Thu Jan 22, 2026 5:16 pm
by chipfryer27
Hi

If you look at my example and previous post you will see that we have (for each switch) three variables.

Count 1 is a simple counter.
Sw1 is status of switch 1 (on/off)
Trig1 let's us know if Sw1 has been/is switched.

Initially everything is at "0"

Counter increments in background.

You press the button and Sw1=1

In the decision box we branch only if Sw1=1 AND Trig1=0

In the branch we reset Count1 to 0 and set Trig1 to 1. This prohibits the counter being reset during next loop if the Switch is still on.

Later we test for Count1 to equal our value (150). We branch only if Count1=150 AND Trig1 = 1. This prevents the branch just if the counter reaches the value.

Of course you should also include a way to reset the above once whatever you want to happens has occurred. Without knowing more about your application there are many possibilities.

Is it a momentary button press / is it from an MCU that will go low after a condition / etc.

Regards

Re: Implementing a non blocking delay

Posted: Thu Jan 22, 2026 5:26 pm
by mvictor
Hi

The signal is from PLC which will only give a momentary trigger from its relay output and go low. It is basically recording temperature from my thermal camera and giving the respective output in form of momentary trigger.

The problem I face in the program is my outputs B5, B6 and B7 don't stay low. Like it is supposed to momentarily go high and turn off which it is not doing for some reason.

Uploading the latest code for guidance.

Regards
Thermaltimingjan_Example1.fcfx
(23.34 KiB) Downloaded 28 times

Re: Implementing a non blocking delay

Posted: Thu Jan 22, 2026 5:31 pm
by chipfryer27
Hi

So it is normally low, and goes high before returning low. How long roughly is it high? As it is a relay you will need to take switch bounce into consideration either in software or physically.

Regards

Re: Implementing a non blocking delay

Posted: Thu Jan 22, 2026 5:54 pm
by mvictor
Hey

The relay bounce time is generally 5ms being a mechanical relay, but online it is suggested to use a software debouncing of 20ms.

It should be high for roughly 200ms but I’m not sure as that I’ll need to test it and amend accordingly.

What I am currently stuck at as the outputs not actually behaving like expected hence I uploaded the program. I have a crystal oscillator of 10Mhz on my PCB, so I’ve set the speed accordingly.

Regards

Re: Implementing a non blocking delay

Posted: Thu Jan 22, 2026 6:40 pm
by chipfryer27
Hi

I will look later once back at a PC

Regards

Re: Implementing a non blocking delay

Posted: Thu Jan 22, 2026 8:45 pm
by chipfryer27
Hi

This example turns on a led after x-seconds, then off after a further y-seconds, resetting trigger so it can run again.

Hope this helps