worthy of a new obj? is it worthwhile?
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?
The object:
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
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
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"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 := 17It 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. 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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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