Implementing a non blocking delay

For general Flowcode discussion that does not belong in the other sections.
chipfryer27
Valued Contributor
Posts: 1861
http://meble-kuchenne.info.pl
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

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

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 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

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

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

Regards

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

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

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

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

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

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 25 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

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

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 »

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

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

I will look later once back at a PC

Regards

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

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
Attachments
Thermaltimingjan_Example.fcfx
(23.11 KiB) Downloaded 29 times

Post Reply