Shop OBEX P1 Docs P2 Docs Learn Events
program keeps restarting — Parallax Forums

program keeps restarting

brian6592brian6592 Posts: 18
edited 2011-10-09 16:25 in BASIC Stamp
Hello I am new to programming, and I am in the process of finishing a class project. My issue is my program keeps restarting for no apparent reason (The speaker emits a sound therefore i know it is restarting). I have ruled out the obvious culprit, batteries. I was wondering what are other things that could cause the software to restart? (certain commands, loops, etc.)
Thank you.
«1

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-10-06 19:34
    Perhaps at some point you're turning on something or too many somethings and you end up dragging your power supply (or batteries) south, forcing your Stamp to brown-out/reset.
  • brian6592brian6592 Posts: 18
    edited 2011-10-06 19:40
    i am running both servos, 2 ir leds, 2 ir receivers , 2 phototransistors, and an occasional red led. I basically combined the Light-sensitive navigation section in the Robotics with the Boe Bot book with navigating with ir headlights section. The program goes toward light unless an object is detected by the infrareds, then it does an avoidance maneuver. The brownout occurs when i do any ir avoidance subroutine.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-10-06 19:55
    So, it's not unlikely that your batteries are under-rated or they're near their end; on the ragged edge, turning on the IR is the straw that breaks the camel's back (?), assuming the IR stuff is wired right.
  • brian6592brian6592 Posts: 18
    edited 2011-10-06 20:08
    I am using brand new 1.5v Rayovac batteries (obviously not rechargable). The wiring is correct because up until i changed the code dramatically, they have always worked. I saw another post about the same issue, and the solution was the subroutines never returned. All of my subroutines end in the RETURN command. Another question I have is if I call for a subroutine in the middle of a subroutine, when the subroutine i called for is finished, will it return to the previous subroutine and finish that, or will it return to the main DO statement (main program). Sorry if this question is confusing, I don't really know the terminology.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-10-06 20:24
    A GOSUB will RETURN to the place where the "call" originated.

    You stated that when you begin an IR avoidance routine (backing up?) things go awry.
    My surmise was that you were experiencing a reset from a loss of power.
    It's possible that when the battery is overtaxed that the voltage dips low enough to "force" a reset, and everything gets turned off (initialised) and everything is fine again till that tipping point is reached.
    I don't know how long you have been working with this battery set.

    Maybe you're re-initialising your program somehow?
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-06 20:25
    The GOSUB / RETURN pairs are "dynamic" pairs. In other words, the GOSUB puts a return address on an internal stack inside the PBasic interpreter, then does a GOTO to the label. The program continues from the GOTO / GOSUB label until it reaches a RETURN somewhere. The RETURN pops the return address off the stack and goes there. If there's a RETURN without a matching GOSUB, the Stamp typically resets because the return address is garbage. The issue of subroutine within subroutine depends on how the program is arranged. If you want more advice than that, you'll have to attach your program to a reply using the Attachment Manager that you get by clicking the "Go Advanced" button.
  • brian6592brian6592 Posts: 18
    edited 2011-10-06 20:29
    Can I PM either one of you the code and let you take a quick look at it? I don't want to post it publicly because several other students have the same project.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-10-07 19:27
    My suggestion is to put the beastie on a stand
    Cypherbot008.jpg

    and insert some strategic DEBUGs to find out where your program is cratering (if that's what's happening); be prepared to simulate conditions.
    640 x 480 - 72K
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-07 20:32
    Replace functional units of your program with nothing or with dummy routines or with DEBUG statements so you can pare your program down to the minimum that exhibits the problem, then post that.

    Sorry, I don't do PM-based help. If you can strip out portions of your program and still get what's left to fail, it won't do your compatriots any good to see what's posted.
  • brian6592brian6592 Posts: 18
    edited 2011-10-08 17:01
    Well I found some small errors in the code, which somehow fixed the brownouts. I'm not too sure which error it was because I changed several portions of the code before doing a test run. My next issue I'm running into is how to power a dc fan. I have looked at several threads trying to find a solution, but have been unsuccessful. I have a very small DC fan: 12v (will run on 6 i think), 130mA max, 1.56W max. Right now i have a 220Ohm resistor in pin 15 connected to the middle pin (Base) of an NPN transistor (several schematics called for this), the schematic said to connect the collector pin (left one) to Vin (i plugged it into one of the 3 holes above the breadboard labeled Vin), and it said connect the emitter pin (right one) to the fan and then to the ground (I put it in a Vss hole above the breadboard). If i run a HIGH 15 command the fan turns very slowly if at all. The tutorial calls for the PWM command which i have had no luck using.
    I Hope this wasn't too lengthy and I didn't want to add another thread to the forum, so any input on my new situation is appreciated.
    Thank You
  • brian6592brian6592 Posts: 18
    edited 2011-10-08 17:14
    it might be the transistor I am using (2N3904). Does this provide enough power? The transistor packaging says 200mA max, so I figured it would suffice.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-10-08 17:18
    A 12V fan needs about 12V.
    With what you've described, the most you're getting to that fan is about 4V, thereaboutish.

    The emitter should go to ground (Vss) and the fan should be between the collector and +12V.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-10-08 17:24
    You could sketch your circuit/s on a sheet of paper and take a pic of that and post it.

    Here's what:
    fan_NPN.JPG
    468 x 258 - 13K
  • brian6592brian6592 Posts: 18
    edited 2011-10-08 17:27
    As of now I'm using 4AAs to power the Boe Bot.
    If i add a seperate 9v battery, can i just pull the power for the fan from the 9V, and somehow use a pin as a switch to turn it on?
    I really don't understand how the power management works on the Boe Bot.
  • brian6592brian6592 Posts: 18
    edited 2011-10-08 17:30
    I'll see what i can do about a schematic, I don't really know the symbols. but i can give you the schematic i tried to follow. I will post it in a min. I have to find it first.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-10-08 17:32
    Yes, you can (probably should) use a separate 9V for the fan, just be sure that its - / negative gets connected to "Vss".

    fan2_npn.JPG
    522 x 274 - 15K
  • brian6592brian6592 Posts: 18
    edited 2011-10-08 17:34
    EM41_S_MN_R1.docx

    This is the word doc I got the information from. I think i attached it to the post.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-10-08 17:39
    Sorry, I can't do .docx
    I added a pic to my previous post.
    (Try using the Attachment Manager and uploading your pics as JPG etc.)
  • brian6592brian6592 Posts: 18
    edited 2011-10-08 17:47
    ok i did this in paint, so it's not pretty lol.

    wiring schematic.jpg
    960 x 642 - 42K
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-10-08 18:00
    OK, that's showing the effort.

    The arrow is the emitter.
    On the 2N3904, looking at the flat/sqr side, with the legs pointing down, it's E-B-C.

    The dwg at the top of your pic shows, I think, what I've advocated (it doesn't agree with the ckt presented in the lower 1/2 of your pic.)

    Keep us posted as to your progress.
  • brian6592brian6592 Posts: 18
    edited 2011-10-08 18:18
    I am now hearing an almost ultrasonic beep coming from the robot (probably the fan). any idea what this is?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-10-08 18:24
    (:
    Localise that beeping.
    Are you PWMing the fan or what?
  • brian6592brian6592 Posts: 18
    edited 2011-10-08 18:44
    the sound is definately the fan. and the pitch increases as the speed of the fan increases. if i spin the fan with my finger, it will keep spinning for a second or two on its own then stops because the speed is low. I am using the PWM command and the speed gradually increases to max speed and then restarts the program.

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

    duty VAR Word
    counter VAR Word
    time VAR Word

    FREQOUT 4, 2000, 3000

    duty = 132

    Main:

    duty = 132

    FOR counter = 0 TO 4
    duty = duty + 22
    FOR time = 0 TO 500
    PWM 15, duty, 1
    NEXT
    NEXT

    GOTO Main

    END
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-10-08 20:06
    Using the Stamp PWM on a motor can be an interesting experience.

    It'll probably go better using PAUSEs (LOOPing 1ms on, 9ms off for 10%; 5ms on, 5ms off for 50%; and so on.)

    How does it go just turning it full on (OUTPUT 15, HIGH 15)?

    [The program gets re-started by the GOTO Main, so there's no bug there.]
  • brian6592brian6592 Posts: 18
    edited 2011-10-09 09:59
    The fan turns on with the output 15 command, but only if i start it with my finger. I guess there is just not enough power. if i was to mount a 9v battery in the space under the board, what would the wiring be? Is it possible to use the pins as a switch? (I think I already asked that) What would be a basic setup to complete the circuit to the fan using a pin?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-10-09 11:22
    Yes, you asked that already. (:
    I attached a sketch of what to do in #17.
  • brian6592brian6592 Posts: 18
    edited 2011-10-09 15:06
    Oops, sorry I didn't see that drawing.
    Well i did another sketch in paint to see if I had the wiring down.
    The issue i am running into is where to connect the negative terminal of the 9V battery without using the 9V as the main power source for the board.
    can i just plug a wire in the VSS hole going straight to the negative terminal of the 9V, or do i need to use a row on the breadboard?

    fanschematic.jpg
    960 x 642 - 60K
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-10-09 15:24
    OK
    Yes, that is what my sketch shows.
    Connect the fan battery's negative to the Stamp/BoE/HWB Vss terminal/s.
    You cannot run the fan from a pin directly, you need to have the transistor for that.
    (Your sketch in #28 does not show the transistor.)
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-10-09 15:35
    Here's another pic:

    fanhowto3.jpg


    If you are running out of Vss places on the header then connect a wire from one of those to a row on the breadboard and then those are all Vss places, too.
    536 x 384 - 81K
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-10-09 16:25
    By the way, back to the sketch in #17 -- there is a diode there that we haven't talked about, and we'll need to, but it seems you're close to overwhelmed as it is.
    Please advise as to your progress.
Sign In or Register to comment.