Hello
Is it possible to create a delay in V4 using variables?
Consider this testprogram:
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
Delay using a variable
Moderator: Benj
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Delay using a variable
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
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
-
- 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
Sorry Ben I don't agree.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.
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
Martin
- 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
Hello
Yes it looks like Medelec is right here
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.
Yes it looks like Medelec is right here
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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
Eric. Your best way to achieve high number delay is the way Ben suggested in a different post:
I know it works because I have use a variable=1520. then created a simple flowchart to give 1520ms delay.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
Martin
-
- 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
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.
- Attachments
-
- large int ms delay.fcf
- (3.5 KiB) Downloaded 362 times
Martin
- 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
Thanks Medelec
I knew I had come up with a better way of doing this before. Must be having a bad day today
I knew I had come up with a better way of doing this before. Must be having a bad day today
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel