CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Less Than and Greater Than

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Geps



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

Less Than and Greater Than
PostPosted: Mon May 16, 2011 3:20 am     Reply with quote

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: 19506

View user's profile Send private message

PostPosted: Mon May 16, 2011 3:37 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon May 16, 2011 3:51 am     Reply with quote

Oops!

I thought I had declared LowerLength, UpperLength.

Sorry!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group