Shop OBEX P1 Docs P2 Docs Learn Events
Controling RCTIME — Parallax Forums

Controling RCTIME

vinnyirlvinnyirl Posts: 6
edited 2009-04-29 07:43 in BASIC Stamp
BS2

In the project I am working on I am comparing two RCtime values. Both of the values are between 100 and 600. I want to compare these two values and move a motor which will attempt to make the values the same. The problem I am having is that of course the values will never be the same so I need to allow for some allowed error.

I am trying to do this with IF statements by saying if a value is between say 200 and 300 then the value is 250, this would mean for any value between 200 and 300 the real value would be 250. This would stop the problem as the variables would need to change a lot before something happens.

The if statement I tried to use (and its wrong) was

IF man >=200 AND man <300 THEN man =250

My problem is trying to get the if statement to make sure two values are true and I cannot seem to be able to do this.

Thanks

Post Edited (vinnyirl) : 4/29/2009 3:01:59 AM GMT

Comments

  • FranklinFranklin Posts: 4,747
    edited 2009-04-29 03:12
    If you attach your code to a message it would be helpful in debugging. If man is byte data then man can only be 254 or less.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • vinnyirlvinnyirl Posts: 6
    edited 2009-04-29 05:04
    Well all I really need to know is if it is possible to make an IF statement where two things need to be true to allow the statement to work as in

    IF (statement 1) AND (statement 2) THEN do stuff

    I have moved away from if statements in my program, I am now trying PID control http://forums.parallax.com/forums/?f=5&m=347572&g=347572#m347572
    although this is still unsuccessful

    a copy of my program

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}


    '
    Define variables, set status of pins

    x VAR Word
    cnt VAR Word
    RC PIN 0
    man VAR Word
    cont VAR Word

    '
    Constant declarations

    S0 PIN 11 'Sensitivity selection pins
    S1 PIN 10
    IN PIN 9 'TSL230 output pin

    '
    Program Start
    start:
    IF IN2 = 0 THEN GOTO main
    IF IN2 = 1 THEN GOTO start
    GOTO start

    main:

    LOW S0 'Set sensitivity pins (S0,S1) to x10
    HIGH S1

    '
    FLC

    COUNT IN, 100, cnt 'COUNT on P2 FOR 100 ms, store value in cnt
    IF cnt <150 THEN cnt =105
    PAUSE 100
    DEBUG HOME, DEC3 cnt 'Display value of cnt, as a decimal

    '----Manual Adjust----
    HIGH RC ' charge the cap
    PAUSE 100 ' for 1 ms
    RCTIME RC, 1, man ' measure RC discharge time
    IF man <150 THEN man =105
    DEBUG CR, DEC man,CR ' display value
    PAUSE 1

    '---PID---

    cont = cnt - man
    DEBUG DEC3 cont

    '---Compare---
    IF cont = 0 THEN off
    IF cont < 50 THEN left
    IF cont > -50 THEN right


    GOTO start

    off:
    LOW 6
    LOW 7
    GOTO start

    left:
    HIGH 6
    HIGH 7
    GOTO start

    right:
    HIGH 6
    LOW 7
    GOTO start
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-04-29 07:43
    Yes, possible:
    > IF (statement 1) AND (statement 2) THEN do stuff

    The syntax of your original statement is fine and will change a starting value in the range of 200 to 300 to a final value of 250.
    > The if statement I tried to use (and its wrong) was
    > IF man >=200 AND man <300 THEN man =250
    > My problem is trying to get the if statement to make sure two values are true and I cannot seem to be able to do this.

    and in what sense is it "wrong"?

    The new program also uses plenty of IF statements, but one thing you can't do in Stamp logic is negative numbers as in
    > IF cont > -50 THEN right <--- won't work like you expect

    The compare logic does not make sense in the program. Partly because it is comparing a COUNT value with an RCTIME value, and I don't see the physics behind that. Also because any cont value between -50 and 50 satisfies the conditions to go both left and right.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.