Beyond Weird
CannibalRobotics
Posts: 535
Anybody have any idea why this peice of code sends out a pulse on AxCmDat pin but not the AxcCS pin? (8 & 10 respectively)
It get's better. I have the code deployed over multiple cogs. This code will work fine in other cogs so I know its not the hardware. This is where it gets really strange. I can switch the values of two variables 8 <->10 and the working pulse will change lines.
================================================
··· Dira[noparse][[/noparse]AxcCS] :=1·············· ' AXc Chip Select High·····
··· DIRA[noparse][[/noparse]AxCmDat] :=1············ ' Shift Data line to output
······························································
··· Outa[noparse][[/noparse]AxcCS] := 0···············' AXc Chip Select low
··· waitcnt((1_000 + cnt))······· ' Wait t_sucs
··· Outa[noparse][[/noparse]AxcCS] := 1··············· ' AXc Chip Select low
··· Outa[noparse][[/noparse]AxCmDat] := 0············' AXc Chip Select low
··· waitcnt((1_000 + cnt))······· ' Wait t_sucs
··· Outa[noparse][[/noparse]AxCmDat] := 1··········· ' AXc Chip Select low
================================================
================================================
·CON
······· AxCmDat = 8·· ' [noparse][[/noparse]Dxx] Data I/O line for compass and axcelerometer
······· CmEN· = 9···· ' [noparse][[/noparse]~EN] Compass Enable Line
······· AxcCS = 10··· ' [noparse][[/noparse]~CS] Axcelerometer Chip Select
······· AxcZG = 11··· ' [noparse][[/noparse]ZG] Axcel Zero G indicator - Free Fall
================================================
·
It get's better. I have the code deployed over multiple cogs. This code will work fine in other cogs so I know its not the hardware. This is where it gets really strange. I can switch the values of two variables 8 <->10 and the working pulse will change lines.
================================================
··· Dira[noparse][[/noparse]AxcCS] :=1·············· ' AXc Chip Select High·····
··· DIRA[noparse][[/noparse]AxCmDat] :=1············ ' Shift Data line to output
······························································
··· Outa[noparse][[/noparse]AxcCS] := 0···············' AXc Chip Select low
··· waitcnt((1_000 + cnt))······· ' Wait t_sucs
··· Outa[noparse][[/noparse]AxcCS] := 1··············· ' AXc Chip Select low
··· Outa[noparse][[/noparse]AxCmDat] := 0············' AXc Chip Select low
··· waitcnt((1_000 + cnt))······· ' Wait t_sucs
··· Outa[noparse][[/noparse]AxCmDat] := 1··········· ' AXc Chip Select low
================================================
================================================
·CON
······· AxCmDat = 8·· ' [noparse][[/noparse]Dxx] Data I/O line for compass and axcelerometer
······· CmEN· = 9···· ' [noparse][[/noparse]~EN] Compass Enable Line
······· AxcCS = 10··· ' [noparse][[/noparse]~CS] Axcelerometer Chip Select
······· AxcZG = 11··· ' [noparse][[/noparse]ZG] Axcel Zero G indicator - Free Fall
================================================
·
Comments
-Phil
Graham
-Phil
In a moment of pure despiration I moved the AxcCS out of the CON section, created a byte variable named AxcCS, set it equal to 10 and everything is working - go figure...
Thanks
waitcnt((1_000 + cnt))
Gives a delay of 0.0125ms if you are running at 80MHz
The 1.0 mSec number I tossed out is actually the time the enable line goes low to activate communication with the accel and A/D converter. I actually measured that one out to. It's roughly 1.7 mSec.
The code above (very top) was really not about delay issues, more about how the compilor seems to be misplacing data.
You've got to admit that if you are using an OUTA[noparse][[/noparse]pin] command and you change 'pin' from a constant ( in the CON section) to a varriable (in the VAR section) and it changes the behavior of the program, something is amiss in the code interpretation process, right?
Graham
Riddle me this? When I "compile top", the code below in one of the objects does not work.
When I "compile current" the code works fine.
Now, I know the cog is running in both compiles bc the call to this routine is in a loop which is reading and updating other AD and axcelerometer data without problems.
PUB PulseCompass
'
Test Pulse
waitcnt((5_000 + cnt)) ' Wait
OUTA[noparse][[/noparse]CmEN] := 0 ' Enable Down
waitcnt((5_000 + cnt)) ' Wait
OUTA[noparse][[/noparse]CmEN] := 1 ' Enable UP
-Phil
You need to remember that many people have posted errors like this and, on further examination, almost all of them have resulted from a problem in the program, either some kind of timing problem or a stack overflow or other situation where one part of a program is writing into a memory area used by another part. I think there was one true compiler error discovered since the Propeller was released and it was fairly subtle.
here tiz. I just want to say thanks in advance for your help.
Jim-
In one pic it's flat - that's the compile top.
The red line is clock, the green is the AxcCS chip select for the axceler. The blue is the sharred data line between the compass and axceler modules. The data are the conversation between the prop and the axc.
1) In ADC0838_Axc, you're setting up a bunch of I/O pins as outputs in the init method, then setting
up the same pins in another cog in the Main method. When two cogs attempt to control one I/O pin,
the output state is the OR of the values in that bit of the OUTA register in each cog. Except in very
specific circumstances, you never want to use the same I/O pin in more than one cog.
2) In ADC0838_Axc, you use COGINIT to start a 2nd cog (#6). Generally it's not a good idea to use
COGINIT unless you're restarting a specific cog. It's usually a bad idea to mix COGINIT and COGNEW
in the same program since it makes it easier to try to use the same cog for two different things when
that's not what you're expecting.
I do see one thing for certain: you're using coginit in your ADC object. That's pretty much a no-no. How do you even know that cog 6 is available? That might be why your code is failing when run from the top object but not when running just the ADC object.
If fixing that doesn't solve anything, can you come up with a minimal program, testable on a Demo board, say, that exhibits the same failure modes as your magnum opus? It would help to isolate the problem and help the forum volunteers if they don't have to wade through so much code.
-Phil
I'm going to look into item 2 over the weekend.
I'm still fightling my way out of the linear programming model and thought process.
Thanks and have a great weekend.
J-