PASM 101 - Manipulation I/O Pins
MJHanagan
Posts: 189
About a year ago I bumped up against the speed limitations in SPIN when I needed to make some high speed ADC measurements using the MCP3202. That limitation forced me into learning how to program in PASM. My only exposure to assembly lanuguage was back in the late 1970's when I took an "Introduction to Computers" class in my senior year of high school. From that experience I gained a quick appreciation for higher level languages like FORTRAN and thought I would never ventured back to assembly. Ugh, I'm back!
Learning PASM has been a lot more difficult than leaning SPIN, mostly because it is a lower level language. At the assembly programming level the commands available do only limited things. The Propeller Manual lists each PASM command in a style reminiscent of those thick orange binders holding the VAX Operating Language. If you already have a working understanding of the language they were a great resource. If you were a beginner they were virtually useless.
There are not many resources available to the early learners of PASM. I did read potatohead's and desilva's short treatises on PASM but these did not prepare me sufficiently for writing my own code for the MCP3202 chip. I stared at several PASM programs specific to the MCP320x IC but these were difficult to understand mostly because they were quite compact/efficient and the commenting was generally limited and geared to the PASM savvy programmer.
The main challenge to using the MCP320x IC's is negotiating the SPI communication protocol using three I/O pins on the Propeller. Along the way I struggled to developed the necessary understanding of how to manipulate these I/O pins using PASM commands. I collected notes from various OBEX code examples and forum postings and assembled a short text summarizing the key I/O concepts and PASM commands.
I attached my notes below hoping that some of the PASM gurus out there would review them for accuracy and completeness.
I look forward to your feedback and comments.
Attached here is the latest version of the notes:
PASM 101 - Manipulating Input and Output Pins V1.1.pdf
Learning PASM has been a lot more difficult than leaning SPIN, mostly because it is a lower level language. At the assembly programming level the commands available do only limited things. The Propeller Manual lists each PASM command in a style reminiscent of those thick orange binders holding the VAX Operating Language. If you already have a working understanding of the language they were a great resource. If you were a beginner they were virtually useless.
There are not many resources available to the early learners of PASM. I did read potatohead's and desilva's short treatises on PASM but these did not prepare me sufficiently for writing my own code for the MCP3202 chip. I stared at several PASM programs specific to the MCP320x IC but these were difficult to understand mostly because they were quite compact/efficient and the commenting was generally limited and geared to the PASM savvy programmer.
The main challenge to using the MCP320x IC's is negotiating the SPI communication protocol using three I/O pins on the Propeller. Along the way I struggled to developed the necessary understanding of how to manipulate these I/O pins using PASM commands. I collected notes from various OBEX code examples and forum postings and assembled a short text summarizing the key I/O concepts and PASM commands.
I attached my notes below hoping that some of the PASM gurus out there would review them for accuracy and completeness.
I look forward to your feedback and comments.
Attached here is the latest version of the notes:
PASM 101 - Manipulating Input and Output Pins V1.1.pdf
Comments
You're just three years too late. I could have really used this when I was starting with PASM.
I'm far from a PASM guru but I'll continue to read through the document. My initial perusal didn't find anything that looked wrong.
This paper would have saved be from having to translate the Propeller Manual's PASM examples into binary.
I also found PASM a lot harder to understand than Spin.
One of the sources I did find for PASM instruction was JonnyMac's Spin Zone articles. I finally had things start to click when working through one of Jon's examples of controlling a bi-color LED.
Thanks for posting this. I'll add a link to this thread in my "How to Program the Propeller" section of my index.
Edit: I don't see your name anywhere in the document. I think it would be good to let people know who wrote the paper in case it gets posted elsewhere on the internet.
Thanks.
Thanks
Bill M.
Thanks!
Erlend
Not too late for some. There are always new users and this is likely to apply to PASM on the Propeller TWO as well as The ONE.
Sorry about the timing, but I'm late for just about everything in my life!
I forgot to mention JonnyMac's name. I looked through several of his OBEX programs written in PASM and found them to be helpful and generally enlightening.
I would wait a bit before posting a link to this document since it is in the unvetted state. If/when the PASM gurus give it a good look over and I get the inevitable errors fixed and the formatting adjusted then you are welcome to post the revision or link to it.
Let me know what errors you find or if you have suggestions on formatting/style and what sections need better clarification.
Well, I am not a big fan of writing and my grasp of PASM is very limited so authoring a book is not likely. But thank you for the flattering suggestion!
I did start another section regarding the various ways of reading and writing data to main RAM. It seems like there are a few ways to get this done. I am still in the learning mode on this topic so it will take some time to pull it together.
I would like to see Parallax write a PASM 101 book. I bet if someone at Parallax provided an outline and a basic style guide they could get a bunch of the forum contributors to each take a section and get the bulk of the writing done. Parallax would only need to assemble these section writings and apply a dose of editing for style and continuity and it will be done in a fairly short period of time. A nice way to share the burden of writing such a tome. Perhaps Parallax would consider giving each contributor a token store credit for their contribution.
Who would we get to do the accompanying UTube video lecture series?
I'm a bit worried by the use of ON/OFF though - to me this is ambiguous - if an LED/resistor is connected to a pin
and to ground, that language is perfectly reasonable.
But if an LED/resistor is connected to 3.3V rail instead of ground, ON means LED off, OFF means LED on!
Furthermore OFF might mean the pin is in the high-Z state, ON means its actively driving as an output.
This is why the words HIGH and LOW are so commonly used for I/O pins since they are completely unambigous,
whether or not negative logic or open-drain or whatever is being used.
Typo: The DIRA and OUTA registers are ANDed together, then the eight results are ORed.
That's very kind of you to say.
And well-done getting more information out. I try to do things in my objects and my column using practical projects, as I've found that tends to resonate with readers and get concepts to stick. That said, writing (well) is darned difficult, and it's impossible to make everybody happy with that writing. Some months ago the editor at Nuts & Volts phoned me because a reader wanted to speak directly with me (after some drunk dials, my telephone number is no longer included in my contact information). I took his number and called him. He was grateful for he call, and then proceeded to lay into me about writing above his head. The actor in me wanted to to tell him where to stuff his cell phone, but I hung in and helped him with a simple trick -- a technique he claimed to have spent two years searching for.
Should you continue and do project-oriented material, you may want to show and explain different ways to accomplish the same task. For example, in my latest IR object I manipulate the DIRA bit for the pin instead of the OUTA bit. This allows the code to work with either circuit configuration (pin to anode, or pin to cathode). Manipulating the DIRA bit is useful in half-duplex communications (serial, 1-wire, I2C, etc) where the idle state of the line is handled with a pull-up. This was the trick that I shared with that caller and once he understood, he became far more friendly.
It's confusing for beginners to use those terms.
1: Each cog have its own DIRA & OUTA registers.
2: A write to the cogs OUTA only affect the pins that have that specific cogs DIRA also set.
3: Sharing the same pin between cogs/Spin:
If any cog (including Spin) have that pin set as DIRA=1 and also set as high with OUTA=1 it will be a high.
even if 7 cogs have it set as a low and one have it set as high, it will stay high.
4: Reading a cogs OUTA register will not reveal the true electrical state of the pin, but INA will.
I agree that project based articles work well when trying to teach the basic programming concepts. I was originally thinking of writing this based on my experience with the MCP3202 but that would have been a much greater effort. I wanted to get this little snippet written and out there in hopes it might help a few struggling beginners like myself. If I ever get around to finishing the RAM read/write section then I might attempt writing something that brings together these two concepts. A likely project candidate is the ubiquitous MCP320x series of ADC's. Fast SPI communication, bit shifting, pin direction altering, RAM read/write, it seem to encompass most of the things PASM does well and fast. Maybe... someday... :nerd:
I like your explanation, much clearer and succinct. OK if I incorporate it into the primer?
I'm sure you should do that. Don't forget to reference the architecture diagrams in the Propeller manual that spell this out in detail diagrammatically.
These details of how logic works, AND, OR, NOT etc, and the symbols used to describe it should be part of any assembler language primer. it clears up a lot of confusion.
Thank you for catching the ANDed (not ORed) error - I will correct it in the text.
You make a good point with the potential confusion with output high/on low/off. I will need to address this too. Thank you.
Sure, one day I would like to make a web flash version so people can click on different bits and see the result.
Is this controlled by rule #3?
The Propeller manual states:
So basically that means that in order to reuse a pin as an input, the last cog to use the pin must shut down (rule #1?), or declare it
an input before the original cog can reuse it as an input again (rule #1?)
Thanks
If this pin was only meant to be a input-pin this would create a override of the input state, or maybe even a electrical short if the load to the pin does not have series resistance of at least 500+ Ohm
You can always read INA from any cog, even if that cog is DIRA set as output.
Setting DIRA from one cog, does not make it an output from another cog as OUTA is first ANDed with that cogs DIRA before this cogs output stage.
N00b question - In what case would you reuse a pin? Once its soldered into a circuit, its usually hooked up to a specific part that is an input or an output. Is this a case of "can, but doesn't usually happen"?
I was thinking about ADC chips that have have Data-In and Data-Out wired together, and
used by two cogs.
Bill M.
if so shouldn't the results of ANDN be opposites to the AND results ie 1=0 and 0=1?
Sorry for my ignorance but it is probably clear to most here,myself it's been a long time since I messed with logic
Thank you both for your help.
0 & 1 = 0
1 & 0 = 0
0 & 0 = 0
The N in ANDN change (inverts) the value in left column,
you can use same mask for a pin both with OR and ANDN this way.
AND and ANDN can not set a bit, it can only keep an existing bit a 1 or clear it.