Shop OBEX P1 Docs P2 Docs Learn Events
need someone to look code over, lcd will not display data, and alarm will not reset — Parallax Forums

need someone to look code over, lcd will not display data, and alarm will not reset

sport270sport270 Posts: 82
edited 2013-10-22 13:21 in BASIC Stamp
' {$STAMP BS2}
' {$PBASIC 2.5}
' -----[ I/O Definitions ]-------------------------------------------------
TX              PIN     15              ' serial output to LCD

' -----[ Constants ]-------------------------------------------------------
#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T2400       CON     396
    T9600       CON     84
    T19K2       CON     32
  #CASE BS2SX, BS2P
    T2400       CON     1021
    T9600       CON     240
    T19K2       CON     110
  #CASE BS2PX
    T2400       CON     1646
    T9600       CON     396
    T19K2       CON     188
#ENDSELECT
LcdBaud         CON     T19K2
LcdBkSpc        CON     $08             ' move cursor left
LcdRt           CON     $09             ' move cursor right
LcdLF           CON     $0A             ' move cursor down 1 line
LcdCls          CON     $0C             ' clear LCD (use PAUSE 5 after)
LcdCR           CON     $0D             ' move pos 0 of next line
LcdBLon         CON     $11             ' backlight on
LcdBLoff        CON     $12             ' backlight off
LcdOff          CON     $15             ' LCD off
LcdOn1          CON     $16             ' LCD on; cursor off, blink off
LcdOn2          CON     $17             ' LCD on; cursor off, blink on
LcdOn3          CON     $18             ' LCD on; cursor on, blink off
LcdOn4          CON     $19             ' LCD on; cursor on, blink on
LcdLine1        CON     $80             ' move to line 1, column 0
LcdLine2        CON     $94             ' move to line 2, column 0
LcdCC0          CON     $F8             ' define custom char 0
LcdCC1          CON     $F9             ' define custom char 1
LcdCC2          CON     $FA             ' define custom char 2
LcdCC3          CON     $FB             ' define custom char 3
LcdCC4          CON     $FC             ' define custom char 4
LcdCC5          CON     $FD             ' define custom char 5
LcdCC6          CON     $FE             ' define custom char 6
LcdCC7          CON     $FF             ' define custom char 7
'
DIR0 = 0               'pin to read left saw or X1X
DIR1 = 0               'pin to read right saw or X2X
DIR2 = 0               'Pin to read xauger or X3X
DIR3 = 0               'pin to read pot for alarms on saws or A1A and is also A2A
DIR4 = 0               'pin to read pot for alarm on xauger or A2A
DIR5 = 0               'pin to turn on buzzer connected to blue pulsing buzzer through transistor
DIR6 = 0               'pin to turn on led for alarm
DIR7 = 0               ' pin saved to read GROUND SPEED at later date
DIR8 = 0                '
DIR9 = 0     '
DIR10 = 0    '
DIR11 = 0    '
DIR12 = 0    '
DIR13 = 0     '
DIR14 = 0    '
DIR15 = 0    '
'
' -----[ Variables ]-------------------------------------------------------
X1X             VAR     Word            ' variable tag for rpm value of Left saw
X2X             VAR     Word            ' variable tag for rpm value of right saw
X3X             VAR     Word            ' variable tag for rpm value of xauger
A1A             VAR     Word            ' variable tag for alarm set point of BOTH saws
A2A             VAR     Word            ' variable tag for alarm set point of auger
A3A             VAR     Word            ' variable tag for alarm set point of right saw BUT REALLY EQUAL TO A1A
ALARM    VAR     Word    ' variable tag to turn on alarm
' -----[ Initialization ]--------------------------------------------------
Reset:
  HIGH TX                               ' setup serial output pin
  PAUSE 100                             ' allow LCD to initialize

' -----[ Program Code ]----------------------------------------------------
' Clear the display and remove cursor and blinking attributes.
Main:
  SEROUT TX, LcdBaud, [LcdBLon, LcdOn1, LcdCls]
  PAUSE 100
 '
GOSUB Pot_SAWS          ' GET pot for alarms on saws
'
GOSUB Pot_XAUGER        ' GET pot for alarm on Xauger
'
GOSUB X1X_SPEED    'GET SPEED OF LEFT SAW WITH COUNT
'
GOSUB X2X_SPEED      'GET SPEED OF RIGHT SAW WITH COUNT
'
GOSUB X3X_SPEED     'GE  SPEED OF XAUGER WITH COUNT
'
GOSUB Compare           ' compare rpms to alarm set points
'
'gosub Set_ALARMS        ' did this in compare
'
GOSUB Update_LCD       ' refreshes lcd display
'
'
'
GOTO main             '
'
 '
' -----[ Subroutines ]-----------------------------------------------------
Update_LCD:
  SEROUT TX, LcdBaud, [LcdLine1, "  ", DEC3 X1X, "  ", DEC3 X3X, "  ", DEC3 X2X]
  SEROUT TX, LcdBaud, [LcdLine2, "  ", DEC3 A1A, "  ", DEC3 A3A, "  ", DEC3 A2A]
  RETURN
 
 

