May 20, 2024, 09:34:22 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.


Sloppy trigger

Started by clinefx1, March 21, 2007, 10:26:30 PM

Previous topic - Next topic

clinefx1

I running a single 7 segment display off a prop 1.  Numbers count up with every button press.  I'm having some trouble getting the program to lock in with every trigger press.  I need help preventing the program skipping ahead or missing a contact closure. 

Thanks for the help.
Chris

' =========================================================================
'
'   File....... elevator test 1
'   Purpose....
'   Author..... Chris
'   E-mail..... Cliefx1@aol.com
'   Started....
'   Updated....
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL seg7       = PIN7
SYMBOL seg6       = PIN6
SYMBOL seg5       = PIN5
SYMBOL SEg4       = PIN4
SYMBOL seg3       = PIN3
SYMBOL seg2       = PIN2
SYMBOL seg1       = PIN1
SYMBOL trigger    = PIN0

' -----[ Constants ]-------------------------------------------------------
SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0
SYMBOL  time            = 170
' -----[ Variables ]-------------------------------------------------------


' -----[ EEPROM Tables ]---------------------------------------------------



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

reset:
       DIRS = %11111110                              ' P0..P4 are outputs


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

Main:

  Clear:
    seg1 = isoff
    seg2 = isoff
    seg3 = isoff
    seg4 = isoff
    seg5 = isoff
    seg6 = isoff
    seg7 = isoff
PAUSE time

IF trigger = isoff THEN clear

  Num_0:
    seg1 = ison
    seg2 = ison
    'seg3 = isoff
    seg4 = ison
    seg5 = ison
    seg6 = ison
    seg7 = ison
PAUSE time

IF trigger = isoff THEN num_0

  Num_1:
    'seg1 = ison
    seg2 = isoff
    'seg3 = isoff
    seg4 = isoff
    'seg5 = ison
    seg6 = isoff
    seg7 = isoff
PAUSE time

IF trigger = isoff THEN Num_1

  Num_2:
    'seg1 = ison
    seg2 = ison
    seg3 = ison
    'seg4 = isoff
    seg5 = isoff
    seg6 = ison
    seg7 = ison
PAUSE time

IF trigger = isoff THEN Num_2

  Num_3:
    'seg1 = ison
    'seg2 = ison
    'seg3 = ison
    'seg4 = isoff
    seg5 = ison
    'seg6 = ison
    seg7 = isoff
PAUSE time

IF trigger = isoff THEN Num_3

  Num_4:
    'seg1 = ison
    seg2 = isoff
    'seg3 = ison
    seg4 = ison
    'seg5 = ison
    seg6 = isoff
    'seg7 = isoff
PAUSE time

IF trigger = isoff THEN Num_4

  Num_5:
    seg1 = isoff
    seg2 = ison
    'seg3 = ison
    'seg4 = ison
    'seg5 = ison
    seg6 = ison
    'seg7 = isoff
PAUSE time

IF trigger = isoff THEN Num_5

  Num_6:
    'seg1 = isoff
    seg2 = isoff
    'seg3 = ison
    'seg4 = ison
    'seg5 = ison
    'seg6 = ison
    seg7 = ison
PAUSE time

IF trigger = isoff THEN Num_6

  Num_7:
    seg1 = ison
    seg2 = ison
    seg3 = isoff
    seg4 = isoff
    'seg5 = ison
    seg6 = isoff
    seg7 = isoff
PAUSE time

IF trigger = isoff THEN Num_7

  Num_8:
    'seg1 = ison
    'seg2 = ison
    seg3 = ison
    seg4 = ison
    'seg5 = ison
    seg6 = ison
    seg7 = ison
PAUSE time

IF trigger = isoff THEN Num_8

  Num_9:
    'seg1 = ison
    'seg2 = ison
    'seg3 = ison
    'seg4 = ison
    'seg5 = ison
    seg6 = isoff
    seg7 = isoff
PAUSE time

IF trigger = isoff THEN Num_9

  Num_P:
    'seg1 = ison
    'seg2 = ison
    'seg3 = ison
    'seg4 = ison
    seg5 = isoff
    'seg6 = isoff
    seg7 = ison
