Page 1 of 1

Delay component when variable used and variable value is 0

Posted: Mon Apr 02, 2007 3:09 pm
by Mark
Hi,

I seem to have found a problem when a Delay component is used and when the delay is a variable and the variable value is 0. The Delay either lasts too long or an enless loop is created (I'm not sure which).

The quick fix is a check to make sure the variable is not zero, however, as the delay is a user input variable and no delay is a realistic option to choose it would make for cleaner coding if a variable holding a value of 0 could be used?

Or is there a likely bug in my code?

Thanks,

Mark

Posted: Mon Apr 02, 2007 3:45 pm
by Benj
Hello Mark

You could have the delay in a desicion branch and only call the delay if the variable is greater then 0

Eg

if var1 > 0

Yes delay for var1

No carry on with program.

I think if you pass a value of 0 it will instantly rollover and give the maximum possible delay eg. 65536 seconds or milliseconds.

Posted: Tue Apr 03, 2007 8:39 am
by Steve
If you are concerned about this, there is a permanent fix you can apply. The FCD files define how these delays work - have a look at the DelayCmdS and DelayCmdMs entries in the "Code" section.

At the moment these are as follows:

Code: Select all

DelayCmdS="delay_s(%o);\n"
DelayCmdMs="delay_ms(%o);\n"
Altering them to this would fix this issue:

Code: Select all

DelayCmdS="if (%o > 0) delay_s(%o);\n"
DelayCmdMs="if (%o > 0) delay_ms(%o);\n"
Do you think I should make this change in all FCD files in the next release?

Posted: Tue Apr 03, 2007 9:33 am
by Mark
Steve,

Thanks for that.

I agree that a change in the next release will be a good move. Not only is the benefit of having a 'delay' of 0 greater than having 65536 (when 65535 is available) but the novice may be mystified by the concept of rollover and 65536.

regards,

Mark