Shop OBEX P1 Docs P2 Docs Learn Events
need bs2 code for 3 channel hz meter displayed on 2x16 backlit lcd — Parallax Forums

need bs2 code for 3 channel hz meter displayed on 2x16 backlit lcd

sport270sport270 Posts: 82
edited 2013-10-18 13:45 in BASIC Stamp
hate to be so needy all the time... i have three 500-650 hz signals that i need to use the COUNT method over 1/2 second to display rpm on a 2x16 backlit lcd screen. i have used the count method before but only to the debug screen. have no idea how to make it goto the lcd screen. i can submit the code i used in the past if the would help. Thanks for anyones time to help. this is used on a custom built cotton harvester. A John Deere 7760 Round Bale Picker that we converted to a Dual burr extracted 16 row stripper. We control all the row units height sensing with proportional controls and pwm control of pumps for hydraulic flow control. I am on the way to deliver this console and woud really like to be able to upload the code for lcd screen today. Jeff Kirk Farm Enhancement Systems 806-767-0715 sport270@yahoo.com

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2013-10-11 08:47
    What LCD is it? There are some that have a serial interface with commands that allow you to send data to it much as you would to the debug screen. Others have a parallel interface where you will need to use the BS2 DIG command to break your value down into digits to send to the screen.

    For idx = 5 to 0
    char = value DIG idx ' pick off the digits with leading zeros
    GOSUB sendChar2LCD
    NEXT

    There are excellent tutorials on LCDs, for example, there is a chapter on Using Character LCDs in Stampworks, download from Parallax.com.
  • sport270sport270 Posts: 82
    edited 2013-10-11 16:26
    serial parallax # 27977-rt
  • sport270sport270 Posts: 82
    edited 2013-10-12 06:20
    7760_HHC.jpg
    this is a jpg of the control console with lcd
    640 x 477 - 80K
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-10-15 10:43
    As per our conversation, the code to update the display in the manner you mentioned is:
    Update_LCD:  
      SEROUT TX, LcdBaud, [LcdLine1, "  ", DEC3 X1X, "  ", DEC3 X3X, "  ", DEC3 X2X]
      SEROUT TX, LcdBaud, [LcdLine2, "  ", DEC3 A1A, "  ", DEC3 A3A, "  ", DEC3 A2A]
      RETURN
    

    Of course, this requires the variables used to all have been set in advance and the attached example code sets things up. I hope this helps.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-10-15 10:51
    As a note, to save code space in EEPROM that can be put on one line:
    Update_LCD:  
      SEROUT TX, LcdBaud, [LcdLine1, "  ", DEC3 X1X, "  ", DEC3 X3X, "  ", DEC3 X2X, LcdLine2, "  ", DEC3 A1A, "  ", DEC3 A3A, "  ", DEC3 A2A]
      RETURN
    
  • sport270sport270 Posts: 82
    edited 2013-10-17 10:55
    ' {$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#ENDSELECTLcdBaud         CON     T19K2LcdBkSpc        CON     $08             ' move cursor leftLcdRt           CON     $09             ' move cursor rightLcdLF           CON     $0A             ' move cursor down 1 lineLcdCls          CON     $0C             ' clear LCD (use PAUSE 5 after)LcdCR           CON     $0D             ' move pos 0 of next lineLcdBLon         CON     $11             ' backlight onLcdBLoff        CON     $12             ' backlight offLcdOff          CON     $15             ' LCD offLcdOn1          CON     $16             ' LCD on; cursor off, blink offLcdOn2          CON     $17             ' LCD on; cursor off, blink onLcdOn3          CON     $18             ' LCD on; cursor on, blink offLcdOn4          CON     $19             ' LCD on; cursor on, blink onLcdLine1        CON     $80             ' move to line 1, column 0LcdLine2        CON     $94             ' move to line 2, column 0LcdCC0          CON     $F8             ' define custom char 0LcdCC1          CON     $F9             ' define custom char 1LcdCC2          CON     $FA             ' define custom char 2LcdCC3          CON     $FB             ' define custom char 3LcdCC4          CON     $FC             ' define custom char 4LcdCC5          CON     $FD             ' define custom char 5LcdCC6          CON     $FE             ' define custom char 6LcdCC7          CON     $FF             ' define custom char 7'DIR0 = 0               'pin to read left saw or X1XDIR1 = 0               'pin to read right saw or X2XDIR2 = 0               'Pin to read xauger or X3XDIR3 = 0               'pin to read pot for alarms on saws or A1A and is also A2ADIR4 = 0               'pin to read pot for alarm on xauger or A2ADIR5 = 0               'pin to turn on buzzer connected to blue pulsing buzzer through transistorDIR6 = 0               'pin to turn on led for alarmDIR7 = 0               ' pin saved to read GROUND SPEED at later dateDIR8 = 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 sawX2X             VAR     Word            ' variable tag for rpm value of right sawX3X             VAR     Word            ' variable tag for rpm value of xaugerA1A             VAR     Word            ' variable tag for alarm set point of BOTH sawsA2A             VAR     Word            ' variable tag for alarm set point of augerA3A             VAR     Word            ' variable tag for alarm set point of right saw BUT REALLY EQUAL TO A1AALARM    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 0HIGH 3       'precharge the capPAUSE 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 0HIGH 4       'precharge the capPAUSE 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 secondX1X = X1X*2    ' correct reading to full secondDEBUG "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 secondX2X = X2X*2    ' correct reading to full secondDEBUG "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 secondX3X = X3X*2    ' correct reading to full secondDEBUG "X3X IS   ",DEC X3X,CR  'PAUSE 100    'RETURN      ''''********************************''COMPARE:    ' COMPARE SPEEDS TO ALARM SETPOINTS'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 FLAGDEBUG "alarm off",CR        'LOW 5        'TURNS OFF BUZZERLOW 6        'TURNS OFF LED'RETURN''A_ON:        'TURNS ON ALARMS & BUZZERDEBUG "alarm on", CR          'HIGH 5        'turn on buzzerHIGH 6        'TURN ON LEDPAUSE 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**********************************
    
  • sport270sport270 Posts: 82
    edited 2013-10-17 10:58
    need help, debug actually works, shows 3 frequency values, alarms show setpoints, but do not trigger or funcction when signals go below the same value from alarm setpoints from rctime.
    and lcd display does not work, it beeps every few seconds and shows a random 8 and { and no backlight
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-10-17 11:05
    Not sure what happened to your code...on my screen the code block is corrupted and unreadable. As for the LCD the most likely thing is that the baud rate value doesn't match the DIP Switch settings on the back. What are the switches set to? What is the baud rate value in the code? I always use 19.2K on my displays so I have both DIP Switches set to ON.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-10-17 11:09
    When you post code, please correct your line endings. What you've posted shows up all as one continuous line and is unreadable, certainly to me. Also be sure to use code tags with [ code ] before the code and [ /code ] after the code (without the extra spaces inside the square brackets). If you don't use the code brackets, any indenting will be "eaten" by the forum software.


    attachment.php?attachmentid=78421&d=1297987572
  • sport270sport270 Posts: 82
    edited 2013-10-17 12:26
    ' {$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
    '
    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**********************************
    
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-10-18 13:45
    Did you see my reply about the LCD? Did it work?
Sign In or Register to comment.