Shop OBEX P1 Docs P2 Docs Learn Events
Bean...a question or two..please... — Parallax Forums

Bean...a question or two..please...

Reference propbasic..How many "LONG(s) are allowed in a COG...and are there more of them used in COG 0 to run or convert the propbasic to spin? I have notice an ERROR at the bottom of the download page that says I have exceeded the number of longs by 27. The program still loads, but in this particular, COG, I do get strange results..mainly, some of the SEROUT to the LCD, does not display...

Also, is there some "secret" way of using the SEROUT command, in the same manner as using the command in the Basic Stamp. Meaning with a comma delimiter between each instruction, instead of using the SEROUT command with only one instruction at a time...? Hope I am making since..thanks...DennO

Comments

  • BeanBean Posts: 8,129
    Each cog has 496 longs free for both code and variables.
    PropBasic is NOT converted to spin. It is converted directly to assembly language on the PC.

    You need to put SEROUT in a subroutine to save code space.

    Bean
  • dennodenno Posts: 223
    edited 2018-08-28 21:44
    Good idea...SUBROUTINE..

    So, when I "build" my program and at the bottom it says "Program size is 3380 LONGS" Is that everything all together. I notice if I should exceed a certain amount of the Program size, some where around 3470 LONGS, I will still get a successful download, to RAM and even EEPROM, but the last part of the program will not work...the part before I ran out of room. I am guessing. Is that right?

    BTW, there is infact 199 lines of code in the complete program...as stated below...so the complier did see the whole program, but just did not compile the whole program?

    And, thanks for all your time and effort in building PROPBASIC...as some of us are just "basic" people...DennO
    PropBasic Version 00.01.48 Aug 9, 2018
    Finished Compile. 199 Lines Read, 910 Lines Generated,  0 Warnings, 0 Errors.
    
    Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved
    Compiled for i386 Win32 at 08:17:48 on 2009/07/20
    Loading Object LCDdisplay_SE
    Loading Object LCD_1.spin
    Loading Object temperature_1.spin
    Loading Object temperature_2.spin
    Lo
    ading Object volt_measure.spin
    Program size is 3380 longs
    Compiled 1176 Lines of Code in 0.076 Seconds
    
    
  • pmrobertpmrobert Posts: 673
    edited 2018-08-28 23:00
    Denno, are you using LMM mode at all for any of that code? It almost sounds like you're not and cog mode is most certainly a)quite restrictive re code size for that particular cog and b)very likely absolutely not necessary for your program. Cog (native) mode is the default and is very, very fast but only really needed for very time critical functions. LMM is somewhat slower but still extremely fast AND lets your code stretch it's legs with the vastly increased potential size for each cog. Post your current code and let's have a look.

    Mike R...
  • pmrobert..thank you for your "instruction", as I did add "LMM" after each TASK as seen in the code, and that did make the difference. Keep in mind that this code is just for practice, as I wanted to get each COG to run something different, and then display that COG(s) result on my display...and my first attempt at using the prop...

    As a footnote, I like to set alot of things to CONSTANTS, and use descriptive words to describe various variables...makes for easier reading of the code...I just purchased a FLIP, and have an embedded project for that. Presently, using the PROP Activity board that was sent to me for free, many years ago, when the PROP first came out...even with the Manual..1.0.

    Readers, please don't take this the wrong way, but I don't like using other peoples "OBJECT(s)" in SPIN, as I find alot of them very hard to read, especially, in assembly language. That is why I always liked PBASIC for the stamp, and now, propbasic for the prop..

    pmrobert, one last question...is the STACK directive necessary in propbasic (LMM mode?)

    The next thing I need to figure out is how to set up a SUB ROUTINE for the SEROUT out commands to save code space.

    thank you again...DennO
    DEVICE P8X32A, XTAL1, PLL16X
    XIN 5_000_000
    'STACK 100
    '========CONSTANTS============
    baud                   CON "N9600"
    carr_return            CON  13   
    clrLCD                 CON  12          'clear the screen on the lcd
    posCMD                 CON  16          'position the curser command
    hideCUR                CON   4           'hide the curser command
    blinkCUR               CON   6           'blink the curser command
    degreeSYM              CON 223           'the "degree" symbol
    receive_data           CON 255
    backLTon               CON  14          'turn the back light on
    backLToff              CON  15          'turn the back light off
    brightness_ctl         CON  27
    quarter_bright         CON  48
    half_bright            CON  49
    three_quarter_bright   CON  50
    full_bright            CON  51
    beep                   CON   7           'beep command
    right_align            CON  18          'RIGHT ALIGN COMMAND
    start_big_char         CON   2
    end_big_char           CON   3
    astrike                CON  42
    block_char             CON 134
    carReturn              CON  13          'carriage return command
    blank_char             CON  32
    left_arrow             CON 127
    right_arrow            CON 126
    LR_arrow               CON 131
    LL_arrow               CON 128
    UR_arrow               CON 129
    UL_arrow               CON 130
    down_arrow             CON 132
    up_arrow               CON 133
    equal_sign             CON  61
    first_line             CON  64
    second_line            CON 104 
    no_char                CON 0    
    
    '======== HUB VARIABLES==============
    degrees_1                  HUB  LONG 'location of temp_1 data
    temp_1DEC                HUB  string(3)
    degrees_2                  HUB  LONG'LONG 'location of temp_2 data
    temp_2DEC                HUB  string(3)
    volt_location              HUB  LONG  'location of volt data
    tenth_location            HUB  LONG
    hunds_location           HUB  LONG
    actualVOLT                 HUB string(10)
    actualVOLTtenth         HUB string (10)
    actualVOLThunds        HUB string  (10)
    '========PIN ASSIGNMENTS========
    '
    'Assignments of pin go in each COG that is using that pin..
    
    '============CODE===============
      LCD_1 TASK   
      temperature_1 TASK
      temperature_2 TASK
      volt_measure  TASK
      LED_blue      PIN 1
    PROGRAM Start  'this is running in COG 0
      Start:
      COGINIT LCD_1, 7         'cog 7
      COGINIT temperature_1, 5 'cog 5
      COGINIT temperature_2, 6 'cog 6
      COGINIT volt_measure, 4  'cog 4
      DO              'this do/loop is just something for COG 0 to do...
        PAUSE 500
        TOGGLE LED_blue
        PAUSE 500
      LOOP
    END
    '===============================================
    TASK LCD_1 LMM         'this TASK is running in COG 7   
      temp_1           VAR  LONG  'the temp_1erature data, itself..
      temp_2           VAR  LONG
      stringVOLT       VAR  LONG
      stringVOLTtenth  VAR  LONG
      stringVOLThunds  VAR  LONG
      LCD_data_out     PIN  2   
    'Define a string variable:
    '   string1  HUB STRING(3)
    'Use STR to place the ASCII' representation of temp_1's value into a string
    '   string1 = STR temp_1,3
    'THEN display it.
    '   SEROUT LCD_data_out, baud, string1 
         SEROUT LCD_data_out, baud, clrLCD
         SEROUT LCD_data_out, baud, beep
         SEROUT LCD_data_out, baud, backLTon
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 64
         SEROUT LCD_data_out, baud, "TEMPERATURE IS"
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 84
         SEROUT LCD_data_out, baud, "TEMPERATURE IS"
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 104
         SEROUT LCD_data_out, baud, "VOLTAGE="
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 119
         SEROUT LCD_data_out, baud, "volts"
     DO  
         RDLONG degrees_1, temp_1  'reading the temperature data that is in the HUB
         PAUSE 100
         temp_1DEC = STR temp_1,3
         RDLONG degrees_2, temp_2  'reading the temperature data that is in the HUB
         PAUSE 100
         temp_2DEC = STR temp_2,3
         RDLONG volt_location, stringVOLT
         PAUSE 100
         RDLONG tenth_location, stringVOLTtenth
         PAUSE 100
         RDLONG hunds_location, stringVOLThunds
         PAUSE 100
         actualVOLT = STR stringVOLT, 1
         actualVOLTtenth = STR stringVOLTtenth,1
         actualVOLThunds = STR stringVOLThunds,1
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 79
         SEROUT LCD_data_out, baud, temp_1DEC
         SEROUT LCD_data_out, baud, degreeSYM
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 99
         SEROUT LCD_data_out, baud, temp_2DEC
         SEROUT LCD_data_out, baud, degreeSYM
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 112
         SEROUT LCD_data_out, baud, actualVOLT
         SEROUT LCD_data_out, baud, "." 
         SEROUT LCD_data_out, baud, actualVOLTtenth
         SEROUT LCD_data_out, baud, actualVOLThunds
           
     LOOP 
    ENDTASK LCD_1  
    '================================================================
    TASK temperature_2  LMM       'this TASK is running in COG 6   
    again:
      temp_2   VAR  LONG  'the temp_1erature data, itself..
      temp_2 = 125 
     DO  
         temp_2 = temp_2 + 1 
         WRLONG degrees_2, temp_2 
         PAUSE 200
     LOOP UNTIL temp_2 >= 400 
     DO  
         temp_2 = temp_2 - 1 
         WRLONG degrees_2, temp_2 
         PAUSE 200
     LOOP UNTIL temp_2 <= 0 
     GOTO again
    
    ENDTASK temperature_2
    '================================================================
    TASK temperature_1  LMM       'this TASK is running in COG 5   
      temp_1   VAR  LONG  'the temp_1erature data, itself..
      temp_1 = 114 
     DO  
         temp_1 = temp_1 + 1 
         WRLONG degrees_1, temp_1 
         PAUSE 200
     LOOP UNTIL temp_1 >= 400 
    ENDTASK temperature_1
    '================================================================
    TASK volt_measure LMM    ' this is running in COG 4
    ADC_Clk                PIN  3 LOW ' MCP3204.11
    ADC_Dout               PIN  4 LOW ' MCP3204.10
    ADC_Din                PIN  5 LOW ' MCP3204.9
    ADC_CS                 PIN  6 HIGH    ' MCP3204.8
    MCPValue               VAR    LONG
    voltDEC                VAR    LONG
    stringVOLT             VAR    LONG
    stringVOLTtenth        VAR    LONG
    stringVOLThunds        VAR    LONG
     DO
       LOW ADC_CS ' Enable MCP3204
       PAUSEUS 100
       SHIFTOUT ADC_Din, ADC_Clk, MSBFIRST, %11000\5 ' Select CH0, Single-Ended
       SHIFTIN ADC_Dout, ADC_Clk, MSBPOST, MCPValue\13 ' Read ADC
       HIGH ADC_CS ' Disable ADC
       LOW ADC_Clk
       stringVOLT = MCPValue/819      
       stringVOLTtenth = MCPValue//819 
       stringVOLTtenth = stringVOLTtenth * 10
       stringVOLTtenth = stringVOLTtenth/819
       stringVOLThunds = stringVOLTtenth //819
       stringVOLThunds = stringVOLThunds * 10
       stringVOLThunds = stringVOLThunds/819
       WRLONG volt_location, stringVOLT
       PAUSE 100
       WRLONG tenth_location, stringVOLTtenth
       PAUSE 100
       WRLONG hunds_location, stringVOLThunds
       PAUSE 100
     LOOP
    ENDTASK volt_measure
    

  • BeanBean Posts: 8,129
    You should combine all those sequences into a single data line.

    InitStr DATA clrLCD, beep, backLTon, posCMD, 64, "TEMPERATURE IS", posCMD, 84, "TEMPERATURE IS", posCMD, 104, "VOLTAGE=", posCMD, 119, "volts", 0


    SEROUT LCD_data_out, baud, InitStr

    Something like that...

    Bean
  • dennodenno Posts: 223
    edited 2018-08-29 20:57
    Wow..Bean...that is great..that is why I ask the expert..thanks again...however, perhaps I am not codeding it properly...as the program is getting stuck in the LOOP, with or without the "=0"...

    And, using propbasic, what are the total number of LONG(s) available to use in programming. Right now, I am at 6720 LONGS in this little test program in my previous post/thread..
    LCD_data DATA clrLCD, beep, backLTon, posCMD, 64, "TEMPERATURE IS", posCMD, 84, "TEMPERATURE IS", posCMD, 104,"VOLTAGE=", posCMD, 119, "volts", 0
      DO
        RDLONG LCD_data_location, LCD_data
        PAUSE 100
        SEROUT LCD_data_out, baud, LCD_data
      LOOP UNTIL LCD_data = 0  
    
  • David BetzDavid Betz Posts: 14,516
    edited 2018-08-30 02:27
    I don't know PropBasic but if it's anything like PASM you might have the arguments to RDLONG backwards. Try this:
        RDLONG LCD_data, LCD_data_location
    

    Edit: Oops! I see I'm wrong. The arguments to the PropBasic RDLONG are backwards from the PASM instruction. Sorry!
  • BeanBean Posts: 8,129
    You only need a single SEROUT to output the whole line.

    SEROUT LCD_data_out, baud, LCD_data

    Bean
  • dennodenno Posts: 223
    edited 2018-08-30 10:47
    Bean...as you see the code above, the SEROUT LCD_data_out, LCD_data, only outputs to the LCD display, the first instruction, which is clrLCD, and that is it. No "beep". If I delete the clrLCD instruction, and leave the "beep" instruction, I will get a beep..but not any more. So, I know that the SEROUT command, is working, but only on one instruction...not the whole lot of instructions...thanks again, for your help, and I will keep working with this...kind of like reading a good novel....LOL...dennO
  • BeanBean Posts: 8,129
    edited 2018-08-30 12:41
    Weird... I just ran this program and it worked fine.
    DEVICE P8X32A,XTAL1,PLL16X
    FREQ 80_000_000
    
    LetterA  CON 65
    LetterB  CON 66
    
    LCD_Pin  PIN 30 HIGH
    
    LCD_Data DATA LetterA,LetterB,67," Testing...", 13, 0
    
    PROGRAM Start
    
    Start:
      PAUSE 5000
      SEROUT LCD_Pin, T9600, LCD_Data
      GOTO Start
    END
    
    

    The LCD may need a delay after some commands like clrLCD and Beep. I don't know...

    If you want to send a character at a time you'll have to do something like:
    LCD_Data DATA "This is a test", 13, 0
    
    StrPos VAR LONG
    Char  VAR LONG
    
    StrPos = 0
    DO
      RDBYTE LCD_Data(StrPos), Char
      INC StrPos
      IF Char = 0 THEN EXIT
      SEROUT LCD_Pin, Baud, Char
      IF Char = clrLCD THEN
        PAUSE 10
      ELSEIF Char = beep THEN
        PAUSE 100
      ENDIF
    LOOP
    

    Bean
  • Bean, I figured out what I was doing wrong....notice that I was trying to use "LDATA" as a LONG, instead of just "DATA"...everything works now, so I can move on...thanks..again...
      LCD_data    LDATA  clrLCD,beep,backLTon,posCMD,64,"TEMPERATURE IS",posCMD,84,"TEMPERATURE IS",posCMD,104,"VOLTAGE=",posCMD,119,"volts",0
    
  • dennodenno Posts: 223
    edited 2018-09-04 11:42
    Bean...In the continuing saga of learning PROPBASIC, in the previous post above, removing the "L" from the "LDATA", that line will display properly on the LCD.

    However when I try to load the following line as data, the "STRINGS" will not display...as example..the "temp_1DEC", "temp_2DEC", "actualVOLT", actualVOLTtenth, and actualVOLThunds....and so on...
      LCD_data_2        DATA  posCMD,79,temp_1DEC,degreeSYM,posCMD,99,temp_2DEC,degreeSYM,posCMD,114,actualVOLT,".",actualVOLTtenth,actualVOLThunds,0
    
    The "degreeSYM" and the "." do place in the proper place on the display...I have tried many different things, but no joy as of yet...

    So, any thoughts on how to pass a DATA string which is just numbers...the following is the code that runs in a DO?LOOP. The variables in the loop get refreshed each iteneration through the loop. But they will not display on the LCD. The loop runs as coded, and the variables will display properly, however, I am wondering if there is a way, using less SEROUT's. I hope I am making sense. Readers please keep in mind that this is just a snippit of the program. Basicly, I am just teaching myself PROPBASIC, and trying to run all eight COGS in one program...
     DO  
    
         RDLONG degrees_1, temp_1  'reading the temperature data that is in the HUB
         PAUSE 100
         temp_1DEC = STR temp_1,3
    '     tempVAL = VAL temp_1DEC
         RDLONG degrees_2, temp_2  'reading the temperature data that is in the HUB
         PAUSE 100
         temp_2DEC = STR temp_2,3
         RDLONG volt_location, VOLT
         PAUSE 100
         RDLONG tenth_location, VOLTtenth
         PAUSE 100
         RDLONG hunds_location, VOLThunds
         PAUSE 100
         actualVOLT = STR VOLT, 1
         actualVOLTtenth = STR VOLTtenth,1
         actualVOLThunds = STR VOLThunds,1
         RDLONG volt_location_3v, VOLT_3v
         PAUSE 100
         RDLONG tenth_location_3v, VOLTtenth_3v
         PAUSE 100
         RDLONG hunds_location_3v, VOLThunds_3v
         PAUSE 100
         actualVOLT_3v = STR VOLT_3v,1
         actualVOLTtenth_3v = STR VOLTtenth_3v,1
         actualVOLThunds_3v = STR VOLThunds_3v,1'
    '     LCD_varables DATA  posCMD,79, tempVAL
    '     SEROUT LCD_data_out, baud, LCD_varables
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 79
         SEROUT LCD_data_out, baud, temp_1DEC
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 99
         SEROUT LCD_data_out, baud, temp_2DEC
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 114
         SEROUT LCD_data_out, baud, actualVOLT
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 116
         SEROUT LCD_data_out, baud, actualVOLTtenth
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 117
         SEROUT LCD_data_out, baud, actualVOLThunds
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 134
         SEROUT LCD_data_out, baud, actualVOLT_3v
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 136
         SEROUT LCD_data_out, baud, actualVOLTtenth_3v
         SEROUT LCD_data_out, baud, posCMD
         SEROUT LCD_data_out, baud, 137
         SEROUT LCD_data_out, baud, actualVOLThunds_3v
     LOOP 
    
    
    Thanks...and this is fun....DennO
Sign In or Register to comment.