PAUSE time

IF trigger = isoff THEN Num_P

  Num_H:
    'seg1 = ison
    seg2 = isoff
    'seg3 = ison
    'seg4 = ison
    seg5 = ison
    'seg6 = isoff
    'seg7 = ison
PAUSE time

IF trigger = isoff THEN Num_H


  GOTO Main
  END



JonnyMac

March 22, 2007, 02:12:47 AM #1 Last Edit: March 22, 2007, 02:33:17 AM by JonnyMac
When dealing with patterns of parallel outputs a great approach is to store those patterns in a table and use READ to retrieve them -- as in the program below.  You'll just need to verify the table with your intended bit patterns; remember, BIT7 (Seg 7) is the leftmost bit, BIT1 (Seg 1) is second from the right.

' =========================================================================
'
'   File...... Elevator-JW.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK  (for Chris Cline)
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN0
SYMBOL  Segments        = PINS


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


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

SYMBOL  theDigit        = B2


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

Reset:
  Segments = %00000000
  DIRS = %11111110                              ' set segment outputs


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

Main:
  IF Trigger = IsOff THEN Main                  ' wait for trigger

Show_Digit:
  theDigit = theDigit + 1 // 13                 ' point to next
  READ theDigit, Segments                       ' update the display
  PAUSE 170                                     ' set min hold time

Release:
  IF Trigger = IsOn THEN Release                ' let it go!
  GOTO Main


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


' -----[ EEPROM Data ]-----------------------------------------------------

Patterns:
  EEPROM (%00000000)                            ' clear
  EEPROM (%11110110)                            ' 0
  EEPROM (%00100010)                            ' 1
  EEPROM (%11001110)                            ' 2
  EEPROM (%00111010)                            ' 3
  EEPROM (%00111010)                            ' 4
  EEPROM (%01111100)                            ' 5
  EEPROM (%11111000)                            ' 6
  EEPROM (%00100110)                            ' 7
  EEPROM (%11111110)                            ' 8
  EEPROM (%00111110)                            ' 9
  EEPROM (%10011110)                            ' P
  EEPROM (%10111010)                            ' H
Jon McPhalen
EFX-TEK Hollywood Office

clinefx1

Thanks that worked awesome. 


In a few days I think I will be building a setup with two 7-seg displays next to each other.  Working off a prop-2 with switches for count up and count down.  Seems like the table is the way to go.
 

JonnyMac

March 22, 2007, 11:06:26 AM #3 Last Edit: March 22, 2007, 11:08:47 AM by JonnyMac
If you're willing to connect a few bits of extra circuitry I could show you how to do it in the Prop-1 as well.  What you need is a 74HC595 shift register for each display.  With two 595s, a bit of code (I'll show you, of course), and three I/O pins you could do it on a Prop-1.  So, your two-digit project would have two buttons, three pins for the 595s, and still have three pins left over.  The 74HC595 costs about a buck each.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

March 22, 2007, 04:03:07 PM #4 Last Edit: March 22, 2007, 04:22:49 PM by JonnyMac
Since I needed a break from what I was doing I looked up my BS1 '595 code and whipped up a two-floor version for you to study.  It looks long, but only uses about half the program space.

' =========================================================================
'
'   File....... Elevator-v2.BS1
'   Purpose....
'   Author..... Jon Williams, EFX-TEK
'   E-mail..... jwilliams@efx-tek.com
'   Started....
'   Updated.... 12 JUL 2005
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Up              = PIN7                  ' SETUP = DN
SYMBOL  Down            = PIN6                  ' SETUP = DN

SYMBOL  Latch           = 2                     ' 74HC595 output latch (12)
SYMBOL  Clock           = 1                     ' 74HC595 shift clock  (11)
SYMBOL  DataOut         = PIN0                  ' 74HC595 serial data  (14)


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

SYMBOL  IsPressed       = 1
SYMBOL  IsNotPressed    = 0

'                          .GFEDCBA             ' segment assignments
SYMBOL  Clear           = %00000000             ' blank
SYMBOL  Lobby           = %00111000             ' L
SYMBOL  Parking         = %01110011             ' P

SYMBOL  MAX_FLOOR       = 14                    ' last is 13th floor


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

SYMBOL  displayBits     = W0
SYMBOL  dispLf          = B0                    ' part of W0
SYMBOL  dispRt          = B1                    ' part of W0

SYMBOL  updn            = B2                    ' button inputs bits
SYMBOL  floor           = B3                    ' floor (0 = parking)
SYMBOL  work            = B4
SYMBOL  idx             = B5


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

Reset:
  DIRS = %00000111                              ' outputs to x595

  floor = 1                                     ' set for lobby
  GOTO Show_New_Floor


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

Main:
  updn = PINS / 64                              ' get button bits
  BRANCH updn, (Main, Down_One, Up_One, Main)   ' accept only one button
  GOTO Main

Up_One:
  IF floor = MAX_FLOOR THEN Main                ' room to go up?
    floor = floor + 1                           '   yes, bump to next
    GOTO Release_Button

Down_One:
  IF floor = 0 THEN Main                        ' room to go down?
    floor = floor - 1                           '   yes, bump to previous

Release_Button:
  PAUSE 100
  updn = PINS / 64                              ' get button bits
  IF updn > %00 THEN Release_Button             ' hold if either pressed

Show_New_Floor:
  IF floor <> 0 THEN Check_Lobby                ' skip if not 0 (parking)
    dispLf = Clear
    dispRt = Parking
    GOTO Refresh_Display

Check_Lobby:
  IF floor <> 1 THEN Show_Floor_Num             ' skip if not 1 (lobby)
    dispLf = Clear
    dispRt = Lobby
    GOTO Refresh_Display

Show_Floor_Num:
  work = floor - 1                              ' adjust for parking level
  dispLf = Clear                                ' assume floor < 10
  IF work < 10 THEN Ones_Digit                  ' allow leading blank

Tens_Digit:
  dispLf = work / 10                            ' extract digit
  READ dispLf, dispLf                           ' convert to LED pattern

Ones_Digit:
  dispRt = work // 10                           ' extract digit
  READ dispRt, dispRt                           ' convert to LED pattern

Refresh_Display:
  GOSUB Shift_LEDs                              ' show new floor
  GOTO Main


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

' Shifts bits patterns (2 x 8) to 7-seg displays connected to
' 74HC595 shift registers.

Shift_LEDs:
  FOR idx = 1 TO 16                             ' shift 16 bits
    DataOut = BIT15                             ' MSB first
    PULSOUT Clock, 1                            ' clock the bit
    displayBits = displayBits * 2               ' get next bit
  NEXT
  PULSOUT Latch, 1                              ' latch x595 outputs
  RETURN

' -----[ EEPROM Data ]-----------------------------------------------------

Digits:
  '        .GFEDCBA                             ' segment assignments
  EEPROM (%00111111)                            ' 0
  EEPROM (%00000110)                            ' 1
  EEPROM (%01011011)                            ' 2
  EEPROM (%01001111)                            ' 3
  EEPROM (%01100110)                            ' 4
  EEPROM (%01101101)                            ' 5
  EEPROM (%01111101)                            ' 6
  EEPROM (%00000111)                            ' 7
  EEPROM (%01111111)                            ' 8
  EEPROM (%01100111)                            ' 9
Jon McPhalen
EFX-TEK Hollywood Office

clinefx1

Wow?! :o  That kind of code is a little scary.  I totally believe you when you say it can be done.  I'm guessing each seg display is wired to it's own 74HC595. The data pins on the two chip are daisy chained together and the correct bit info ends up where it is addressed? 

I'm still plotting out allot of other circuits for this thing and when I sell my boss and producers on a price I'll defiantly be back for some serious help. 


Thanks
Chris

JonnyMac

March 23, 2007, 07:50:54 AM #6 Last Edit: March 23, 2007, 08:37:19 AM by JonnyMac
The code may look a little scary at first blush, but if you study it a bit you'll find it's quite straightforward.  Yes, each display is wired to the outputs of the 75HC595.  And yes, the chips are daisy-chained together -- this is the feature that saves you pins.  If you wanted to expand to three or four displays you would just add them and update the code, you wouldn't need to use any more Prop-1 I/O pins.
Jon McPhalen
EFX-TEK Hollywood Office

