#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2009
    Location
    London, ON
    Posts
    322
    Rep Power
    215

    PBasic (Basic Stamp 2) Pulldown


    Hi, I have just started programming in Basic and for processors, and I'm a little confused on the logic and syntax.

    Here's my program, written in PBasic:

    VB Code:
     
    'Automatic Car.bs2
    'UWO Formula Racing Team
    'September 2, 2010
    'Allows for switched Manual, Automatic, or Launch Control transmission variations
    'To be used with the 2010 FSAE Pneumatic Switching board
    'RPMs are to be input AFTER the ECU, for a digital signal.
    
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
     
    '+---------- General Purpose I/O Pin Assignments -------+
    'Mode Selector Switch
    S_MAN     PIN 0
    S_AUTO    PIN 1
    S_LAUNCH  PIN 2
     
    'Shift Buttons
    B_DWNIN     PIN 3
    B_UPIN      PIN 4
    B_DWNOUT    PIN 7
    B_UPOUT    PIN 8
     
    'Tachometer Pulse from ECU
    RPM_IN    PIN 5
     
    'Launch Control GND Pin (Active LOW)
    LC_IN     PIN 6
     
    'Constant Declaration
    IsOn  CON 1
    IsOff CON 0
    CountMs CON 10
    RPMConst CON 6000
     
    'Workspace Declaration
    B1_WRK VAR Byte
    B2_WRK VAR Byte
     
    'Variable Declaration
    RPM_PULSE VAR Word
    RPM_VAL   VAR Word
    COUNTER   VAR Word
     
    'PIN Setup
    Setup:
      INPUT S_MAN
      INPUT S_AUTO
      INPUT S_LAUNCH
     
      INPUT B_DWNIN
      INPUT B_UPIN
     
      LOW   B_DWNOUT
      LOW   B_UPOUT
      HIGH  LC_IN
     
     
    'Main program - Based on selector switch mode:
    'S_MAN (Manual Transmission) ->
        'In Manual mode, the shift buttons are directed straight to the external
        'Shifting board, activating the shifting mechanisms.
    'S_AUTO (Automatic Transmission) ->
        'In Automatic mode, the shift buttons are activated when engine RPM hits
        'The prime shift point (12,000 RPM)
    'S_LAUNCH (Launch Control) ->
        'In Launch Control mode (designed for Acceleration Run), the processor has
        'Three states:  Pre-launch, < 3500 RPM, allows for manual gear changes.
        'During Launch, > 3500RPM, activates Launch Control and becomes Automatic
        'Post Launch, after first gear change, deactivates Launch Control
    Main:
     
      IF S_MAN    = IsOn THEN GOSUB Manual
      IF S_AUTO   = IsOn THEN GOSUB Automatic
      IF S_LAUNCH = IsOn THEN GOSUB Launch
     
      GOTO Main
    END
     
    Manual:
      DO WHILE S_MAN = IsOn
        BUTTON B_DWNIN, IsOn, 255, 0, B1_WRK, 1, Downshift
        BUTTON B_UPIN,  IsOn, 255, 0, B2_WRK, 1, Upshift
      LOOP
    RETURN
     
    Automatic:
      DO WHILE S_AUTO = IsOn
        COUNT RPM_IN, CountMs, RPM_PULSE
        RPM_VAL = RPM_PULSE * RPMConst
        IF RPM_VAL < 3500 THEN
          GOSUB Downshift
        ELSEIF RPM_VAL >= 12000 THEN
          GOSUB Upshift
        ENDIF
      LOOP
    RETURN
     
    Launch:
      RPM_VAL = 0
      DO WHILE RPM_VAL < 3500
        COUNT RPM_IN, CountMs, RPM_PULSE
        RPM_VAL = RPM_PULSE * RPMConst
        BUTTON B_DWNIN, IsOn, 255, 0, B1_WRK, 1, Downshift
        BUTTON B_UPIN,  IsOn, 255, 0, B2_WRK, 1, Upshift
      LOOP
     
      LOW LC_IN
      DO WHILE S_LAUNCH = IsOn
        COUNT RPM_IN, CountMs, RPM_PULSE
        RPM_VAL = RPM_PULSE * RPMConst
        IF RPM_VAL >= 12000 THEN
          GOSUB Upshift
        ELSEIF RPM_VAL < 3500 THEN
          GOSUB Downshift
        ENDIF
      LOOP
    RETURN
     
    Downshift:
      PULSOUT B_DWNOUT, 50
    RETURN
     
    Upshift:
      PULSOUT B_UPOUT, 50
      HIGH LC_IN
    RETURN


    I think I've done it right, but my question is for LC_IN. LC_IN is a pin from the ECU that's held high at 4.5V and is active LOW. So to activate the ECU pin, do I make my Basic Stamp pin LOW, or do I make it an Input?

    Thanks!
    Paul
    <Tetrad> the program I just wrote 1) compiled the first time without any errors and 2) worked like it was supposed to
    <Tetrad> I don't know whether to be proud or scared to death
    Originally Posted by DaWei_M
    That covers a multitude of your sins, right there.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2009
    Location
    London, ON
    Posts
    322
    Rep Power
    215
    Well, thanks to anyone who looked, but I got my answer from a friend:

    LOW (pin number) grounds the pin. It's still considered an Output because you're writing a value to the pin.
    <Tetrad> the program I just wrote 1) compiled the first time without any errors and 2) worked like it was supposed to
    <Tetrad> I don't know whether to be proud or scared to death
    Originally Posted by DaWei_M
    That covers a multitude of your sins, right there.

IMN logo majestic logo threadwatch logo seochat tools logo