+or-


Closed Thread
Results 1 to 13 of 13

Thread: +or-

  1. #1
    Join Date
    Jan 2004
    Location
    Exeter, England
    Posts
    25

    Default +or-

    Instead of doing two compares to see if a variable is greater or less than something, is there a way of doing a "+ or -" in one command?
    Keep your motor running

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Not equal...

    If PayPacket<>Expectations goto NewJob

  3. #3
    Join Date
    Jan 2004
    Location
    Exeter, England
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Sorry, I didn't really explain it properly.
    I need to check if var2 is between (var2-var1)/2 and (var3-var2)/2 etc.
    Keep your motor running

  4. #4
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Moby,

    Moby>>I need to check if var2 is between (var2-var1)/2 and (var3-var2)/2 etc.<<

    Not sure if I understand fully but...

    if(Abs(Var3-Var2)=(Var3-Var2)) then Do whatever

    This equation will make sure Var2 is lower than Var 3
    Use this equation again with the other variable..

    if(Abs(Var3-Var2)=(Var3-Var2)) &&
    if(Abs(Var2-Var1)=(Var2-Var1))
    Then do something

    This equation makes sure Var2 IS lower than Var3 AND
    Var2 is greater than Var1

    This is written in Psuedo code...but the idea is exactly the same..
    I think in PBP it will look like this:

    if(Abs(Var3-Var2)=(Var3-Var2))
    if(Abs(Var2-Var1)=(Var2-Var1))
    Then do something
    Endif
    Endif

    I am at work, I have no way to check the syntax out.

    Dwayne
    Last edited by Dwayne; - 31st March 2005 at 16:58.
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  5. #5
    Join Date
    Jan 2004
    Location
    Exeter, England
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    That's sort of it Dwayne but not quite. I think it's my inability to explain it that's the problem.
    Imagine a product was made with one of say 5 identity resistors and there are also fake products which use different resistors.
    To determine if the product is genuine you would need to measure the resistor in the product and check to see if it was the same as one of the expected 5, within a certain tolerance.
    I can set an array of the 5 expected values and when I measure the product resistor I want then to check it against the array values. It's simplifying that process that I can't quite work out.

    (Just to say, the actual resistance doesn't need to be calculated, I just work on raw adc readings, having done measurements with a resistance box.)
    Keep your motor running

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    my suggestion, take a/d reading of your expected resistors. store these value in the internal eeprom, in an array or variables. allow a error %,

    your program must compare your product reading to all your value store in array, internal eeprom or variables with your error %.

    what are your target resistors values???
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Moby,

    Real var byte
    Test1 var byte
    Test2 Var byte
    Test3 var byte
    Test4 var byte
    Test5 var byte

    if (abs(Read-Test1)less than Tolerance) then output REAL items!

    if (abs(Read-Test2)less than Tolerance) then output REAL items!

    if (abs(Read-Test3)Less than Tolerance) then output REAL items!

    if (abs(Read-Test4)Less than Tolerance) then output REAL items!

    if (abs(Read-Test5)less than Tolerance) then output REAL items!

    I had to type in Less than, instead of using the sign, because of the
    html coding.

    There you go!!

    Dwayne
    Last edited by Dwayne; - 31st March 2005 at 16:23.
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  8. #8
    Join Date
    Jan 2004
    Location
    Exeter, England
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Thanks folks. I think Dwaynes answer is the way to go. I will try it and let you know how I get on.
    Keep your motor running

  9. #9
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    The way that works is the following.

    Lets say we are checking resisters, and need to know if they are within a certain tolerance....

    say within 5 pecent....

    Your known resistance is 1000 OHMS, and 5 percent is 50 ohms

    The ABS function works as the following:

    Lets say TEST is 1500 homes

    ABS(test-1000)=500

    Thus If (test-1000)<50 then output good resistor! (but its not less than 50)

    Lets say TEST=900


    ABS(test-900)=100 (if the value is negative, it changes to postive)

    Thus If (test-1000)<50 then output good resistor! (but its not less than 50)


    Lets say TEST = 970
    ABS(test-1000)=30

    Thus If (test-1000)<50 then output good resistor! (Wonderful!! good part)

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  10. #10
    Join Date
    Jan 2004
    Location
    Exeter, England
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    I had never thought about the ABS function before. Many thanks, it appears to work fine.
    Keep your motor running

  11. #11
    Join Date
    Jan 2004
    Location
    Exeter, England
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Well, I thought it worked fine. Now having added actual code to my prgramme I can't get it to compile. It gives an error "bad expression or missing then" for the line with ABS in it:

    For word_no=0 to res_max
    if (abs(adval-id_res[word_no]))<=((id_res[word_no]*res_tol)/100) then
    answer=ok
    goto endsub
    endif
    next word_no

    Am I doing something stupid?


    Edit: It's alright. I just forgot how to do arrays!!!! Seems OK now.
    Last edited by moby; - 5th April 2005 at 11:51.
    Keep your motor running

  12. #12
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Moby,


    Moby>>if (abs(adval-id_res[word_no]))<=((id_res[word_no]*res_tol)/100) then

    I believe you have 1 too many parentheses <sp> on your if statement...
    lets divid it up a little ok??

    yours:
    if (abs(adval-id_res[word_no]))<=((id_res[word_no]*res_tol)/100) then

    Divided up:

    if (abs (adval-id_res[word_no]) ) <=((id_res[word_no]*res_tol)/100) then


    if you notice, your ending parenthises <sp> end before your less than or equal sign....
    It probably should look like this:
    if(XXXXX<=YYYY) then zzzz

    if ( abs(adval-id_res[word_no]) <=((id_res[word_no]*res_tol)/100) ) then

    Another format is
    if xxxxx<=yyyyy then zzzz

    if abs(adval-id_res[word_no]) <=((id_res[word_no]*res_tol)/100) then

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  13. #13
    Join Date
    Jan 2004
    Location
    Exeter, England
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Yes, I think that was another problem. It does seem to be working now.
    Thanks.
    Keep your motor running

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts