View previous topic :: View next topic |
Author |
Message |
Geps
Joined: 05 Jul 2010 Posts: 129
|
Less Than and Greater Than |
Posted: Mon May 16, 2011 3:20 am |
|
|
Hi,
I'm creating a function, that using the CCP module will return a 1 or 0 depending on when a pulse matching a certain duration is received.
I'm getting the pulse width values but can't carry out the comparison successfully.
Code: |
int1 wait_for_positive_pulse_in_us(int16 UpperLength, int16 LowerLength){
int1 LeaveLoop = 0;
int16 PulseWidthUS = 0;
.
.
.
.
.
printf("PulseWidth:%Lu\n",PulseWidth);
printf("Lower Length:%Lu\n",LowerLength);
printf("Upper Length:%Lu\n",UpperLength);
if ((LowerLength < PulseWidthUS) && (PulseWidthUS < UpperLength)){
LeaveLoop= 1;
printf("Loop");
}
GotPulseWidth = FALSE;
}
.
.
.
.
.
} |
Shows this on my terminal:
Quote: | Upper Length:2
PulseWidthUS:538
Lower Length:7000
Upper Length:2
PulseWidthUS:290
Lower Length:7000 |
Any ideas?
Cheers, |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19516
|
|
Posted: Mon May 16, 2011 3:37 am |
|
|
So what is unsuccessful?.
For the values you give, 'LowerLength', is greater than 'PulseWidthUS', so the loop print won't occur. Correct for the code you show...
Your test can never go true, since UpperLength is less than LowerLength.
Best Wishes |
|
|
Geps
Joined: 05 Jul 2010 Posts: 129
|
|
Posted: Mon May 16, 2011 3:51 am |
|
|
Oops!
I thought I had declared LowerLength, UpperLength.
Sorry! |
|
|
|