Stupidest things ever (or am I stupid?)
Bobb Fwed
Posts: 1,119
OK...I've been banging my head against the wall ...trying to figure this one out:
Program 1:
Program 2:
Should be the same program right? In both test88 is ignored.
On my test board here...program 1 sets pin 13 high...and nothing on pin 24
Program 2 does exactly what is should do...turn pin 24 high and low...nothing anywhere else...
WTF!!!! I've tried this on two different boards, same results.
If you change one thing...like add a waitcnt(clkfreq + cnt) before the cognew is called...then it works fine again.
There's no way it could be the µController...right? What am I doing wrong...or am I just missing the simplest mistake ever!? Or is it something with my hardware...but look at the program...there should be zero difference, right!?
...I'm frustrated to say the least...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
Program 1:
CON OBJ VAR PUB Main cognew(@test1, 0) DAT ORG 0 test88 MOV DIRA, Pin XOR OUTA, Pin test1 MOV DIRA, Pin :loop XOR OUTA, Pin JMP #:loop Pin LONG |< 24 FIT 496
Program 2:
CON OBJ VAR PUB Main cognew(@test1, 0) DAT ORG 0 test88 'MOV DIRA, Pin 'XOR OUTA, Pin test1 MOV DIRA, Pin :loop XOR OUTA, Pin JMP #:loop Pin LONG |< 24 FIT 496
Should be the same program right? In both test88 is ignored.
On my test board here...program 1 sets pin 13 high...and nothing on pin 24
Program 2 does exactly what is should do...turn pin 24 high and low...nothing anywhere else...
WTF!!!! I've tried this on two different boards, same results.
If you change one thing...like add a waitcnt(clkfreq + cnt) before the cognew is called...then it works fine again.
There's no way it could be the µController...right? What am I doing wrong...or am I just missing the simplest mistake ever!? Or is it something with my hardware...but look at the program...there should be zero difference, right!?
...I'm frustrated to say the least...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
Comments
I guess we're both stupid!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
Post Edited (Rayman) : 6/17/2009 1:04:37 AM GMT
Does that make sense?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
Thank you for killing my headache!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
...yeah, my first object with multiple entries into the PASM code....usually I just have one..and the PASM figures it out..but I guess I got a little too fancy for my level of PASM expertise....you live you learn...then you realize just how little you actually know.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
Won't work. They are not relative in the sense you think they are. It's the '$' operator and it means the current compiler cog address.
In the context of the program above it'd still be wrong.
This will give you an infinite loop, but the actual code compiled is hardcoded to those locations, so to load it elsewhere in a cog will cause mayhem.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Missed it by ->" "<- that much!
I think there's a way to do it by changing the DAT code before launching the code... Just calculate the #longs between your desired start point and the actual ORG 0 and then subtract that difference from all the JMP lines in your DAT section...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
Yep, that'd do it but you also need to shuffle _all_ your source and dest addresses. Basically look at the instruction and if it does not have the 'i' bit set you need to re-calculate the source and destination addresses, otherwise you only need to recalculate the dest address.
Is it really worth that much trouble?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Missed it by ->" "<- that much!
Long answer - the COG will load the 496 longs starting from the address provided in COGINIT/COGNEW and start executing the first instruction. The PropTool (or equivalent) has to change all labels to absolute register numbers (i.e. JMP #:loop becomes JMP #1). The ORG 0 tells the PropTool to restart the register numbering at 0. So in Program 1 it gets to JMP #:loop and changes it to JMP #3, while for Program 2 it gets changed to JMP #1. However, in both cases :loop XOR OUTA, Pin gets loaded into register 1 by COGNEW( @test1, 0 ). Result - Program 1 effectively does a JMP #Pin and goes off to never-never-land.
Now, there's no reason you can't have multiple PASM programs in a single DAT section, just precede each by ORG 0. However, trying to have overlapping code (i.e. COG 1 contains code A + code B, and COG 2 contains code B + code C with the DAT being code A code B code C) just seems like a lot of effort and complexity to save a minor amount of HUB RAM. Much easier to duplicate the overlapping code in the DAT section, or create the code so both COGs get loaded with all the routines and then JMP to the starting address. For example:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Composite NTSC sprite driver: http://forums.parallax.com/showthread.php?p=800114
NTSC color bars (template): http://forums.parallax.com/showthread.php?p=803904
I think I will go with the PASM-controlled routing, like you suggested.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
This is a custom driver I wrote for a MCP3008. It just gets the voltage of each channel and feeds it back to the volts long(s).
It seems to work on only channel 0.
The headache is I am getting the whole pin 13 is going high and low randomly depending on how I add or remove code.
I'm still in the pangs of learning PASM, so please any criticism would be nice on how to make the code better.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
Post Edited (Bobb Fwed) : 6/17/2009 10:51:29 PM GMT
Shouldn't your variables use RESs instead of LONGs? Like this example line
val RES 1
At least that's what I understand.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
Long allows you to let SPIN set DAT values, its very handy.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
You better do something after that line, e.g. fetch the next command, wait forever or terminate the cog. But what you don't want is execute data [noparse]:)[/noparse] I cannot guarantee that this is the source of your problem but it certainly contributes.