Shop OBEX P1 Docs P2 Docs Learn Events
Using pins for debug — Parallax Forums

Using pins for debug

Just wanted to share something I only today realized (everyone else probably did a long time ago, but maybe this will help someone else).

I've got a decently complex program using 8 cogs for various things, and was having some issues with my GUI not always processing every keyboard input. I am using the serial terminal for some logging, but it would be too slow for everything I needed to see in my routine, plus it would scroll so quickly as to be unusable.

I was using my logic analyzer (found out about it from the P2 holiday youtube videos: https://www.amazon.com/HiLetgo-Analyzer-Ferrite-Channel-Arduino/dp/B077LSG5P2/ best $13 I've spent!), and realized I have a bunch of spare pins on my P2. I modified the ifs and repeats to set pins high when they were called (and low otherwise), and I was then able to see nearly clock-for-clock alongside the keyboard input what my code was doing. I fixed my bugs and now it works great :) As a bonus I could see how long my screen updates were taking and increase my framerate without affecting performance.

Comments

  • About a year ago I was stuck on a project. I realized that I had available pins on the circuit so I connected a couple to that logic analyzer, along with the TTL side of an RS-485 converter so I could watch the traffic between nodes. Within minutes, the problem was solved. I was using a Spin1 routine that had been around for a long time that was just not fast enough in this application. Thankfully, I had a spare cog so I was able to deploy a PASM version of that routine. Problem solved.

    Tools don't have to be expensive to be useful.

  • I do the same with my four-channel oscilloscope. It really helps with the debugging.

    -Phil

  • I have used software "flags", indicator LEDs, on-screen VGA messages and activity flashing symbols - all the time. I wrote a "Workbench" SPIN-2 program with a nice VGA app, a few months back, to do diagnostics and view pin I/o activity, ahead of actually writing a complex program. An old timers trick for sure.

  • An old timers trick for sure.

    Your avatar checks out. :)

    -Phil

  • You can not only output flags to (digital) pins to debug timing or decision (if/then/else) issues. But you can also output variable values to DAC pins in real time! The limited resolution of a scope is probably not enough to detect small calculation errors but you can easily detect roll-overs or glitches.

  • Oh good idea, I hadn't thought of that! Definitely come in handy in the future, thanks :)

Sign In or Register to comment.