Shop OBEX P1 Docs P2 Docs Learn Events
worthy of a new obj? is it worthwhile? — Parallax Forums

worthy of a new obj? is it worthwhile?

Bobb FwedBobb Fwed Posts: 1,119
edited 2008-09-27 00:53 in Propeller 1
ok. I thought I'd throw together an object that would run debug commands on a separate cog (thus not slowing down --much-- the cog that is giving me the info). But I've caught a snag, and I'm sure it is something simple.

Here is what happens: the LCD clears, then 0 is displayed, one second later 1 is displayed, then it hangs (most likely until the internal clock loops back) for a minute or so then 2 is displayed, and it continues, but at the pace of 1 every minute, rather than 1 every second.

Can someone else run this code, or tell me what I am doing wrong?

CON

  _CLKMODE      = XTAL1 + PLL16X                     ' 80MHz clock
  _XINFREQ      = 5_000_000                          ' 5MHz Crystal

  DEBUG_DISP       = 1                               ' display debug terminal
  DEBUG_P          = 4
  DEBUG_BAUD       = 19200                           ' only 19200 with 80MHz clock
  DEBUG_LINES      = 4
  
OBJ

  DEBUG  : "DEBUG"

PUB debug_test | i
  DEBUG.init(DEBUG_p, DEBUG_BAUD, DEBUG_LINES)

  REPEAT i from 0 to 500
    DEBUG.dec(i)
    waitcnt(clkfreq + cnt)




The object:
OBJ

  lcd : "serial_lcd"                                    ' driver for Parallax Serial LCD
  num : "simple_numbers" 

VAR

  long val1,val2
  byte ntype
  long debugstack[noparse][[/noparse]500]                                   ' cog stack
  byte cogon, cog
  
PUB init(pin, baud, lines)                               ' initiate cogs

  stop
  cogon := (cog := cognew(debug(pin, baud, lines, @val1, @val2, @ntype), @debugstack)) > 0
  
PUB stop                                                 ' stop cogs if already in use
  if cogon~
    cogstop(cog)

PUB debug (pin, baud, lines, val1Addr, val2Addr, typeAddr)
  lcd_init(pin, baud, lines)                             ' start up the LCD obj
  lcd.cls

  REPEAT
    REPEAT UNTIL byte[noparse][[/noparse]typeAddr] <> 0                     ' repeat until ntype is changed
    CASE byte[noparse][[/noparse]typeAddr]
      1 : lcd.putc(long[noparse][[/noparse]val1Addr])
      2 : lcd.str(val1Addr)
      3 : lcd.str(num.dec(long[noparse][[/noparse]val1Addr]))
    byte[noparse][[/noparse]typeAddr]~                                      ' reset back to 0 to "wait"
    long[noparse][[/noparse]val1]~
    long[noparse][[/noparse]val2]~

PUB lcd_init(pin, baud, lines) : okay

  okay := lcd.init(pin, baud, lines) 
  
PUB putc(txbyte)

  val1  := txbyte
  ntype := 1
  
PUB str(strAddr)

  val1  := strAddr
  ntype := 2  

PUB dec(value) 
  
  val1  := value
  ntype := 3



While this may not be the best way to do this, it will work for my uses

