Shop OBEX P1 Docs P2 Docs Learn Events
Stability — Parallax Forums

Stability

allatarallatar Posts: 4
edited 2013-11-14 17:37 in BASIC Stamp
Hello,

I made up a pressure sensor LED bar display using a BS2 and a fliexiforce resistive sensor. There is a 10 M ohm resistor in parallel with the flexiforce sensor and is setup usin an RCTime circuit. I am using an AC adapter. The main circuit with the RC timer is on a BS2 protoboard, the signals to drive the LED bar display are sent over a ribbon cable to another protoboard with the display drivers and LEDs. The program is pretty basic and is below.


The problem is when I have a laptop connected to it everything works just fine, when I try this without the laptop things become unstable. i.e. the LEDs will sometime light randomly.

Any suggests would be of great help,

Thanks,

Larry

' {$STAMP BS2}

' {$PBASIC 2.5}

'Test pressure sensor

' Read pressure sensor in RC-time circuit using RCTIME command

'Pin 0 = IN0 - Bit 0 on thumbwheel

'Pin 1 = IN1 - Bit 1 on thumbwheel

'Pin 2 = IN2 - Bit 2 on thumbwheel

'Pin 3 = RC Timer

'Pin 4 -> 16 Output LEDs

' 50 GR = 0 OZ = 3695

' 60 GR = 0.4 OZ = 3463

' 100 GR = 1.8 OZ = 2362

' 115 GR = 2.25 OZ = 1630

' 135 GR = 3.0 OZ = 1274

' 175 GR = 4.5 OZ = 828


TSELECT VAR Byte

time VAR Word

offset VAR Word

offset1 VAR Word

I VAR Nib
TS0 VAR Word
TS1 VAR Word
TS2 VAR Word
TS3 VAR Word
TS4 VAR Word
PP VAR Word
Mx VAR Nib
MV VAR Word


TS0 = 3463
TS1 = 2362
TS2 = 1630
TS3 = 1274
TS4 = 1000

' Set Max Pressure level (max is 1)

MP VAR Word
' LED output pins
LOW 4
LOW 5
LOW 6
LOW 7
LOW 8
LOW 9
LOW 10
LOW 11
LOW 12
LOW 13
LOW 14
LOW 15
offset1 = 0

PAUSE 1000

HIGH 3

' Turn off LEDs

LOW 4
LOW 5
LOW 6
LOW 7
LOW 8
LOW 9
LOW 10
LOW 11
LOW 12
LOW 13
LOW 14
LOW 15

' Test LEDs

PAUSE 200
HIGH 4
PAUSE 200
LOW 4
HIGH 5
PAUSE 200
LOW 5
HIGH 6
PAUSE 200
LOW 6
PAUSE 100
HIGH 7
PAUSE 200
LOW 7
HIGH 8
PAUSE 200
LOW 8
HIGH 9
PAUSE 200
LOW 9
HIGH 10
PAUSE 200
LOW 10
HIGH 11
PAUSE 200
LOW 11
HIGH 12
PAUSE 200
LOW 12
HIGH 13
PAUSE 200
LOW 13
HIGH 14
PAUSE 200
LOW 14
HIGH 15
PAUSE 400

' Calibrate - calculate offset

offset1 = 0

FOR I = 1 TO 5

HIGH 3

RCTIME 3, 1, offset

PAUSE 1000


offset1 = offset + offset1

DEBUG HOME, "time = ", DEC5 time


DEBUG " offset1 = ", DEC5 offset1

DEBUG " MP = ", DEC5 MP

DEBUG " I = ", DEC1 I

DEBUG CRSRDN

DEBUG CR


NEXT


offset = 500 + offset1/5

DEBUG " offset = ", DEC5 offset


' Read thumbwheel

