Shop OBEX P1 Docs P2 Docs Learn Events
Help! My program doesn't work as expected. — Parallax Forums

Help! My program doesn't work as expected.

Chuck E.Chuck E. Posts: 14
edited 2007-07-24 16:21 in BASIC Stamp
Attached is the code. I have 10 relays that connect a sensor array to an amplifier, the output of which is connected to an ADC.
I have commented out the save routine until I can get this part working. The way it's SUPPOSED to work is to energized each relay in turn, convert the result and load it into a slot on the RTC RAM. It should do each relay in turn, wait a minute, then start over. On the Debug window it only writes this:

RTC RAM cleared
0

Then adds "getting signal" to the line after the "0". This repeats every 2 seconds instead of incrementing through the relays.

So, all you software gurus, what did I do wrong?

After this is working I will add the data save routine that will read the data from RTC RAM and load it into a data logger.

Thanks,

Chuck

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2007-07-23 14:01
    Depends on how you're powering the relays.

    What you're showing is a classic symptom of "brown-out reset" -- meaning your power supply doesn't have sufficient current capacity to power both the BS2 and the relay at the same time (relays are a bit power hungry). As a result, the voltage from your power supply 'drops', the BS2 detects this and resets itself. This turns off the relay, the BS2 comes back up, tries to run the program again, and voila -- another brown-out reset.
  • Chuck E.Chuck E. Posts: 14
    edited 2007-07-23 18:07
    I'm powering the relays through darlington transister arrays to keep from loading the I/O pins. The power supply is rated for several amps, the relays draw about 170 milliamps according to the data sheets and I'm only powering one at a time. I will try running them and the darlington arrays through a separate power regulator to see what happens. You may very well be correct as relay 0 is turning on and then the program starts over.

    Chuck
  • Chuck E.Chuck E. Posts: 14
    edited 2007-07-23 19:03
    OK, just to rule out overloading the power supply, I put the relays and the darlington arrays on a separate 5v power supply, no change. I then put a voltmeter on the relay power bus and put everything back to original configuration, voltage runs 4.968vdc, the bar graph on my Fluke 179 never even wavers at any time. The relay is on for about .5 seconds, so I think something would show if the bus was being dragged down. Nope, I'm pretty sure this is a software issue of my own creation. I'll try and post a schematic by tomorrow sometime in case someone wants to check that over. I'm pretty confident on the electronics, I've been building radios since I was 11, working as a technician professionally for the last 20+ years. It's just the programming I'm new to.

    Chuck
  • stamptrolstamptrol Posts: 1,731
    edited 2007-07-23 19:33
    Chuck,

    So, if the power supply is up to the task, and the program seems to make sense (which it does ), then its back to a straight electrical probelm. Have you got diodes around each relay coil to handle the back EMF when the relays shut-off? I suspect everything works fine until the first relay shuts off.

    You could also test this simply by not providing any power to the relay circuits and running the Stamp through its paces, as reported on your DEBUG screen.

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • Chuck E.Chuck E. Posts: 14
    edited 2007-07-24 14:02
    The relays have diodes built in, plus the program never gets to the point where the relay is shut off, it's like it "locks up" between the stabilize and convert subroutines, then the whole processor resets and starts over. All of the little test programs I've made to test different functions have run in less time than that, so they're not a good test. Does anybody know of a test program that will go through and test all the addresses and functions of a BS2? It's starting to look to me like my stamp chip isn't chomping bits properly or something.
    Disconnecting all the electronics didn't do anything. I also added some debug lines to try and figure out where exactly the problem lies. It just seems to stop executing at the return line from the stabilize subroutine, then the whole thing resets about 2 seconds later and does the same thing. Is there a problem with the RAM address that stores the value for the next instruction maybe? How would I test that. I guess I'll write some test code and see what I can figure out.

    Chuck
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-07-24 15:01
    Aha!

    In your 'main' routine, you're using "GOTO" to go to subroutines, then the subroutines are using a "RETURN". If you "RETURN" from someplace you didn't use "GOSUB" to get to, the BS2 tries to get a 'return' address from the "GOSUB" stack. If there ISN'T a return address there, it resets the processor, as you're seeing.

    Convert those "GOTO" to "GOSUB", and it should work much better.
  • Chuck E.Chuck E. Posts: 14
    edited 2007-07-24 15:36
    DOH! Even though I'm a relative newbie, I do know the difference between GOTO and GOSUB from my Trash-80 days. I just couldn't see the forest for the trees, too close to my creation. That fixed that problem, I still have some logic flow problems, but it's working much better now. I might actually get it working.yeah.gif
    THANKS!

    Chuck
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-07-24 16:06
    Yay! I'm glad it's working for you, that's why I post on here.
  • stamptrolstamptrol Posts: 1,731
    edited 2007-07-24 16:21
    Good catch! There's always a "logical" reason!

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
Sign In or Register to comment.