November 23, 2024, 06:43:52 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


converting RC pwm to on off commands

Started by reddragon, November 22, 2009, 02:48:05 PM

Previous topic - Next topic

reddragon

hi Jon i was wondering if you can convert this to prop 2 code for me this way its all on one board?

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Sio             = 7                     ' SETUP = UP

SYMBOL  Y2              = 3                     ' servo pulse inputs
SYMBOL  X2              = 2
SYMBOL  Y1              = 1
SYMBOL  X1              = 0


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400


' -----[ Variables ]-------------------------------------------------------

SYMBOL  ctrlBits        = B0
SYMBOL  pWidth          = B2


' -----[ Initialization ]--------------------------------------------------

Reset:
  SEROUT Sio, Baud, ("!DC16", %00, "X")
  PAUSE 5


' -----[ Program Code ]----------------------------------------------------

Main:
  SEROUT Sio, Baud, ("!DC16", %00, "L", ctrlBits)
  SEROUT Sio, Baud, ("!DC16", %00, "P", 6, BIT5)        ' remove for v1.5


' Stick #1

Check_Y1:
  PULSIN Y1, 1, pWidth
  IF pWidth > 170 THEN Y1_Up
  IF pWidth < 130 THEN Y1_Down

Y1_Stick_Off:
  BIT0 = IsOff
  BIT1 = IsOff
  GOTO Check_X1

Y1_Up:
  BIT0 = IsOn
  BIT1 = IsOff
  GOTO Check_X1

Y1_Down:
  BIT0 = IsOff
  BIT1 = IsOn

Check_X1:
  PULSIN X1, 1, pWidth
  IF pWidth > 170 THEN X1_Left
  IF pWidth < 130 THEN X1_Right

X1_Stick_Off:
  BIT2 = IsOff
  BIT3 = IsOff
  GOTO Check_Y2

X1_Left:
  BIT2 = IsOn
  BIT3 = IsOff
  GOTO Check_Y2

X1_Right:
  BIT2 = IsOff
  BIT3 = IsOn


' Stick #2

Check_Y2:
  PULSIN Y2, 1, pWidth
  IF pWidth > 170 THEN Y2_Up
  IF pWidth < 130 THEN Y2_Down

Y2_Stick_Off:
  BIT4 = IsOff
  BIT5 = IsOff
  GOTO Check_X2

Y2_Up:
  BIT4 = IsOn
  BIT5 = IsOff
  GOTO Check_X2

Y2_Down:
  BIT4 = IsOff
  BIT5 = IsOn

Check_X2:
  PULSIN X2, 1, pWidth
  IF pWidth > 170 THEN X2_Left
  IF pWidth < 130 THEN X2_Right

X2_Stick_Off:
  BIT6 = IsOff
  BIT7 = IsOff
  GOTO Main

X2_Left:
  BIT6 = IsOn
  BIT7 = IsOff
  GOTO Main

X2_Right:
  BIT6 = IsOff
  BIT7 = IsOn
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------



JonnyMac

Here's a direct translation to the Prop-2; what's changed is the PBASIC 2.5 programming structure and the 5x timing change for PULSIN.

In the future please don't call me out for programming help as this dis-invites others from helping you -- and we want to encourage anyone who can write a helpful program to do so as that's how we all get better.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated... 26 SEP 2009
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Y2              PIN     11                      ' pulse inputs
X2              PIN     10
Y1              PIN     9
X1              PIN     8


' -----[ Constants ]-------------------------------------------------------

IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

Yes             CON     1
No              CON     0


' -----[ Variables ]-------------------------------------------------------

pWidth          VAR     Word
ctrlBits        VAR     Byte


' -----[ Initialization ]--------------------------------------------------

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000000 : DIRL = %11111111           ' set outputs


' -----[ Program Code ]----------------------------------------------------

Main:
  OUTL = ctrlBits                               ' update

' Stick #1

Check_Y1:
  PULSIN Y1, 1, pWidth
  IF (pWidth > 850) THEN                        ' up
    ctrlBits.BIT0 = IsOn
    ctrlBits.BIT1 = IsOff
  ELSEIF (pWidth < 650) THEN                    ' down
    ctrlBits.BIT0 = IsOff
    ctrlBits.BIT1 = IsOn
  ELSE                                          ' off
    ctrlBits.BIT0 = IsOff
    ctrlBits.BIT1 = IsOn
  ENDIF

Check_X1:
  PULSIN X1, 1, pWidth
  IF (pWidth > 850) THEN                        ' left
    ctrlBits.Bit2 = IsOn
    ctrlBits.Bit3 = IsOff
  ELSEIF (pWidth < 650) THEN                    ' right
    ctrlBits.Bit2 = IsOff
    ctrlBits.Bit3 = IsOn
  ELSE                                          ' off
    ctrlBits.Bit2 = IsOff
    ctrlBits.Bit3 = IsOn
  ENDIF


' Stick #2

Check_Y2:
  PULSIN Y2, 1, pWidth
  IF (pWidth > 850) THEN                        ' up
    ctrlBits.Bit4 = IsOn
    ctrlBits.Bit5 = IsOff
  ELSEIF (pWidth < 650) THEN                    ' down
    ctrlBits.Bit4 = IsOff
    ctrlBits.Bit5 = IsOn
  ELSE                                          ' off
    ctrlBits.Bit4 = IsOff
    ctrlBits.Bit5 = IsOn
  ENDIF

Check_X2:
  PULSIN X2, 1, pWidth
  IF (pWidth > 850) THEN                        ' left
    ctrlBits.Bit6 = IsOn
    ctrlBits.Bit7 = IsOff
  ELSEIF (pWidth < 650) THEN                    ' right
    ctrlBits.Bit6 = IsOff
    ctrlBits.Bit7 = IsOn
  ELSE                                          ' off
    ctrlBits.Bit6 = IsOff
    ctrlBits.Bit7 = IsOn
  ENDIF

  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office