IF IN0 = 0 AND IN1 = 0 AND IN2 = 0 THEN Mx = 1: MV = offset - 2700
IF IN0 = 1 AND IN1 = 0 AND IN2 = 0 THEN Mx = 1: MV = offset - 1800
IF IN0 = 0 AND IN1 = 1 AND IN2 = 0 THEN Mx = 1: MV = offset - 950
IF IN0 = 1 AND IN1 = 1 AND IN2 = 0 THEN Mx = 1: MV = offset - 750
IF IN0 = 0 AND IN1 = 0 AND IN2 = 1 THEN Mx = 1: MV = offset - 580

PP = offset


LOW 15
HIGH 14
PAUSE 200
LOW 14
HIGH 13
PAUSE 200
LOW 13
HIGH 12
PAUSE 200
LOW 12
HIGH 11
PAUSE 200
LOW 11
HIGH 10
PAUSE 200
LOW 10
HIGH 9
PAUSE 200
LOW 9
HIGH 8
PAUSE 200
LOW 8
HIGH 7
PAUSE 200
LOW 7
HIGH 6
PAUSE 200
LOW 6
HIGH 5
PAUSE 200
LOW 5
HIGH 4
PAUSE 200
LOW 4

DO

HIGH 3

PAUSE 5

RCTIME 3, 1, time


DO WHILE time = 0

RCTIME 3,1, time


LOOP

DEBUG CRSRY, 1

DEBUG CR

DEBUG "time = ", DEC5 time

DEBUG " Offset = ", DEC5 offset

DEBUG " MV = ", DEC5 MV

DEBUG " PP = ", DEC5 PP

DEBUG " Mx = ", DEC5 Mx


IF time > PP THEN time = offset
IF time > (PP - (MV*1)/(Mx*12)) THEN HIGH 4 ELSE LOW 4
IF time =< (PP - (MV*2)/(Mx*12)) THEN HIGH 5 ELSE LOW 5
IF time =< (PP - (MV*3)/(Mx*12)) THEN HIGH 6 ELSE LOW 6
IF time =< (PP - (MV*4)/(Mx*12)) THEN HIGH 7 ELSE LOW 7
IF time =< (PP - (MV*5)/(Mx*12)) THEN HIGH 8 ELSE LOW 8
IF time =< (PP - (MV*6)/(Mx*12)) THEN HIGH 9 ELSE LOW 9
IF time =< (PP - (MV*7)/(Mx*12)) THEN HIGH 10 ELSE LOW 10
IF time =< (PP - (MV*8)/(Mx*12)) THEN HIGH 11 ELSE LOW 11
IF time =< (PP - (MV*9)/(Mx*12)) THEN HIGH 12 ELSE LOW 12
IF time =< (PP - (MV*10)/(Mx*12)) THEN HIGH 13 ELSE LOW 13
IF time =< (PP - (MV*11)/(Mx*12)) THEN HIGH 14 ELSE LOW 14
IF time =< (PP - MV) THEN HIGH 15 ELSE LOW 15


LOOP

