BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 12:22 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: min max commands
PostPosted: Tue Nov 02, 2010 3:51 pm 
Offline
Guru

Joined: Fri Nov 13, 2009 10:28 am
Posts: 82
Location: Reno, Nevada
Is there a way to assign a min value and a max value to a single variable?
ie- x can have a maximum value of 1000 and a minimum value of 500.

_________________
Harley


Top
 Profile  
 
 Post subject: Re: min max commands
PostPosted: Tue Nov 02, 2010 10:26 pm 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
Hello, Harley.
You mean like in a modifier that holds a variable within a range? Not that I know of.
However, you can always create two variables, x-MIN and x-MAX, preassign the "legal" values in the range, then perform an IF-THEN conditional to hold x in that range.
Code:
x var word
x-MIN var word
x-MAX var word
x-MIN = 500
x-MAX = 1000

MAIN
... some code ...
;After we collect some data or input a value, we do the following range check:
IF x > x-MAX then  ; is x > 1000?
x = x-MAX  ; make x = 1000
ELSE
IF x < x-MIN then  ; is x < 500?
x = x-MIN   ; make x = 500
ENDIF

GOTO MAIN  ; repeat all this

Basically we have asked if x is greater than 1000 or become less than 500. If either is true (out of range) we then set x to its range limits, which in this example is 500 for the low side or 1000 for the high side. The IF-THEN conditional would likely be a subroutine so it would be available to multiple routines changing the value in x, in which case we have a "RETURN" after the "ENDIF".
Make sense?
Have a nice project.

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: min max commands
PostPosted: Wed Nov 03, 2010 9:09 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
or you can use the min and max math functions.

temp = value max 1000 ;limit temp to a maximuim of 1000 when copying value to temp.

temp = value min 100 ; limit temp to a minimum of 100 when copying value to temp.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: min max commands
PostPosted: Wed Nov 03, 2010 2:09 pm 
Offline
Guru

Joined: Fri Nov 13, 2009 10:28 am
Posts: 82
Location: Reno, Nevada
Thanks for the suggestions. I ended up using kenjj's method and it worked well for my application.

_________________
Harley


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO