Shop OBEX P1 Docs P2 Docs Learn Events
Program help — Parallax Forums

Program help

CodyBreezeCodyBreeze Posts: 2
edited 2009-12-10 02:13 in BASIC Stamp
I am pretty new at this and am working on a project for my class this semester. Here is what I am trying to do:
I have two pumps hooked up to a dual H-bridge running off of the BS2. The program is to start when a laser beam hitting a light-to-frequency converter is blocked and the count substantially drops. The program works to a point. When the laser is broken, the correct sequence runs based on the IF statements. The problem is that I want the light-to-frequency converter to continually monitor the laser so when the glass is lifted and the laser reconnects the pumps stop per the fourth IF statement. I guess I don't know how to end the PWM sequences in either "Shot," "EvenFlow," or "DoubleFlow" after a glass is filled and then return to a continually running "Checklaser" sequence. Help would be greatly appreciated. Thank you!


' {$STAMP BS2}
' {$PBASIC 2.5}
'Mixer pins
'pin10 ENB
'pin11 INB2
'pin12 INB1
'Liquor pins
'pin13 ENA
'pin14 INA2
'pin15 INA1
OUTPUT 10
OUTPUT 11
OUTPUT 12
OUTPUT 13
OUTPUT 14
OUTPUT 15
'switch designation
'pin 3 is shot
'pin 4 is EvenFlow
'pin 5 is DoubleFlow
INPUT 3
INPUT 4
INPUT 5

' TSL230R-Test.bs2
' Configures TSL230R for x100 sensitivity
' Displays output in Debug Terminal

'
Define variables, set status of pins
x VAR Word
cnt VAR Word

'
Constant declarations
S0 PIN 0 'Sensitivity selection pins
S1 PIN 1
In PIN 2 'TSL230R output pin

'
Program Start
HIGH S0 'Set sensitivity pins (S0,S1) to x100
HIGH S1

HIGH 15 'Set Hbridge INA1 pin high
LOW 14 'Set Hbridge INA2 pin low
'INA1 pin high and INA2 pin low runs liquor pump in "forward" direction

HIGH 12 'Set Hbridge INB1 pin high
LOW 11 'Set Hbridge INB2 pin low
'INB1 pin high and INB2 pin low runs mixer pump in "forward" direction

'
Main program loop
CheckLaser:
COUNT In, 100, cnt 'COUNT on P2 FOR 100 ms, store value in cnt
DEBUG HOME, DEC5 cnt 'Display value of cnt as a decimal
IF cnt < 500 AND IN3=0 THEN Shot
IF cnt < 500 AND IN4=0 THEN EvenFlow
IF cnt < 500 AND IN5=0 THEN DoubleFlow
IF cnt > 500 THEN GOTO CheckLaser



Shot:

PWM 13, 200, 10000


EvenFlow:

PWM 13, 100, 10000
PWM 10, 100, 10000


DoubleFlow:

PWM 13, 200, 10000
PWM 10, 100, 10000

Post Edited (CodyBreeze) : 12/10/2009 2:15:04 AM GMT

Comments

  • $WMc%$WMc% Posts: 1,884
    edited 2009-12-10 00:12
    CodyBreeze

    I think a GOSUB in the IF's and a RETURN after the jump would help.

    You have nothing to return back to the top to rescan the laser, Your code just falls through.

    Just for starters!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············___$WMc%___···························· BoogerWoods, FL. USA
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-12-10 01:00
    CodyBreeze

    I going to point out a few thing

    One it is easier to follow code routine if you label your·IO pins

    ········································ 'Mixer pins·
    Mix_ENB·········· PIN····· 10···· 'pin10 ENB
    Mix_INB2········· PIN····· 11···· 'pin11 INB2
    Mix_INB1········· PIN····· 12···· 'pin12 INB1

    ······································· 'Liquor pins

    Liq_ENA·········· PIN····· 13···· 'pin13 ENA
    Liq_INA2········· PIN····· 14···· 'pin14 INA2
    Liq_INA1········· PIN····· 15···· 'pin15 INA1

    Two if you where to put your Forward controls in two routines for your pumps


    GOSUB Liq_Pump_FWD
    GOSUB Mix_Pump_FWD

    ·

    Liq_Pump_FWD:······················· 'This Rountine runs liquor pump in "forward" direction
    HIGH Liq_INA1························· 'Set Hbridge INA1 pin high
    LOW· Liq_INA2························· 'Set Hbridge INA2 pin low
    RETURN

    Mix_Pump_FWD:························· 'This runs mixer pump in "forward" direction
    HIGH Mix_INB1··························· ·'Set Hbridge INB1 pin high
    LOW· Mix_INB2··························· ·'Set Hbridge INB2 pin low
    RETURN

    Three You need to make these in to subroutines

    Shot:

    PWM 13, 200, 10000

    ·EvenFlow:

    PWM 13, 100, 10000
    PWM 10, 100, 10000


    DoubleFlow:

    PWM 13, 200, 10000
    PWM 10, 100, 10000

    Shot:
    PWM Liq_ENA, 200, 10000
    RETURN



    In the Attachment below I clean up your code a little bit BUT I will not do your Project for you

    Also there is a blank template for you to use when you write your code so that you can keep it neat looking and easy to read and follow

    I hope this helps

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 12/10/2009 2:02:54 AM GMT
  • CodyBreezeCodyBreeze Posts: 2
    edited 2009-12-10 02:13
    Thank you to both of you. I greatly appreciate it. I was completely unaware of GOSUB RETURN and DO LOOP and may have never found those. Thanks again!
Sign In or Register to comment.