Comments

  • FranklinFranklin Posts: 4,747
    edited 2013-10-07 14:08
    Code is hard to read without indenting. If you edit your post and readd your code between [code] tags it will retain the indenting. Also if you would include a detailed description of your connections and perhaps a clear picture that might help.
  • allatarallatar Posts: 4
    edited 2013-10-07 19:52
    Hi, Here's the file again and a diagram. CR and indenting did not work, done by hand.[ '{$STAMP BS2}
    ' {$PBASIC 2.5}
    'Test pressure sensor
    ' Read pressure sensor in RC-time circuit using RCTIME command
    'Pin 0 = IN0 - Bit 0 on thumbwheel
    'Pin 1 = IN1 - Bit 1 on thumbwheel
    'Pin 2 = IN2 - Bit 2 on thumbwheel
    'Pin 3 = RC Timer
    'Pin 4 -> 16 Output LEDs

    'Weight reference grams = oz = RCTime
    ' 50 GR = 0 OZ = 3695
    ' 60 GR = 0.4 OZ = 3463
    ' 100 GR = 1.8 OZ = 2362
    ' 115 GR = 2.25 OZ = 1630
    ' 135 GR = 3.0 OZ = 1274
    ' 175 GR = 4.5 OZ = 828
    ' Variables
    time VAR Word
    offset VAR Word
    offset1 VAR Word
    I VAR Nib
    TS0 VAR Word
    TS1 VAR Word
    TS2 VAR Word
    TS3 VAR Word
    TS4 VAR Word
    Mx VAR Nib
    MV VAR Word
    MP VAR Word
    ' Initialize variables
    TS0 = 3463
    TS1 = 2362
    TS2 = 1630
    TS3 = 1274
    TS4 = 1000
    offset1 = 0
    time = 0

    ' LED output pins set LEDs Off
    LOW 4
    LOW 5
    LOW 6
    LOW 7
    LOW 8
    LOW 9
    LOW 10
    LOW 11
    LOW 12
    LOW 13
    LOW 14
    LOW 15
    PAUSE 1000
    ' Set RCTIME Initial state
    HIGH 3
    ' Test LEDs seqquence up, Calibrate, then down

    PAUSE 200
    HIGH 4
    PAUSE 200
    LOW 4
    HIGH 5
    PAUSE 200
    LOW 5
    HIGH 6
    PAUSE 200
    LOW 6
    PAUSE 100
    HIGH 7
    PAUSE 200
    LOW 7
    HIGH 8
    PAUSE 200
    LOW 8
    HIGH 9
    PAUSE 200
    LOW 9
    HIGH 10
    PAUSE 200
    LOW 10
    HIGH 11
    PAUSE 200
    LOW 11
    HIGH 12
    PAUSE 200
    LOW 12
    HIGH 13
    PAUSE 200
    LOW 13
    HIGH 14
    PAUSE 200
    LOW 14
    HIGH 15
    PAUSE 400
    ' Calibrate - calculate offset
    FOR I = 1 TO 5
    HIGH 3
    RCTIME 3, 1, offset
    PAUSE 1000
    offset1 = offset + offset1
    DEBUG HOME, "time = ", DEC5 time
    DEBUG " offset1 = ", DEC5 offset1
    DEBUG " MP = ", DEC5 MP
    DEBUG " I = ", DEC1 I
    DEBUG CRSRDN
    DEBUG CR
    NEXT
    ' Average and fudge factor offset
    offset = 500 + offset1/5
    DEBUG " offset = ", DEC5 offset
    ' Read thumbwheel
    IF IN0 = 0 AND IN1 = 0 AND IN2 = 0 THEN Mx = 1: MV = offset - 2700
    IF IN0 = 1 AND IN1 = 0 AND IN2 = 0 THEN Mx = 1: MV = offset - 1800
    IF IN0 = 0 AND IN1 = 1 AND IN2 = 0 THEN Mx = 1: MV = offset - 950
    IF IN0 = 1 AND IN1 = 1 AND IN2 = 0 THEN Mx = 1: MV = offset - 750
    IF IN0 = 0 AND IN1 = 0 AND IN2 = 1 THEN Mx = 1: MV = offset - 580
    ' Test LEDs sequence down
    LOW 15
    HIGH 14
    PAUSE 200
    LOW 14
    HIGH 13
    PAUSE 200
    LOW 13
    HIGH 12
    PAUSE 200
    LOW 12
    HIGH 11
    PAUSE 200
    LOW 11
    HIGH 10
    PAUSE 200
    LOW 10
    HIGH 9
    PAUSE 200
    LOW 9
    HIGH 8
    PAUSE 200
    LOW 8
    HIGH 7
    PAUSE 200
    LOW 7
    HIGH 6
    PAUSE 200
    LOW 6
    HIGH 5
    PAUSE 200
    LOW 5
    HIGH 4
    PAUSE 200
    LOW 4

    time = 0
    DO
    HIGH 3
    PAUSE 5
    RCTIME 3, 1, time
    DO WHILE time = 0
    RCTIME 3,1, time
    LOOP
    DEBUG CRSRY, 1
    DEBUG CR
    DEBUG "time = ", DEC5 time
    DEBUG " Offset = ", DEC5 offset
    DEBUG " MV = ", DEC5 MV
    DEBUG " Mx = ", DEC5 Mx
    ' Light up LED bar topressure level
    IF time > offset THEN time = offset
    IF time > (offset - (MV*1)/(Mx*12)) THEN HIGH 4 ELSE LOW 4
    IF time =< (offset - (MV*2)/(Mx*12)) THEN HIGH 5 ELSE LOW 5
    IF time =< (offset - (MV*3)/(Mx*12)) THEN HIGH 6 LOW 6
    IF time =< (offset - (MV*4)/(Mx*12)) THEN HIGH 7 ELSE LOW 7
    IF time =< (offset - (MV*5)/(Mx*12)) THEN HIGH 8 ELSE LOW 8
    IF time =< (offset - (MV*6)/(Mx*12)) THEN HIGH 9 ELSE LOW 9
    IF time =< (offset - (MV*7)/(Mx*12)) THEN HIGH 10 ELSE LOW 10
    IF time =< (offset - (MV*8)/(Mx*12)) THEN HIGH 11 ELSE LOW 11
    IF time =< (offset - (MV*9)/(Mx*12)) THEN HIGH 12 ELSE LOW 12
    IF time =< (offset - (MV*10)/(Mx*12)) THEN HIGH 13 ELSE LOW 13
    IF time =< (offset - (MV*11)/(Mx*12)) THEN HIGH 14 ELSE LOW 14
    IF time =< (offset - MV) THEN HIGH 15 ELSE LOW 15

    LOOP
    END]
    diagram.jpg
    796 x 586 - 23K
  • GadgetmanGadgetman Posts: 2,436
    edited 2013-10-08 05:50
    allatar wrote: »
    Hi, Here's the file again and a diagram. CR and indenting did not work, done by hand.
     '{$STAMP BS2}
     ' {$PBASIC 2.5}
     'Test pressure sensor
     ' Read pressure sensor in RC-time circuit using RCTIME command
     'Pin 0 = IN0 - Bit 0 on thumbwheel
      'Pin 1 = IN1 - Bit 1 on thumbwheel
      'Pin 2 = IN2 - Bit 2 on thumbwheel
      'Pin 3 = RC Timer
     'Pin 4 -> 16 Output LEDs
     
      'Weight reference grams = oz = RCTime
        ' 50 GR = 0 OZ = 3695
        ' 60 GR = 0.4 OZ = 3463
        ' 100 GR = 1.8 OZ = 2362
        ' 115 GR = 2.25 OZ = 1630
        ' 135 GR = 3.0 OZ = 1274
        ' 175 GR = 4.5 OZ = 828
    ' Variables
     time VAR Word
     offset VAR Word
     offset1 VAR Word
     I VAR Nib
     TS0 VAR Word
     TS1 VAR Word
     TS2 VAR Word
     TS3 VAR Word
     TS4 VAR Word
     Mx VAR Nib
     MV VAR Word
     MP VAR Word
    ' Initialize variables
        TS0 = 3463
        TS1 = 2362
        TS2 = 1630
        TS3 = 1274
        TS4 = 1000
        offset1 = 0
        time = 0
    
     ' LED output pins set LEDs Off
      LOW 4
      LOW 5
      LOW 6
      LOW 7
      LOW 8 
      LOW 9
      LOW 10
      LOW 11
      LOW 12
      LOW 13
      LOW 14
      LOW 15
     PAUSE 1000
    '  Set RCTIME Initial state
       HIGH 3
     ' Test LEDs seqquence up, Calibrate, then down
      
      PAUSE 200
      HIGH 4
      PAUSE 200
      LOW 4
      HIGH 5
      PAUSE 200
      LOW 5
      HIGH 6
      PAUSE 200
      LOW 6
      PAUSE 100
      HIGH 7
      PAUSE 200
      LOW 7
      HIGH 8
      PAUSE 200
      LOW 8
      HIGH 9
      PAUSE 200
       LOW 9
      HIGH 10
      PAUSE 200
      LOW 10
      HIGH 11
      PAUSE 200
      LOW 11
      HIGH 12
      PAUSE 200
      LOW 12
      HIGH 13
      PAUSE 200
      LOW 13
      HIGH 14
      PAUSE 200
      LOW 14
      HIGH 15
      PAUSE 400
     ' Calibrate - calculate offset
             FOR I = 1 TO 5
                 HIGH 3
                 RCTIME 3, 1, offset
                 PAUSE 1000
                 offset1 = offset + offset1
                 DEBUG HOME, "time = ", DEC5 time
                 DEBUG " offset1 = ", DEC5 offset1
                 DEBUG " MP = ", DEC5 MP
                 DEBUG " I = ", DEC1 I
                 DEBUG CRSRDN
                 DEBUG CR
             NEXT
    ' Average and fudge factor offset
        offset = 500 + offset1/5
     DEBUG " offset = ", DEC5 offset
     ' Read thumbwheel
       IF IN0 = 0 AND IN1 = 0 AND IN2 = 0 THEN Mx = 1: MV = offset - 2700
        IF IN0 = 1 AND IN1 = 0 AND IN2 = 0 THEN Mx = 1: MV = offset - 1800
       IF IN0 = 0 AND IN1 = 1 AND IN2 = 0 THEN Mx = 1: MV = offset - 950
       IF IN0 = 1 AND IN1 = 1 AND IN2 = 0 THEN Mx = 1: MV = offset - 750
       IF IN0 = 0 AND IN1 = 0 AND IN2 = 1 THEN Mx = 1: MV = offset - 580
    ' Test LEDs sequence down
      LOW 15
      HIGH 14
      PAUSE 200
      LOW 14
      HIGH 13
      PAUSE 200
      LOW 13
      HIGH 12
      PAUSE 200
      LOW 12
      HIGH 11
      PAUSE 200
      LOW 11
      HIGH 10
      PAUSE 200
      LOW 10
      HIGH 9
      PAUSE 200
      LOW 9
      HIGH 8
      PAUSE 200
      LOW 8
      HIGH 7
      PAUSE 200
      LOW 7
      HIGH 6
      PAUSE 200
      LOW 6
      HIGH 5
      PAUSE 200
      LOW 5
      HIGH 4
      PAUSE 200
      LOW 4
    
    time = 0
     DO
            HIGH 3
            PAUSE 5
            RCTIME 3, 1, time
                         DO WHILE time = 0
                                RCTIME 3,1, time
                         LOOP
                DEBUG CRSRY, 1
                DEBUG CR
                DEBUG "time = ", DEC5 time
                DEBUG " Offset = ", DEC5 offset
                DEBUG " MV = ", DEC5 MV
                DEBUG " Mx = ", DEC5 Mx
              '  Light up LED bar topressure level
              IF time > offset THEN time = offset
              IF time > (offset - (MV*1)/(Mx*12)) THEN HIGH 4 ELSE LOW 4
              IF time =< (offset - (MV*2)/(Mx*12)) THEN HIGH 5 ELSE LOW 5
              IF time =< (offset - (MV*3)/(Mx*12)) THEN HIGH 6 LOW 6
              IF time =< (offset - (MV*4)/(Mx*12)) THEN HIGH 7 ELSE LOW 7
              IF time =< (offset - (MV*5)/(Mx*12)) THEN HIGH 8 ELSE LOW 8
              IF time =< (offset - (MV*6)/(Mx*12)) THEN HIGH 9 ELSE LOW 9
              IF time =< (offset - (MV*7)/(Mx*12)) THEN HIGH 10 ELSE LOW 10
              IF time =< (offset - (MV*8)/(Mx*12)) THEN HIGH 11 ELSE LOW 11
              IF time =< (offset - (MV*9)/(Mx*12)) THEN HIGH 12 ELSE LOW 12
              IF time =< (offset - (MV*10)/(Mx*12)) THEN HIGH 13 ELSE LOW 13
              IF time =< (offset - (MV*11)/(Mx*12)) THEN HIGH 14 ELSE LOW 14
              IF time =< (offset - MV) THEN HIGH 15 ELSE LOW 15
    
     LOOP 
    END
    

    See?
  • allatarallatar Posts: 4
    edited 2013-10-10 19:19
    Ok thanks, that looks a lot better.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-10-15 10:12
    I think he was pointing out that with CODE tags your code could look like this:
    ' -----[ Initialization ]--------------------------------------------------
    
    Reset:
      HIGH TX                               ' setup serial output pin
      PAUSE 100                             ' allow LCD to initialize
    
    
    DnLoad_Custom_Chars:
      FOR idx1 = 0 TO 35                    ' download 4 characters
        READ CC0 + idx1, char               ' get data from table
        SEROUT TX, LcdBaud, [char]          ' send to LCD
      NEXT
    
    
    
    
    ' -----[ Program Code ]----------------------------------------------------
    
    
    ' Clear the display and remove cursor and blinking attributes.
    
    
    Main:
      SEROUT TX, LcdBaud, [LcdBLoff, LcdOn1, LcdCls]
      PAUSE 250
      SEROUT TX, LcdBaud, ["THE BASIC STAMP"]
    
    
    
    
    ' Scroll "chomper" animation across LCD line 2
    
    
    Animation:
      FOR idx1 = 0 TO 15                    ' scroll across line
        READ (Msg2 + idx1), newChar         ' read new character
        FOR idx2 = 0 TO 4                   ' animate a current position
          LOOKUP idx2, [0, 1, 2, 1, newChar], char
          SEROUT TX, LcdBaud, [(LcdLine2 + idx1), char]
          PAUSE 75
        NEXT
      NEXT
    
    
    

    Instead of like this:

    '
    [ Initialization ]


    Reset:
    HIGH TX ' setup serial output pin
    PAUSE 100 ' allow LCD to initialize


    DnLoad_Custom_Chars:
    FOR idx1 = 0 TO 35 ' download 4 characters
    READ CC0 + idx1, char ' get data from table
    SEROUT TX, LcdBaud, [char] ' send to LCD
    NEXT




    '
    [ Program Code ]


    ' Clear the display and remove cursor and blinking attributes.


    Main:
    SEROUT TX, LcdBaud, [LcdBLoff, LcdOn1, LcdCls]
    PAUSE 250
    SEROUT TX, LcdBaud, ["THE BASIC STAMP"]




    ' Scroll "chomper" animation across LCD line 2


    Animation:
    FOR idx1 = 0 TO 15 ' scroll across line
    READ (Msg2 + idx1), newChar ' read new character
    FOR idx2 = 0 TO 4 ' animate a current position
    LOOKUP idx2, [0, 1, 2, 1, newChar], char
    SEROUT TX, LcdBaud, [(LcdLine2 + idx1), char]
    PAUSE 75
    NEXT
    NEXT



    Of course, I would just attach the code if it is a whole program. That would be the ideal way to look at it within the editor. :nerd:
  • bsjohnbsjohn Posts: 19
    edited 2013-10-15 18:45
    I wonder if your AC power adapter is noisy causing your stability issue. Try using a battery instead or different power adapter.
  • allatarallatar Posts: 4
    edited 2013-11-14 17:37
    Sorry, for the long delay in replying, but I did resolve the issue.

    The term Mx is multiplied by 12 and was exceeding 65536. This must have caused some rollover and generated random lighting of the LEDs.

    I fixed this be adjusting the circuit so that it would not go over 5000 and also testing the value just in case it did go over 5000 and limited it to 5000.
Sign In or Register to comment.