Shop OBEX P1 Docs P2 Docs Learn Events
Proper use of OBJ instances — Parallax Forums

Proper use of OBJ instances

RsadeikaRsadeika Posts: 3,837
edited 2007-03-24 16:27 in Propeller 1
I need some advice as to whether I am using the OBJ instances properly. My snippet below, I have declared two instances of "Extended_FDSerial", I am assuming that I am now using 3 cogs- 0, 1, 2, two are for the two instances of "Extended_FDSerial". Now the question I have is, can I make the code below work with the use of two cogs total. In other words, can ser[noparse][[/noparse]2]: ... be made to use only one cog. As my program starts to grow, I think I am going to start to run out of cogs. Any other tweaking that I could do, would be appreciated.

Thanks

Ray



''deBugger.spin
''

CON
· _clkmode = xtal1 + pll16x
· _xinfreq = 5_000_000
OBJ
· ser[noparse][[/noparse]2]: "Extended_FDSerial"
VAR
· byte IRdat

PUB main
· TestPrg
· StartRobot
·
PUB TestPrg
· ser[noparse][[/noparse]0].start(31, 30, 0, 57800)
· waitcnt(400_000_000 + cnt)
· repeat 5
··· ser[noparse][[/noparse]0].str(string("This is a test!",10,13))
··· waitcnt(160_000_000 + cnt)

PUB StartRobot
·· ser[noparse][[/noparse]1].start(17, 16, 0, 57600)
·· ser[noparse][[/noparse]1].str(string(128))
·· ser[noparse][[/noparse]1].str(string(132))
·· ser[noparse][[/noparse]0].str(string("The robot is prog mode",10,13))
·· repeat
···· ser[noparse][[/noparse]1].str(string(142,17))
···· IRdat := ser[noparse][[/noparse]1].rx
···· if IRdat == 130
······ ser[noparse][[/noparse]0].str(string("The forward button",10,13))
······ ser[noparse][[/noparse]0].dec(IRdat)

Comments

  • Jeff MartinJeff Martin Posts: 755
    edited 2007-03-24 16:27
    Hi,

    You're right, 3 cogs, the first is your main code, 2nd and 3rd are running the serial code (haven't looked at it, but I imagine it is assembly).

    Having the second instance use the cog of the first instance is not really possible the way it is written.· That's not to say that such a thing isn't possible... depending on the baud rates and your clock speed, it would be possible to write an object that launches a single cog which handles serial on two ports (2 pair of Tx/Rx), but only if the code is written with that specifically in mind.· I'm afraid that object wasn't written for that use.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Jeff Martin

    · Sr. Software Engineer
    · Parallax, Inc.
Sign In or Register to comment.