clinefx1

So a few more questions.  I'm planning on running two 12vdc 7seg displays in the elevator and two others on a hard wired control panel.  I'm not sure what the seg voltage will be on the control panel. Will the 74HC595's give me 12v outs?  Then how would you  parallel the display to the digits on the control panel? 



Chris

JonnyMac

What I would do, Chris, is use common-anode displays and tie that to 12 vdc.  Run your segment control lines (cathodes) through suitable resistors and to a ULN2803.  The inputs of the ULN will be the output of the 74HC595 which is a TTL (0 to 5v) device.  So, for each display you'd have '595 to decode and output the parallel bits and a ULN2803 to provide the current for the displays at 12 vdc; that will let you get them nice and bright.
Jon McPhalen
EFX-TEK Hollywood Office

clinefx1

So I got my display up and running with the 74hc595s and no smoke.  ;D The program you wrote works great.  I'm having some trouble with changing the floor sequence.  My new order is { L, 2, 3, 4, 5, 25, 26, 27, 28, 29, 30, PH}   I was hoping you could work some magic and edit it.  I'm also want to add another button that jumps strait to PH.   I tried to make these changes but it won?t compile for me.     


Thanks for all you help
-Chris

JonnyMac

Here you go, Chris.  This program uses a floor index that drives a LOOKUP table for the actual floor number to display.  I've adjusted things a little so that "L" is floor 0, and "PH" is floor 100.  For the PH button you'll need to add a 10K resistor between P5.B and P5.W, then a normally open button between P5.W and P5.R. 

And since I know we're practically neighbors, I'd like to see this thing in action when it's done!  ;D

' =========================================================================
'
'   File....... Elevator-v3.BS1
'   Purpose....
'   Author..... Jon Williams, EFX-TEK
'   E-mail..... jwilliams@efx-tek.com
'   Started....
'   Updated.... 29 MAR 2007
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Elevator simulation; displays floors:
'   L, 2, 3, 4, 5, 25, 26, 27, 28, 29, 30, PH
'
' ... with direct control to PH
'
' Lobby is floor #0, PH is floor #100


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


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

SYMBOL  Up              = PIN7                  ' SETUP = DN
SYMBOL  Down            = PIN6                  ' SETUP = DN
SYMBOL  PHNow           = PIN5                  ' add external pull-down

SYMBOL  Latch           = 2                     ' 74HC595 output latch (12)
SYMBOL  Clock           = 1                     ' 74HC595 shift clock  (11)
SYMBOL  DataOut         = PIN0                  ' 74HC595 serial data  (14)


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

SYMBOL  IsPressed       = 1
SYMBOL  IsNotPressed    = 0

'                          .GFEDCBA             ' segment assignments
SYMBOL  Clear           = %00000000             ' blank
SYMBOL  Ltr_L           = %00111000             ' L
SYMBOL  Ltr_P           = %01110011             ' P
SYMBOL  Ltr_H           = %01110110             ' H

SYMBOL  MAX_FLRIDX      = 11                    ' 0..11 floor positions


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

SYMBOL  displayBits     = W0
SYMBOL  dispLf          = B0                    ' part of W0
SYMBOL  dispRt          = B1                    ' part of W0

SYMBOL  updn            = B2                    ' button inputs bits
SYMBOL  flrIdx          = B3                    ' floor index
SYMBOL  floor           = B4                    ' floor displayed
SYMBOL  shift           = B5                    ' for bit shifting


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

Reset:
  DIRS = %00000111                              ' outputs to x595

  flrIdx = 0                                    ' set for lobby
  GOTO Show_New_Floor


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

Main:
  IF PHNow = IsNotPressed THEN Check_UpDn       ' PH button pressed?
    flrIdx = MAX_FLRIDX                         ' yes, set floor index
    GOTO Show_New_Floor                         ' and update display