Post Edited (Bobb Fwed) : 9/25/2008 8:46:33 PM GMT

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2008-09-25 10:33
    Bobb,

    Change the following:
        long[noparse][[/noparse]val1]~   ->>>  long[noparse][[/noparse]val1Addr]~  or val1~
        long[noparse][[/noparse]val2]~   ->>>  long[noparse][[/noparse]val2Addr]~  or val2~
    
    

    You should·also reverse the order of the repeat loop. You are using the byte[noparse][[/noparse]typeaddr] as a flag between processes, so their order is normally important. This is not your problem though because you are waiting for 1 second anyway. But get into good habits or you will spend hours trying to find this one.

        long[noparse][[/noparse]val1]~
        long[noparse][[/noparse]val2]~
    
        byte[noparse][[/noparse]typeAddr]~                                      ' reset back to 0 to "wait"
    


    cool.gif·
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2008-09-25 15:14
    I knew it was something simple, thanks!
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2008-09-25 20:49
    OBJ
    
      lcd : "serial_lcd"                                     ' driver for Parallax Serial LCD
      num : "simple_numbers" 
    
    VAR
    
      long val1
      long val2
      byte ntype
      long debugstack[noparse][[/noparse]150]                                   ' stack
      byte cogon, cog
      
    PUB init(pin, baud, lines)                               ' initiate cogs
    
      stop
      cogon := (cog := cognew(debug(pin, baud, lines, @val1, @val2, @ntype), @debugstack)) > 0
      
    PUB stop                                                 ' stop cogs if already in use
      if cogon~
        cogstop(cog)
    
    PUB debug (pin, baud, lines, val1Addr, val2Addr, typeAddr) | type
      lcd_init(pin, baud, lines)                             ' start up the LCD obj
      lcd.cls
    
      REPEAT
        REPEAT UNTIL (type := byte[noparse][[/noparse]typeAddr]) <> 0           ' repeat until ntype is changed
        CASE type
          1 : lcd.putc(long[noparse][[/noparse]val1Addr])
          2 : lcd.str(long[noparse][[/noparse]val1Addr])
          3 : lcd.str(num.dec(long[noparse][[/noparse]val1Addr]))
          4 : lcd.str(num.decf(long[noparse][[/noparse]val1Addr], long[noparse][[/noparse]val2Addr]))
          5 : lcd.str(num.decx(long[noparse][[/noparse]val1Addr], long[noparse][[/noparse]val2Addr]))
          6 : lcd.str(num.hex(long[noparse][[/noparse]val1Addr], long[noparse][[/noparse]val2Addr]))
          7 : lcd.str(num.ihex(long[noparse][[/noparse]val1Addr], long[noparse][[/noparse]val2Addr]))
          8 : lcd.str(num.bin(long[noparse][[/noparse]val1Addr], long[noparse][[/noparse]val2Addr]))
          9 : lcd.str(num.ibin(long[noparse][[/noparse]val1Addr], long[noparse][[/noparse]val2Addr]))
          10: lcd.cls                     
          11: lcd.home
          12: lcd.gotoxy(long[noparse][[/noparse]val1Addr], long[noparse][[/noparse]val2Addr])
          13: lcd.clrln(long[noparse][[/noparse]val1Addr])
          14: lcd.cursor(long[noparse][[/noparse]val1Addr])
          15: lcd.displayOn
          16: lcd.displayOff
          17: lcd.backLight(long[noparse][[/noparse]val1Addr])
        byte[noparse][[/noparse]typeAddr]~                                      ' reset back to 0 to "wait"    
    
    PUB lcd_init(pin, baud, lines) : okay
    
      okay := lcd.init(pin, baud, lines)    
    
    PUB putc(txbyte)
    
      REPEAT UNTIL ntype == 0           ' repeat until ntype is reset
      val1  := txbyte
      ntype := 1
    
    PUB cr
    
      REPEAT UNTIL ntype == 0           ' repeat until ntype is reset
      val1  := $0D
      ntype := 1  
      
    PUB str(strAddr)
    
      REPEAT UNTIL ntype == 0           ' repeat until ntype is reset
      val1  := strAddr
      ntype := 2  
    
    PUB dec(value) 
    
      REPEAT UNTIL ntype == 0           ' repeat until ntype is reset
      val1  := value
      ntype := 3    
    
    PUB decf(value, width) 
    
      REPEAT UNTIL ntype == 0           ' repeat until ntype is reset
      val1  := value
      val2  := width
      ntype := 4   
    
    PUB decx(value, digits) 
    
      REPEAT UNTIL ntype == 0           ' repeat until ntype is reset
      val1  := value
      val2  := digits
      ntype := 5   
    
    PUB hex(value, digits)
    
      REPEAT UNTIL ntype == 0           ' repeat until ntype is reset
      val1  := value
      val2  := digits
      ntype := 6  
    
    PUB ihex(value, digits)
    
      REPEAT UNTIL ntype == 0           ' repeat until ntype is reset
      val1  := value
      val2  := digits
      ntype := 7     
    
    PUB bin(value, digits)
    
      REPEAT UNTIL ntype == 0           ' repeat until ntype is reset
      val1  := value
      val2  := digits
      ntype := 8  
    
    PUB ibin(value, digits)
    
      REPEAT UNTIL ntype == 0           ' repeat until ntype is reset
      val1  := value
      val2  := digits
      ntype := 9       
    
    PUB cls
    
      REPEAT UNTIL ntype == 0           ' repeat until ntype is reset
      ntype := 10 
    
    PUB home
    
      REPEAT UNTIL ntype == 0           ' repeat until ntype is reset
      ntype := 11  
    
    PUB gotoxy(col, line)
    
      REPEAT UNTIL ntype == 0           ' repeat until ntype is reset
      val1  := col
      val2  := line
      ntype := 12   
      
    PUB clrln(line)
    
      REPEAT UNTIL ntype == 0           ' repeat until ntype is reset
      val1  := line  
      ntype := 13  
    
    PUB cursor(type)
    
      REPEAT UNTIL ntype == 0           ' repeat until ntype is reset
      val1  := type
      ntype := 14
    
    PUB display(status)
    
      REPEAT UNTIL ntype == 0           ' repeat until ntype is reset
      if status
        ntype := 15    
      else
        ntype := 16    
          
    PUB backLight(status)
    
      REPEAT UNTIL ntype == 0           ' repeat until ntype is reset
      val1  := status  
      ntype := 17   
    
    


    It works as a drop-in replacement for the Debug_Lcd object, but it uses a cog to reduce load (and time) on the "source" cog. I will find it very useful as I rarely use all my cogs in my work, but I wonder if others may find it useful.
    It will remove wait times for debug commands that are more than a couple ms apart (at 80MHz) and will always reduce the wait time for single debug commands.

    Please let me know if this is object worthy, this would be my first "official" object, so what would the next steps be? Also, are there any changes to the code that should be done?

    Post Edited (Bobb Fwed) : 9/25/2008 8:57:22 PM GMT
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2008-09-25 23:11
    Good job on your first object.· If you would like, and I recommend it, is that you "archive" your object with the Propeller Tool and place the object in the Object Exchange.· Be sure to write a details description on what your object is and how to use it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.

    www.brilldea.com·- Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto fo SunSPOT, BitScope
    www.sxmicro.com - a blog·exploring the SX micro
    www.tdswieter.com
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2008-09-26 23:29
    how does the copyright stuff work? Do I put that terms of use stuff in or does someone else do that? Is it automatically copyrighted once on the site, or is there some type of process?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-26 23:50
    On the main Propeller Object Exchange page there's a link to "MIT License". Click on it and read the detailed discussion.
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2008-09-27 00:53
    All objects posted in the Exchange must have an MIT license. Objects just posted on the forum can have any license if I remember correctly. You need to add the details of the license to your code itself.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.

    www.brilldea.com·- Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto fo SunSPOT, BitScope
    www.sxmicro.com - a blog·exploring the SX micro
    www.tdswieter.com
Sign In or Register to comment.