![]() |
Re: Delay code isn't delaying.
Quote:
|
Re: Delay code isn't delaying.
It looks like you might be being bitten by C18's habit of doing single byte arithmetic. In your if statement cast WAITING_TIME and LOOPS_IN_A_SECOND to int.
For example: if(auton_counter < (int) WAITING_TIME * (int) LOOPS_IN_A_SECOND){ //wait C18 is most likely currently treating them as single byte numbers - so 8 x 38 is 304, which overflows to become 48. (Which would only give you about a 1 second wait.) |
Re: Delay code isn't delaying.
Quote:
|
Re: Delay code isn't delaying.
I know this sound trivial, and it "should" work the way you have it, but....
Try changing Code:
if(auton_counter < WAITING_TIME * LOOPS_IN_A_SECOND)Code:
if(auton_counter << (WAITING_TIME * LOOPS_IN_A_SECOND)) |
Re: Delay code isn't delaying.
Quote:
|
Re: Delay code isn't delaying.
Quote:
|
Re: Delay code isn't delaying.
Quote:
Code:
if(auton_counter < WAITING_TIME * LOOPS_IN_A_SECOND){ //waitCode:
if (auton_counter < WAITING_TIME * LOOPS_IN_A_SECOND)If you prefer terseness, here is a common idiom for such counters: Code:
if (auton_counter++ < WAITING_TIME * LOOPS_IN_A_SECOND) |
Re: Delay code isn't delaying.
Quote:
Quote:
|
Re: Delay code isn't delaying.
Since integer promotion isn't enabled by default, and those preprocessor macros are effectively just search-and-replace, the calculations would not give the expected result. Casting them correctly and using parentheses generously should fix this, as previously stated.
|
| All times are GMT -5. The time now is 20:23. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi