Pasm vs. Spin
James Long
Posts: 1,181
I have a question that I feel is pretty dumb, but I'm going to ask it any way.
Is there any operation of which Spin can do that Pasm can not.
We are not talking about length of code, so if the code wouldn't fit in the eeprom, that is ok.
I'm thinking about starting the exciting journey of Pasm, and wondering if there are any instructions (combinations) which do not convert.
I have been tinkering with the Propeller for a long time, and it is time to start learning Pasm. I think it will help me understand Spin operations a little better (or just totally confuse me. One or the other).
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
Is there any operation of which Spin can do that Pasm can not.
We are not talking about length of code, so if the code wouldn't fit in the eeprom, that is ok.
I'm thinking about starting the exciting journey of Pasm, and wondering if there are any instructions (combinations) which do not convert.
I have been tinkering with the Propeller for a long time, and it is time to start learning Pasm. I think it will help me understand Spin operations a little better (or just totally confuse me. One or the other).
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
Comments
You're right about PASM helping to understand spin better and write more efficient spin code. I've spent the last few days playing with PASM, and pulling my hair out. I've been taking a spin program and converting it to PASM, mainly for speed purposes. Wow, that's much faster. I've been makin an ADC object, and the spin code can pull about 4ksps, and my optimized PASM can pull almost 200ksps(the maximum for the ADC).
In the process, I've learned alot of new tricks that I can use in my spin code, such as shifting bits, binary OR's and AND's in spin. It simplifies code and, suprisingly, speeds up spin alot too.
Post Edited (Philldapill) : 4/17/2009 11:36:22 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propalyzer: Propeller PC Logic Analyzer
http://forums.parallax.com/showthread.php?p=788230
Of course a COG running PASM can start other COGs. What do you think the SPIN interpreter is? It's PASM code. So when SPIN can start new COGs PASM can do it as well. Easy thing is to start other PASM code.
@James
NO. The SPIN interpreter is written in PASM. So, everything that can be done in SPIN can also be done in PASM!
1) There's no multiply or divide operation in PAsm. Spin does it using a subroutine and makes the operations available as a primitive operator. There are a few other less common things that are primitive operations in Spin done by subroutine in Pasm.
2) Pasm has the ANDN instruction which is very handy for doing I/O. Spin has separate AND (&) and NOT (!) operations.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
www.tdswieter.com
My short time from Pasm research created some questions:
I ask the second question, because of one item I'm using now, doesn't appear that Pasm would speed it up much, but my take on Pasm may be wrong.
If using lookdown in spin, the program is basically stepping through values to match another. In Pasm, it would be a simple loop (well simple in Pasm terms) with a loop counter in it. I know that is easier to type than do, but still the background operation is the same.
At this point, I wondering if it would be a "for instance" of an operation that would make little difference. Am I totally missing the point?
I have looked at Pasm, and after a few years of staring at Spin, it is less intimidating than at my first view of it. But I have yet to write any programs in it. I have looked at a few "starter programs" (tutorials) and Desilva's PDF. Mind you I haven't been through it all.
There are a few things (a bunch really) that do not make a huge amount of sense, but those will come with time.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
To the first question, a lot of the code I have seen isn't geared to run at a set speed based on clock of the MCU. I am guilty of this too and I should start doing better in my own code. Some code just runs flat out and it is within limits of the operating device, however this is sloppy programming and I think a lot of objects may break with the Propeller II or may already break of someone runs on the code on a 40MHz Prop versus an 80MHz. clock. For instance, the I2C code runs flat out, but by I2C standards from what I understand there is a 100KHz and 400kHz operation, but the ICs out there, for the most part, don't care as long as it is getting its clock and not watching setup time of the signals. The Prop II will surely thrust this issue into light.
For the second question, sure why wouldn't it speed up the operation? For some though, the 'programming' and 'debugging' operation may be slower than in SPIN.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
www.tdswieter.com
2) If your code is using WAITCNTs or if your code is mostly using the cog counters, changing to PASM wouldn't necessarily speed things up because the timing is set by the system clock, not the program's execution time.
3) Yes, the "_" can be used in the PASM portion of a program
Write some simple programs in PASM and use GEAR to execute them so you can watch what happens when you execute them. Sometimes you can go crazy thinking about something new when just doing some of it makes things much clearer.
Mike,
So you are saying, you calculate pauses to place in your code to keep the speed in the range you want. I've noticed the I2C speed range, and still working to figure out how to use it.
I have been using your code to communicate with an SD card, and it works beautifully. Now if I can figure out the I2C part to communicate with a PCF8575 I'll be in the money. Then my only other task to deal with is making lookdown in Pasm.
I'm going to download GEAR again (I know I have had it in the past, but don't want to do a major search for it. I may have uninstalled it).
I appreciate all the help with learning Pasm. I'm planning to buy AndreL's (think I got that right) book on Pasm, and also go through the tutorials from the forum. There is a lot of information on Pasm here, and lot of great people.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
The routines in BB_i2cSpiLdr are readExpander and writeExpander. There's a "pass through" interface for these in BB_massStorage because BB_massStorage uses BB_i2cSpiLdr. You'll see if you look at the code.
The PCF8575 requires a two byte read and two byte write. You could just make copies of readExpander and writeExpander and add a "2" at the end of the names, then change the byte count from 1 to 2 in the readExpander2 and writeExpander2 routines in BB_i2cSpiLdr. That way, you'll simply transfer 16 bit words instead of 8 bit bytes.
I think I posted a PASM lookup routine for 16 bit values in the PASM beginner's tutorial in one of the "sticky threads". Have a look for that message.
Mike,
Thanks, I'm sure I'll have more questions, but I'll try to make them more specific.
James
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
I have looked at the code, and it looks pretty straight forward. (BoeBotBasic) I do have a question. What is the default speed of the I2C. I'm having a hard time trying to find where it is set. I figure it is set in it's start up or init .
I've found it is difficult to go through others programs, but I'm getting better at it.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
I thought REBOOT was SPIN only, but there's a bit in the CLK register (set in PASM with CLKSET) to reboot the system.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Composite NTSC sprite driver: http://forums.parallax.com/showthread.php?p=800114
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propalyzer: Propeller PC Logic Analyzer
http://forums.parallax.com/showthread.php?p=788230
Mike,
Yea, I see that. Now I'm just trying to figure out how to use the method. I made a second version with the following changes:
to this
I have a small problem....and trying to work through it. Because I'm working with a breakout board I built, I'm using the pins backwards. My SCL is 5 and SDA is 6 so I'm looking to rewrite the asm a little to let me get around the problem.
I think I'm going to reverse the the order of the following (SCL and SDA)
to this
If I understand the commands correctly, I need to send the following to the method to get a output to turn on (PCF8575):
XXX.writeExpander (%0010_0000, %0000_0000_0000_0001)
This should turn on output 0 (or one if you count in standard terms). I'm only using the expanders for out. I do not need to read them at all.
I'm not sure if this will work or not.
I think I have tried all of this, but my results are not promising at the moment.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
Post Edited (James Long) : 4/19/2009 11:21:43 PM GMT
That was my original thought, but I figure it never hurts to ask.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
I'm not sure I'm initializing the system correctly, or missing something calling the command.
I'm really picking up on the Pasm pretty quickly, there are so many actions to this Object, it is pretty hard to follow.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
I finally got the I2C code somewhat working, but have a problem, and do not know where to look.
I went back and put everything back in it's original state. Then I changed the asm to put the SCL after the SDA. That was a no brainer after I studied it for a while (SHL to SHR).
I finally worked out the coding for the SCL address (actually found it in the Boe Bot Basic, and discovered that is what I needed).
I changed the count to 2(two) in the writeExpander method, but here is where the problem develops. If I keep the count as 2 I only get half of the PCF8575 outputs. They are the top 8 , but they come out on the bottom 8 on the I/O chip. They are reversed as well, but I found that problem, and I'm not sure how to fix that part.
If I bump the writeExpander up to 4 I do get other outputs but they are not working correctly. The outputs are not staying on long. If I wasn't paying attention, I probably wouldn't have noticed.
I'm not sure if I am aligned byte wise with the asm call, but have tried changing some length on the caller code. Nothing seems to work.
I really do not know where to look from here. Do you have any ideas?
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
Please don't critique the mess, I'm still hacking at it (literally).
Here are the notes and locations of what I changed, that way you won't have to look hard to find any changes I did.
Under PCF8575 objects:
BB_Definitions lines 24 and 25
BB_i2cSpiLdr line 71
BB_i2cSpiInit lines 140 through 143
Sorry, I just edited line 143 from shl to shr. I forgot I put them back as original.
The main call that starts this lineage is in the top object file line 131 and 141
"lightout.main($XX,d1,@cuelist)"
If you can weed through that mess and find the problem, that would be great. I can't find it.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
Post Edited (James Long) : 4/20/2009 4:22:58 PM GMT
In writeExpander, the value should be 2, not 3. In readExpander, the value should be 2, not 1.
If I spot anything else, I'll post other messages
you use the following instead
This way you still specify the pin pair, but SDA is the even numbered pin and SCL is the next higher odd numbered pin.
In this case, you'd supply the pin pair number of the SCL pin and the SDA pin would be the next lower.
You'd have ADDR = SCL << 18 where SCL = 6.
Please change BB_definitions back the way it was originally.
Note that the least significant byte is sent first and the most significant byte is sent second so bits 0-15 of the I/O expander should still correspond to bits 0-15 of the value passed to writeExpander.
Mike so you want the BB_definitions to have the following:
James
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
I made the following changes as you suggest,
I put the bb_definitions back original.
I used the shr asm command because, like a dummy, I put the pins backwards (and on an odd pin) on the breakout board.
I changed this in the PCF8575 driver object:
SCL = 6
ADDR = bootADDR + $40 << 8
bootADDR = SCL << 18
If I do not shift the SCL address in with the bootaddr, the chip never gets activated.
I think I'm going to need to modify the asm. I think it is doing two (2) write commands of 8 bits each. The PCF requires a 16 bit command (Address + 16). I think that is where the problem occurs.
I'm not positive that is the problem, but it seems to be. The first half (15-8) I/O barely blink (very rapid on and off) when turned on and off. The second half of the I/O (7-0) work as advertised (which makes no sense). I have tested with a spin Driver and it works fine until I switch over to asm.
I'm just guessing at this point.
James
BTW, I appreciate your help. I have learn more from Beau and you than anyone.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother SMT Assembly Services
I'm sorry I gave you wrong advice. The PCF9554 requires one address byte before the data while the PCF8575 only uses two data bytes. The following is corrected. The device select code is incorporated into the "addr" value. You can define "ADDR = (SCL << 18) + $40". Note that the device select code is in the least significant byte of the address for devices without an address byte.
Then you call it with "writeExpander(6<<18+$40,OUT)" or "writeExpander(ADDR,OUT)" with ADDR defined as above.
Post Edited (Mike Green) : 4/20/2009 7:26:52 PM GMT