Hello
I am trying to use delay values in seconds and part second values to 2 decimal places for example 2.15 . How can i enter this value for a delay.
Thank you
Values for delay timer
- Steve
- Matrix Staff
- Posts: 3422
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
If you have a constant delay time, you can simply use a 2s delay followed by a 150ms delay.
If you have this delay time as a variable, you need to be a little clever. The value of a variable passed to the delay icon must be between 0 and 255, so you will need to do a little bit of work...
I will assume you have 2 variables, SEC for the second part of the delay and FSEC for the fractional part of the delay (a value between 0 and 99, meaning 0 to 990 ms). You could create a new macro which contains the following in a 'C' code icon:
There will be other methods, but this should work (although I haven't tried it).
An alternative approach would be to have your delay variable contain a number between 0 and 255, where each increment of this variable represents a whole number of milliseconds. This approach depends on your required maximum value for the delay. Here's an example which will hopefully explain what I mean:
A "DELAY" value of 1 could represent 8ms. In which case, your maximum delay available would be 8*255 = 2.04 seconds. Your code for the delay would then be 8 consecutive delay (ms) icons, each with the "DELAY" variable as a parameter.
This second appropach has the advantage of being simpler to code (it avoids 'C'), but it does mean that the variable does not equate to a convenient delay time (for example, if DELAY=100, the actual delay would be 0.8 seconds).
I hope this helps.
If you have this delay time as a variable, you need to be a little clever. The value of a variable passed to the delay icon must be between 0 and 255, so you will need to do a little bit of work...
I will assume you have 2 variables, SEC for the second part of the delay and FSEC for the fractional part of the delay (a value between 0 and 99, meaning 0 to 990 ms). You could create a new macro which contains the following in a 'C' code icon:
Code: Select all
//delay the whole number of seconds
delay_s(FCV_SEC);
//delay the fractional part
if (FCV_FSEC >= 80)
{
delay_ms((FCV_FSEC - 80) * 10);
delay_ms(200);
delay_ms(200);
delay_ms(200);
delay_ms(200);
} else if (FCV_FSEC >= 60) {
delay_ms((FCV_FSEC - 60) * 10);
delay_ms(200);
delay_ms(200);
delay_ms(200);
} else if (FCV_FSEC >= 40) {
delay_ms((FCV_FSEC - 40) * 10);
delay_ms(200);
delay_ms(200);
} else if (FCV_FSEC >= 20) {
delay_ms((FCV_FSEC - 20) * 10);
delay_ms(200);
} else {
delay_ms(FCV_FSEC * 10);
}
An alternative approach would be to have your delay variable contain a number between 0 and 255, where each increment of this variable represents a whole number of milliseconds. This approach depends on your required maximum value for the delay. Here's an example which will hopefully explain what I mean:
A "DELAY" value of 1 could represent 8ms. In which case, your maximum delay available would be 8*255 = 2.04 seconds. Your code for the delay would then be 8 consecutive delay (ms) icons, each with the "DELAY" variable as a parameter.
This second appropach has the advantage of being simpler to code (it avoids 'C'), but it does mean that the variable does not equate to a convenient delay time (for example, if DELAY=100, the actual delay would be 0.8 seconds).
I hope this helps.