Check_UpDn:
  updn = PINS / 64                              ' get button bits
  BRANCH updn, (Main, Down_One, Up_One, Main)   ' accept only one button
  GOTO Main

Up_One:
  IF flrIdx = MAX_FLRIDX THEN Main              ' room to go up?
    flrIdx = flrIdx + 1                         '   yes, bump to next
    GOTO Release_Button

Down_One:
  IF flrIdx = 0 THEN Main                       ' room to go down?
    flrIdx = flrIdx - 1                         '   yes, bump to previous

Release_Button:
  PAUSE 100
  updn = PINS / 64                              ' get button bits
  IF updn > %00 THEN Release_Button             ' hold if either pressed

Show_New_Floor:
  LOOKUP flrIdx, (0,2,3,4,5,25,26,27,28,29,30,100), floor

Check_Lobby:
  IF floor <> 0 THEN Check_Parking              ' skip if not 0 (lobby)
    dispLf = Clear
    dispRt = Ltr_L
    GOTO Refresh_Display

Check_Parking:
  IF floor < 100 THEN Show_Floor_Num            ' skip if not 100 (parking)
    dispLf = Ltr_P
    dispRt = Ltr_H
    GOTO Refresh_Display

Show_Floor_Num:
  dispLf = Clear                                ' assume floor < 10
  IF floor < 10 THEN Ones_Digit                 ' allow leading blank

Tens_Digit:
  dispLf = floor / 10                           ' extract digit
  READ dispLf, dispLf                           ' convert to LED pattern

Ones_Digit:
  dispRt = floor // 10                          ' extract digit
  READ dispRt, dispRt                           ' convert to LED pattern

Refresh_Display:
  GOSUB Shift_LEDs                              ' show new floor
  GOTO Main


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

' Shifts bits patterns (2 x 8) to 7-seg displays connected to
' 74HC595 shift registers.

Shift_LEDs:
  FOR shift = 1 TO 16                           ' shift 16 bits
    DataOut = BIT15                             ' MSB first
    PULSOUT Clock, 1                            ' clock the bit
    displayBits = displayBits * 2               ' get next bit
  NEXT
  PULSOUT Latch, 1                              ' latch x595 outputs
  RETURN

' -----[ EEPROM Data ]-----------------------------------------------------

Digits:
  '        .GFEDCBA                             ' segment assignments
  EEPROM (%00111111)                            ' 0
  EEPROM (%00000110)                            ' 1
  EEPROM (%01011011)                            ' 2
  EEPROM (%01001111)                            ' 3
  EEPROM (%01100110)                            ' 4
  EEPROM (%01101101)                            ' 5
  EEPROM (%01111101)                            ' 6
  EEPROM (%00000111)                            ' 7
  EEPROM (%01111111)                            ' 8
  EEPROM (%01100111)                            ' 9
Jon McPhalen
EFX-TEK Hollywood Office

clinefx1

Just ran your updated code on the bench and it ran great.  Thank you once again.   This is part of an elevator rig for a sit-com shooting down in Hollywood.  Once they fully green light this gag and I get it fully installed I'll get you in to check it out. 


-Chris

clinefx1

Hi again-

Hope everything is going well.  I ran into a small glitch with the Elevator-v3.BS1 program.  Its a small cosmetic glitch that occurs only at start up and prior to any button presses.  When I power on I have some bits of the displays that light and create gibberish.  I was hoping you could help me out with a clear code or a small count down (33,22,11,)  to get the displays settled at power up. 


Thanks for everything
Chris-

JonnyMac

You may need to do something with your 595's, Chris.  What you may need to do is add an RC circuit to the SCLR pin to clear the outputs on power-up.  I'm on the road at the moment and can't experiment with that.  I can update your code to add a countdown, but I don't thing it will help the glitched displays.
Jon McPhalen
EFX-TEK Hollywood Office

clinefx1

I think your probably right about adding a RC circuit. A new set of the glitches happens on my satellite display after rapid sequences.  I figured out the count down part on my own,  it was rather rewarding and it solved my start up glitch. I also added more floors and changed the PH button to a floor #60 button. 

Thanks
Chris