Shop OBEX P1 Docs P2 Docs Learn Events
Why isn't less than working for me? — Parallax Forums

Why isn't less than working for me?

ghost13ghost13 Posts: 133
edited 2007-08-20 13:26 in BASIC Stamp
Hi,
I am building an altimeter for rocketry, and when the rocket reaches the peak of its flight (apogee), it should beep out the altitude. I am trying to do this by getting the altitude and then checking if the current altitude is less than the previous altitude (the rocket is falling). This is not working, however. The altimeter thinks it has reached apogee as soon as it is turned on.
Thanks in advanced for your help!

PS: code is attached.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-20 04:55
    What are the values you're testing in the IF statement (using DEBUG)? Are they correct? Are they what you expect?
  • ghost13ghost13 Posts: 133
    edited 2007-08-20 05:25
    During ground reading:
    Sensor VOUT = 368 millivots (960')
    Altimeter output = 960'

    After ground reading (PYRO is called):
    Sensor VOUT = 368 millivots (960')
    Altimeter output = 5' (which means that PYRO should never have been called because of the noise-reduction code.)

    The values are as expected... the altitude is not changing, but "Pyro" is still being called.
    Thanks!
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-20 06:05
    That's not what I mean. Glancing at you code ... I'm guessing that the IF statement is the "IF feet < prev THEN Pyro"

    My question was: What were the values of feet and prev? They're probably wrong and you'll have to trace back to find out why.

    In debugging, you start with the observed resulting action. You're not debugging the BS1 ... That's assumed to work, much like you normally assume that your processor and memory for your PC are working. If the IF is doing the wrong thing, your data must be wrong. You want to verify that, then work backwards to see where the data came from. You can also work forward from known good data.
  • ghost13ghost13 Posts: 133
    edited 2007-08-20 08:23
    I modified my board to hook up to the serial cable... and I found my problem! It works perfectly, and then I get this:
    FEET = 15
    PREV = 0
    FEET = 15
    PREV = 65531

    I assume 65531 is the variable being maxed out, and that is why the if statement is returning true. Nothing changes... and then I get that data. Any ideas?

    Thanks!

    EDIT: After some more testing, I realized that Prev is always being maxed out! I tried resetting AD to zero in the Convert subroutine, but it didn't do a thing [noparse]:([/noparse]

    Post Edited (ghost13) : 8/20/2007 8:33:48 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-20 13:26
    65531 is the same as -5 in 16 bit arithmetic. You're calculating "prev = feet - 20" which, in this last case, is -5.

    Maybe you should check for "feet < 20" and set "prev = 0" in that case.
Sign In or Register to comment.