Shop OBEX P1 Docs P2 Docs Learn Events
Use PST from more than one module? — Parallax Forums

Use PST from more than one module?

Hello all,

Fairly new to SPIN here, trying to improve an old project. I'm using Parallax Serial Terminal for program-flow debug, but I really need to be able to get debug out of a couple of modules used by the main program.

Clearly, I can't start multiple PST objects pointing to the same physical pins, and I can't call the parent object's methods that use the PST from within a sub-module. Any suggestions how best to proceed? Is there some way to extract a pointer to the started terminal object's TX buffer that can then be passed to a sub-module and used, or .... ?

Thanks for any help you may have to offer.

Comments

  • realjoshfreeman,
    One way of debugging several cog modules is to use a background cog as a debugger.
    JonnyMac has posted some examples of this strategy;
    http://forums.parallax.com/discussion/comment/1483675/#Comment_1483675
  • I have a version of PST which can be used in multiple objects. I moved the variables to the DAT section so all the objects share the same variables. It works best with locks.
    It will take me a bit to find it. I'll get back to you later this evening.

    I generally only use this version of PST while a program is in development. As macrobeak suggests, it's generally a better strategy to use a single cog for serial output.
  • The top-level object in my project instantiates a Parallax Serial Terminal object, which starts a cog for its uses. That top-level object runs most of the project's original code in what the discussion at macrobeak's link called embedded cogs. The embedded cogs can share the serial terminal object just fine (using locks).

    But the top-level object also instantiates another original module in a separate .spin file, and the code in that module has timing problems needing some debug. I need that code to be able to access the same serial terminal in real time (A solution like having the sub-module store a string that the top-level main loop checks for and prints to the terminal won't help).

    It's probably also worth mentioning that the project as it stands uses all eight cogs. So a debugging solution that requires an extra free cog won't help either.

    I'm definitely interested in what Duane is describing. At the moment, I'm wondering if simply converting the sub-module code to another embedded cog might be a quicker way forward.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2020-04-03 14:37
    Here's the most recent version of my "PstDat" I could find.
    You only start this object once but you can include it in multiple objects and call it from multiple objects.
    I noticed in this version I had commented out the normal Start method since I was likely using this with pins other than 30 and 31.

    You'll want to uncomment out methods you need and you might want to comment out some of the added methods like PressToContinue and ReadableBin.

    I added ReadableBin since it makes it easier for me to read binary numbers. The method displays the bits in groups of four.

    SafeStr will output hex values for non-printable characters.

    I noticed this version doesn't include any locks. If you have multiple cogs calling this method at once, the output can become gabbled. If you want to see a version with locks let me know.
  • Duane Degn wrote: »
    Here's the most recent version of my "PstDat" I could find.
    You only start this object once but you can include it in multiple objects and call it from multiple objects.
    I noticed in this version I had commented out the normal Start method since I was likely using this with pins other than 30 and 31.

    You'll want to uncomment out methods you need and you might want to comment out some of the added methods like PressToContinue and ReadableBin.

    I added ReadableBin since it makes it easier for me to read binary numbers. The method displays the bits in groups of four.

    SafeStr will output hex values for non-printable characters.

    I noticed this version doesn't include any locks. If you have multiple cogs calling this method at once, the output can become gabbled. If you want to see a version with locks let me know.

    I would...
  • I would...

    I'll make a small demo program to illustrate how the various methods are used.

    I'd like to include a child object and an ADC object would make a good example.

    Do you have a Propeller Activity Board or a Propeller Board of Education? Or some other Propeller board I can use for the example program?
  • Here's a demo which blinks three LEDs using three different cogs and three objects.

    The demo shows how this version of the Parallax Serial Terminal object can be used from multiple objects and from multiple cogs.

    I merged a couple different serial objects I use to make this version. One version used "Tx" to transmit individual characters while the other used "Char". I'm afraid the method names are not very consistent. You are of course encouraged to change the names of methods to suit your needs.

    I used a QuickStart board when testing this program. It blinks the LEDs connected to pins 16, 17 and 18. You might need to change pin numbers if you use it with a different board.
  • Duane Degn wrote: »
    Here's a demo which blinks three LEDs using three different cogs and three objects.

    The demo shows how this version of the Parallax Serial Terminal object can be used from multiple objects and from multiple cogs.

    I merged a couple different serial objects I use to make this version. One version used "Tx" to transmit individual characters while the other used "Char". I'm afraid the method names are not very consistent. You are of course encouraged to change the names of methods to suit your needs.

    I used a QuickStart board when testing this program. It blinks the LEDs connected to pins 16, 17 and 18. You might need to change pin numbers if you use it with a different board.

    Thank you, Duane. I got busy and didn't check back on the forum until today. I have numerous propeller boards, that I will try your example/demo on...
Sign In or Register to comment.