Delay using a variable

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Delay using a variable

Post by Eric »

Hello

Is it possible to create a delay in V4 using variables?
Consider this testprogram:

snap0210.jpg
snap0210.jpg (22.91 KiB) Viewed 8260 times

I need a delay with a value depending on certain conditions.
So I attributed the variable "delay" with the value 1000 ms.
In the delay icon I use this variable to generate my delay.
The problem I have is that if I want a delay of eg 1000 ms, the real delay on hardware seems always to be a delay of 250 ms.
Every value greater than 250 seems to generate the same delay of 250 ms.
If I don't use the variable " delay" but enter 1000 directly in the delay icon, the delay is ok.
Are there other ways to generate a delay using a variable?

Regards,

Eric

fresh
Posts: 47
Joined: Mon Jun 08, 2009 11:11 am
Contact:

Re: Delay using a variable

Post by fresh »

Is your variable = BYTE or INT ?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Delay using a variable

Post by Benj »

If your variable is a byte then you are assigning the following

byte = 1000 which actually equals 1000 MOD 255 which is 235.

You can go into the variable manager by clicking Edit -> Variables and then use the rename vairable button to convert the variable from a byte to an int. Your calculation will then correctly assign the value 1000 to the variable.

Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Re: Delay using a variable

Post by Eric »

That was my first idea too, but the variable is effectively type INT.
I also need to say that it simulates well in Flowcode ( it simulates 1 sec ), but in real hardware it doesn't work correct.
Maybe somebody can try it on his hardware to verify this.

Rgds,

Eric

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Delay using a variable

Post by medelec35 »

Benj wrote:You can go into the variable manager by clicking Edit -> Variables and then use the rename vairable button to convert the variable from a byte to an int. Your calculation will then correctly assign the value 1000 to the variable.
Sorry Ben I don't agree.
if you assigned Variable to int, the delay will still only last for 220ms and not 1000ms (unless I am missing something?)
Has to be 10 loops of 100ms.

If I am wrong, will say sorry later :P
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Delay using a variable

Post by Benj »

Hello

Yes it looks like Medelec is right here :oops:

The problem is that the boostC delay function only allows a byte parameter. When you give flowcode a fixed delay eg 1000 ms then it breaks this down into a series of calls that all use bytes. If you are using a variable value then Flowcode cannot do this correctly.

My suggestion would be to divide your delay value by 10 and then create a loop that runs 10 times. Inside the loop add your delay icon and your program should then run correctly on the hardware and the simulation. Alternativley replace the 10 with a number that yields delays no larger then 255ms.

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Delay using a variable

Post by medelec35 »

Eric. Your best way to achieve high number delay is the way Ben suggested in a different post:
Benj wrote:When using a variable delay you can do something similar to the following where delayval is your INT delay variable.

calc: delayval = 800

loop: delayval > 255
{

delayms: 255

calc: delayval = delayval - 255

}

delayms: delayval
I know it works because I have use a variable=1520. then created a simple flowchart to give 1520ms delay.
Martin

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Delay using a variable

Post by medelec35 »

Here you are. based on Bens idea. You can enter a larger value variable for a delay. In the example I have set delay variable for 1000, giving a delay of 1000ms.
large Var Delay.JPG
large Var Delay.JPG (17.08 KiB) Viewed 8181 times
Attachments
large int ms delay.fcf
(3.5 KiB) Downloaded 362 times
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Delay using a variable

Post by Benj »

Thanks Medelec

I knew I had come up with a better way of doing this before. Must be having a bad day today :mrgreen:

Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Re: Delay using a variable

Post by Eric »

Thanks guys, this helps a lot.

Regards,

Eric

Post Reply