PDA

View Full Version : Help with this project



imix500
09-03-2008, 07:53 PM
Hello all, I'm new to this forum and micro controllers but not electronics.
So I'm having trouble with the code for this project. It needs to spin a motor with a paddle wheel attached a certain number of times and then stop for a certain amount of time. The external components (motor ,paddle wheel switch) are working fine. Since the BS1 can't count, I'm using the FOR...NEXT instruction to set a number of loops for both paddle counting and interval timing. I am planning on using FOR...NEXT a large number of times for some of the intervals (~6 to 12 hours). Is there a better way in the BS1? Right now it seems like the BUTTON instruction is resetting the FOR...NEXT instruction for the motor control. Here's the program: Thanks!

SYMBOL btn = 0 ' FOR BUTTON

SYMBOL btnWrk = B4

SYMBOL reps = B2 ' FOR...NEXT loop counter

motor:
HIGH 0
FOR reps = 1 TO 3 ' repeat for 3 button pushes
BUTTON Btn, 7, 1, 255, btnWrk, 0, No_Press
DEBUG "button"
TOGGLE 1
NEXT


timer:
FOR reps = 1 TO 12 ' repeat with Reps = 1,2,3,etc
PAUSE 60000
NEXT
GOTO motor

No_Press:
GOTO motor

Chris Savage
09-04-2008, 12:10 AM
The only problem I see with this approach is that if your motor is DC then without additional circuitry your loops will not always equal the same amount of rotations on the motor shaft each time, especially if it is in water.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering

imix500
09-04-2008, 01:43 AM
Hi Chris, thanks for the reply. I see where you are coming from. However, what I was trying to do was have the micro switch tell the stamp when a paddle went by which is more important than the period of the loop or even the period in between when the motor moves.
This is actually controlling the movement of parts into a machine.
I think I read the clue I previously missed. The BUTTON instruction cannot stop a loop, which is where my head was. So, any tips on how to have the stamp let a set number of paddles go by before stopping the motor and continuing on with the instructions?

Chris Savage
09-04-2008, 03:35 AM
Well, depending on what else needs to happen in the loop you could increment a counter and when it reaches a certain point then you stop updating the paddles. A flow chart would be invaluable to determining what you want your program to do. I always use one for seemingly complex programs.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering

imix500
09-04-2008, 07:41 AM
Here's a quick flowchart I whipped up. You mentioned counting, and I'm assuming the only way to do that is with the FOR...NEXT instruction. Maybe I need to do it in a subroutine instead of inside the loop? Time for some experimenting.

Chris Savage
09-04-2008, 09:24 AM
That’s kind of simplified I think…I mean what happens if the switches never get activated….should the motor keep going? FOR…NEXT is not the only way to count. You can do it inside a loop, such as DO…LOOP and simply add a value to a variable each pass. You can have it set up so each time someone activates a switch a variable is incremented. When it reaches three you shut the motors down for the set duration. Then you repeat the process.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering

imix500
09-04-2008, 10:11 AM
Thanks Chris, that gave me a few things to think about. Namely, a fail safe timer in case the motor runs for more than 15 seconds or so.
So, it seems to be working. Maybe not the most elegant of programming but it does seem to work -a starting point. The only change I made was where the No_Press condition branches to:

SYMBOL btn = 0 ' FOR BUTTON

SYMBOL btnWrk = B4

SYMBOL reps = B2 ' FOR...NEXT loop counter

motor:
HIGH 0
FOR reps = 1 TO 3 ' repeat for 3 button pushes

switch:
BUTTON Btn, 7, 1, 255, btnWrk, 0, No_Press
DEBUG "button"
TOGGLE 1
NEXT


timer:
FOR reps = 1 TO 12 ' repeat with Reps = 1,2,3,etc
PAUSE 60000
NEXT
GOTO motor

No_Press:
GOTO switch