8 years, 2 months ago.

Is it possible to attach a timeout period as a variable in timeout()

Hi

I'm having a problem with timeout() on mBed LPC1768; if I set

flag1.attach(&set1, 10.0);

then this works fine. But if I do:

flag1.attach(&set1, T1);

where TI has previously been declared as a float and initialised to 10.0, then the timeout does not work - the activity at the end of the desired timing period doesn't happen (program compiles without error).

Thanks for any advice.

Gerry

Question relating to:

That should work fine. Can you post the full code or at least some context showing the function and variable definitions? Use <<code>> and <</code>> to maintain the formatting so that it's readable.

posted by Andy A 10 Feb 2016

Declarations used:

Timeout flag1; float T1;

posted by Gerry McMahon 10 Feb 2016

<<code>>

Re problem with timeout() on mBed LPC1768; code extracts:

Timeout flag1; float T1, RC;

RC = 50.0;

....

T1 = 0.1 * 2.0 * RC;

....

flag1.attach(&set1, T1);

with separately defined set1 function which sets an mBed Pin to logic H.

The above code produces no activity on teh pin. However if I change the last line to

flag1.attach(&set1, 10);

then the code works as desired. I just can't see where the problem is at the moment.

Thanks for any advice.

Gerry

<</code>>

posted by Gerry McMahon 11 Feb 2016

<code>

Re problem with timeout() on mBed LPC1768; code extracts:

Timeout flag1; float T1, RC;

RC = 50.0;

....

T1 = 0.1 * 2.0 * RC;

....

flag1.attach(&set1, T1);

with separately defined set1 function which sets an mBed Pin to logic H.

The above code produces no activity on teh pin. However if I change the last line to

flag1.attach(&set1, 10);

then the code works as desired. I just can't see where the problem is at the moment.

Thanks for any advice.

Gerry

</code>

posted by Gerry McMahon 11 Feb 2016

I have no idea why it's not working. As a sanity check can you add a a printf to output the vale of T1 when it does the attach?

BTW if you edit a comment after posting it you get a bigger edit box and a preview button, handy for getting the syntax highlighting to work. I gave up trying to work out the logic behind some of the design on this site a long time ago.

posted by Andy A 12 Feb 2016

Andy I followed your advice and found that T1 was set to zero! Checking the code carefully I found that while I had declared T1 as a global variable at the start of the code, I also redeclared the variable, in error, in main() - so presumably the global value was not then the same as that in main(). The actual value of T1 was set in main().

It's all working properly now. Many thanks for your help, Andy - it's much appreciated.

Gerry

posted by Gerry McMahon 14 Feb 2016
Be the first to answer this question.