'NEW CODE BLOCKS************************************
'
'
'
'
'
'*************************************
Pot_SAWS:    'input pin 03  .. 10K TRIMPOT,  .1uf cap and 220 ohm in series to
'
A1A = 0      'reset to 0
HIGH 3       'precharge the cap
PAUSE 100    '
RCTIME 3,1,A1A    '
PAUSE 10    '
'debug "A1A is   ",dec A1A,CR  'used to get real scale
'
'
A1A = A1A+0        ' Add to or change scale to get into the range needed
'
DEBUG "A1A is   ",DEC A1A,CR  '
'
PAUSE 100    '
'
A2A = A1A    'sets alarm for right saw the same as left
'
RETURN      '
'******************************
'
'
'
Pot_Xauger:    'input pin 04  .. 10K TRIMPOT,  .1uf cap and 220 ohm in series to
'
A3A = 0      'reset to 0
HIGH 4       'precharge the cap
PAUSE 100    '
RCTIME 4,1,A3A    '
PAUSE 10    '
'debug "A3A is   ",dec A3A,CR  'used to get real scale
'
'
A3A = A3A+0        ' Add to or change scale to get into the range needed
'
DEBUG "A3A is   ",DEC A3A,CR  '
'
PAUSE 100    '
'
'
RETURN      '
'
'
'**********************************
'
'
X1X_SPEED:    'get speed of left saw on pin 0
'
COUNT 0,500,X1X    ' count pin 0 for 1/2 second
X1X = X1X*2    ' correct reading to full second
DEBUG "X1X IS   ", DEC X1X,CR  '
PAUSE 100    '
RETURN      '
'
'
'###################################
'
'
X2X_SPEED:    'get speed of left saw on pin 1
'
COUNT 1,500,X2X    ' count pin 1 for 1/2 second
X2X = X2X*2    ' correct reading to full second
DEBUG "X2X IS   ",DEC X2X,CR  '
PAUSE 100    '
RETURN      '
'
'
'**********************************
'
'
X3X_SPEED:    'get speed of left saw on pin 2
'
COUNT 2,500,X3X    ' count pin 2 for 1/2 second
X3X = X3X*2    ' correct reading to full second
DEBUG "X3X IS   ",DEC X3X,CR  '
PAUSE 100    '
RETURN      '
'
'
'********************************
'
'
COMPARE:    ' COMPARE SPEEDS TO ALARM SETPOINTS
'
ALARM = 0     '
IF X1X  < A1A THEN X2  '
ALARM = ALARM +1  'FLAG TO SET ALARM IF ANY ARE BELOW SETPOINT
'
x2:       '
IF X2X < A2A THEN X3  '
ALARM = ALARM +1    ' FLAG FOR ALARM
'
X3:      '
IF X3X < A3A THEN Alarm_SET    '
ALARM = ALARM +1    '
'
Alarm_SET:       '
'
'
IF ALARM >0 THEN A_ON  '
ALARM=0        'RESET ALARM FLAG
DEBUG "alarm off",CR        '
LOW 5        'TURNS OFF BUZZER
LOW 6        'TURNS OFF LED
'
RETURN
'
'
A_ON:        'TURNS ON ALARMS & BUZZER
DEBUG "alarm on", CR          '
HIGH 5        'turn on buzzer
HIGH 6        'TURN ON LED
PAUSE 100      'PAUSE LONG ENOUGH TO CHARGE CAP TO KEEP LED & BUZZER CONSTANT AND NOT INTERMITTENT
'ALARM=0        'RESET ALARM FLAG
'LOW 5        'TURNS OFF BUZZER
'LOW 6        'TURNS OFF LED
'
RETURN
 '
'
'Z**********************************

Comments

  • sport270sport270 Posts: 82
    edited 2013-10-17 18:55
    OK, after looking at sample code provided by chris, (thanks, Chris) I found the lcd problem. I had goto main at bottom, and when replaced with loop: it worked ......except it only makes one pass then stops
  • sport270sport270 Posts: 82
    edited 2013-10-18 04:59
    thanks all for your suggestions. I got it working, simple address relocation, and had to change one of the <> . also had to add gosub update_lcd in a few more places to keep screen from blinking. now I just need to add a transistor for the buzzer.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-10-18 14:54
    OK, after looking at sample code provided by chris, (thanks, Chris) I found the lcd problem. I had goto main at bottom, and when replaced with loop: it worked ......except it only makes one pass then stops

    Interesting...the code you had should have worked if you moved the LCD init code above Main. Replacing the GOTO with a LOOP should have caused a LOOP without DO error.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-10-18 14:57
    thanks all for your suggestions. I got it working, simple address relocation, and had to change one of the <> . also had to add gosub update_lcd in a few more places to keep screen from blinking. now I just need to add a transistor for the buzzer.

    The LCD shouldn't do any blinking unless you are executing the following block of code repeatedly.
    Main:  SEROUT TX, LcdBaud, [LcdBLon, LcdOn1, LcdCls]
      PAUSE 100
    
    
    

    This code should only ever execute once. The Update_LCD routine is designed to overwrite the entire screen in such a way that you should never have to clear it and should not see any blink.
  • sport270sport270 Posts: 82
    edited 2013-10-22 12:56
    lcd.jpg

    anyone ever see this happen. the top row gets three signals into the bs2, and displays the three speeds across top, the bottom row has three alarm setpoints that go with the speeds on the top row, and sound an alarm and led if the speed drops below the set point. this worked for about a day, now display shows this. and the center speed is no longer showing the speed of the signal.
    i ran the signal speed of a mag pickup coil sensor thru a 220ohm resister then through, a In4004 diode with stripe facing sensor, then had a 4.7v zenier diode to ground and a 100k to +5v then straight into bs2. schematic below. lcd is 16x2 backlit serial connection
    bs2_lcd_schematic 1.jpeg
    640 x 477 - 72K
    548 x 251 - 30K
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-10-22 13:21
    As per our earlier conversation I would test this by swapping out the display with a known good unit. If you get the same results your program has been somehow corrupted.
Sign In or Register to comment.