PDA

View Full Version : PASM problem - Too many hub accesses?



Chris_D
12-18-2009, 02:09 AM
Hi folks,

I am tyring to narrow down a very odd problem.· I have an ASM program which runs in 3 cogs.· Each cog is sent its own base address to access hub memory with the start routine.· All has been working very good with the code until recently.

If I add just one more rdlong command, "Strange" things start happening - too convoluted to define it any better yet.

As with all the other rdlongs, the format I follow is this..

·· Mov··· Hub_Index, par
···Add··· Hub_index, #72· 'or whatever offset value I need
·· Rdlong FeedHold, Hub_index

I have about another 20 or more similar reads and or writes to the hub memory and they all work as expected.· I have even tried using different variable names so that the data being read shouldn't affect anything, yet the problem is the same.· I have also tried reading other variables from the hub, the problem is the same.

This is part of a motion controller I am working on.· The "Strange" behaviour is showing up in motions and I have yet to track down what is changing in the software that results in the odd motion problems.·· I just can't seem to figure out how reading data can screw up some variables elsewhere.· I know this is all terribly vague, but does anyone have any suggestions?

Oh, and yes I have the # signs where I am using literals,

Chris

SamMishal
12-18-2009, 02:31 AM
Chris,



It sounds to me that you might have run out of COG RAM....check that the code
still fits within the 512 longs·of cog ram.



Samuel

jazzed
12-18-2009, 02:33 AM
Chris_D said...

Mov Hub_Index, par
Add Hub_index, #72 'or whatever offset value I need
Rdlong FeedHold, Hub_index


I could be wrong, but this looks like a pipe-line problem. Add an instruction like NOP between instructions that change an instruction and the instruction changed. For example:




Mov Hub_Index, par
Add Hub_index, #72 'or whatever offset value I need
NOP ' or some useful instruction ... this ensures the next instr. is ready
Rdlong FeedHold, Hub_index

Phil Pilgrim (PhiPi)
12-18-2009, 02:36 AM
No, that example does not affect the pipeline, since the value of Hub_Index isn't fetched with the instruction, but in a later cycle.

-Phil

jazzed
12-18-2009, 02:57 AM
So it's only the instruction opcode that is affected by the pipe? Changing S and D happen in time? What about movs / movd ???

Chris_D
12-18-2009, 02:58 AM
Memory check information,,,

I hit "View Info" for the asm code

Program 284 Longs

Variable 1 long

Stack/Free 7,903 Longs

Not sure why is shows only 1 LOng, I know I got a lot more than that used for variables



Chris

Phil Pilgrim (PhiPi)
12-18-2009, 03:12 AM
jazzed,

Anything written directly into the next instruction fetched will require pipeline considerations. Otherwise, no, it's not an issue.

-Phil

photomankc
12-18-2009, 03:25 AM
I'm an assembly moron but in my recent adventures in capturing a signal I ran into really weird behavior when I had my entry label above the code on a blank line after "org 0". I only tracked that down when I noticed that the variable I expected to be written wasn't and the one just above it was after some cursing. There could have been more to it as well since I had PASD inserted in the code too.

SamMishal
12-18-2009, 03:27 AM
Chris_D said...Not sure why is shows only 1 LOng, I know I got a lot more than that used for variables
Maybe that is an indicator of what is going wrong....something is making the compiler
THINK that you have one variable.....so maybe the variables are not being set correctly and
thus when you RDLNG you are reading bad data.....

Investigate WHY you are getting only 1 long instead of the many you are expecting....this may lead to
the area that is causing the trouble in general.

Samuel
·

Chris_D
12-18-2009, 03:32 AM
Hmmm, even more strange...

Working through this, I decided to add a handfull of variables that I would treat as pointers.· Then, in the actual program loop, I wouldn't need to fetch the PAR variable and deal with adding my offset values.

Interestingly, I simply added

·· Mov··· Hub_Index, par
···Add··· P_FeedHold, #72

and this creates the same problem as detailed before. So this thing doesn't actually related to the RDLONG or WRLONG statement specifically.· It is like I am out of memory or something.· I few posts ago I offered up what the VIEW INFO is telling me and from what I can tell, I should have plenty of room left. But this problem sure seems to be indicating otherwise.

Chris

jazzed
12-18-2009, 03:45 AM
Phil Pilgrim (PhiPi) said...
jazzed,

Anything written directly into the next instruction fetched will require pipeline considerations. Otherwise, no, it's not an issue.

-Phil

Brainfart! eeew. Pardon me :) For some reason I misinterpreted the original it as something like this:




Add :readit, #4
:readit Rdlong FeedHold, 0-0




Must ... pull ... head ... out ... of ......

MagIO2
12-18-2009, 04:10 AM
Why don't you give us the whole code?

Chris_D
12-18-2009, 04:31 AM
MagIO2,



I might have to.· Right now I am trying to streamline it a bit to see if I can reduce the code size.· The problem certainly seems as though I am out of memory somewhere.· I just tried adding 5 NOP codes and that caused the problem to come back.



CHris

SamMishal
12-18-2009, 04:53 AM
Chris,

I am sure you are taking in consideration ALL your DAT variables.....these are not counted by the
compiler as VARIABLES per se....they are DATA not variables and thus the compiler will not count
them as variables.......you have to see where the code (including PASM lines) starts and ends and count
the number of longs that you are expecting to be copied to the COG when you start it.

Remember that the cog will load 512-16 = 496 longs no matter what......

So if some of your DAT variables are beyond this then you will definitely have a problem of ram
since now you are expecting some DAT variables to be part of the cog ram when you load the cog
but they are not......



Samuel

ericball
12-18-2009, 05:08 AM
SamMishal said...

So if some of your DAT variables are beyond this then you will definitely have a problem of ram
since now you are expecting some DAT variables to be part of the cog ram when you load the cog
but they are not......


This is where the "FIT 496" directive comes in.· Just like "ORG 0" is normally before the entry point of your PASM code, "FIT 496" should be after the last opcode, long or res in your PASM code.



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Composite NTSC sprite driver: Forum (http://forums.parallax.com/showthread.php?p=800114)
NTSC & PAL driver templates: ObEx (http://obex.parallax.com/objects/483/) Forum (http://forums.parallax.com/showthread.php?p=803904)
OnePinTVText driver: ObEx (http://obex.parallax.com/objects/480/) Forum (http://forums.parallax.com/showthread.php?p=822453)


Post Edited (ericball) : 12/17/2009 9:21:36 PM GMT

SamMishal
12-18-2009, 05:19 AM
ericball said...the "FIT 496" directive comes in.· Just like "ORG 0" is normally before the entry point of your PASM code, "FIT 496" should be after the last opcode or long in your PASM code.
YES...I forgot about that directive.....EXACTLY....use the Fit 496 directive just under the last part of DATs and code
you need to go in the Cog....and if it does not fit you will get a COMPILE time error... thanks Eric for reminding
me about it.....

Samuel

Chris_D
12-18-2009, 05:23 AM
Yup, This sure does appear to be a memory problem.· I changed all of my code from

·· Mov··· Hub_Index, par
···Add··· Hub_index, #72· 'or whatever offset value I need
·· Rdlong FeedHold, Hub_index

to setting up pointers at the start of the program which in turn changes the hub access to,,,

·Rdlong FeedHold, P_FeedHold

This reduced my code size from 284 to 248.· My program is running again and I am guessing I still have a little wiggle room to add the remaining features.

Phew, didn't see this problem comming!

Thanks everyone, hopefully this is resolved.

Chris

MagIO2
12-18-2009, 06:04 AM
Why don't you use the fit compiler instruction? It will tell you if you exceed the limit of COG-RAM.
If you use COG-RAM as variables you should at least REServe. In this way the fit takes also variable space into account.

org 0

mov Hub_Index, par
...

FeedHold res 128

fit 496



PS: It's late ... I'm tired ... and I think I missed some posts in between ;o) ... never mind

Post Edited (MagIO2) : 12/17/2009 10:09:24 PM GMT

ericball
12-18-2009, 10:42 AM
Chris_D said...
This reduced my code size from 284 to 248.· My program is running again and I am guessing I still have a little wiggle room to add the remaining features.

That's strange as each cog holds 496 longs.· That's 496 instructions, long/word/byte and res.· So either you have 200+ non instructions or something else is going on.


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Composite NTSC sprite driver: Forum (http://forums.parallax.com/showthread.php?p=800114)
NTSC & PAL driver templates: ObEx (http://obex.parallax.com/objects/483/) Forum (http://forums.parallax.com/showthread.php?p=803904)
OnePinTVText driver: ObEx (http://obex.parallax.com/objects/480/) Forum (http://forums.parallax.com/showthread.php?p=822453)

kuroneko
12-18-2009, 10:53 AM
It'd really help to see the code (at least the startup sequence, i.e. cognew & Co). A single long variable sounds a bit fishy. Or is par by any chance referencing DAT?

Chris_D
12-18-2009, 07:43 PM
After positing my "Resolved" comment, things got goofy again.· A little later this morning when I wake up, I will post the code for this object.·

I added a few more lines of code and again it went goofy - the view info showed the program at 262 longs and I know I dont have that·200 or so·variables!

Something is just not right with that thing.

Chris

Ale
12-18-2009, 08:07 PM
Are you sure you used a ORG directive ? sometimes the code seems to work without it...

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit some of my articles at Propeller Wiki:
MATH on the propeller propeller.wikispaces.com/MATH (http://propeller.wikispaces.com/MATH)
pPropQL: propeller.wikispaces.com/pPropQL (http://propeller.wikispaces.com/pPropQL)
pPropQL020: propeller.wikispaces.com/pPropQL020 (http://propeller.wikispaces.com/pPropQL020)
OMU for the pPropQL/020 propeller.wikispaces.com/OMU (http://propeller.wikispaces.com/OMU)

Chris_D
12-18-2009, 08:36 PM
Yup, I have ORG 0 at the top of my code, well, atleast it was there the last time I checked :-)


Chris

Chris_D
12-18-2009, 09:13 PM
Here is the code for the offending application...

The top part of the file is the actual code,·at the bottom in the commented area·is the top portion of the main program which has all the hub variables and object/cog startups.· Notice that the object is loaded into 3 cogs, one for each axis of motion.· Each object is directed to its own set of variables to work with.· When the "Strange problems" start happening, it appears as though something is changed in one of the 3 COGs, (Specifically, the 2nd axes which is Y) even though the inputs provided should not be affecting that axis.· I have yet to track down exactly what is being changed - even with viewport I have yet to see the data being changed.



{
}

VAR
· long· cog·························· ' This is in hub ram

PUB start(A1sp,A1dp,Homep,ProbeP,A1iP,P_offset,FlagPoi nter) : okay
'Step pin, Dir pin, Home sw pin, Probe sw pin, Axis indicator LED pin, Pointer offset, Pointer to start of data
A1S_pinmask := |< A1sp········· 'Set pinmasks for each pin
A1D_pinmask := |< A1dp········· '|< means bitwise decode with single bit high
Home_Sw_mask := |< Homep
Probe_mask := |< ProbeP
ACU_Active_pinmask := |< A1iP········· '|< means bitwise decode with single bit high
Pntr_Offset := P_Offset

okay := cog := cognew(@entry, FlagPointer) + 1·

PUB stop

'' Stop - frees a cog
· if cog
··· cogstop(cog~ -· 1)


DAT

entry·················· Org···· 0······················ 'Specify location of code
······················· mov···· Home_SW_Flag,#0········ 'Set flag to zero
······················· mov···· Hub_Index, par
······················· or····· dira,A1S_pinmask······· 'Sets pin to an output
······················· or····· dira,A1D_pinmask······· 'Sets pin to an output
······················· or····· outa,A1D_pinmask······· 'Set direction pin high
······················· or····· dira,ACU_Active_pinmask 'Sets pin to an output
······················· or····· outa,ACU_Active_pinmask 'Makes active pin high to turn on LED

······················· 'Check home/limit switch
······················· mov···· InpStates,ina·················· 'copy the ina reg to InpStates for comparisions
······················· and···· InpStates,Home_Sw_mask········· 'Exclude all other pins for comparison
······················· xor···· InpStates, Home_Sw_mask wz,nr·· 'Set Z flag ONLY if switch is made
············· if_z····· mov···· Home_Sw,#1
············· if_nz···· mov···· Home_sw,#0
······················· 'check Probe switch here
······················· mov···· InpStates,ina·················· 'copy the ina reg to InpStates for comparisions
······················· and···· InpStates,Probe_mask··········· 'Exclude all other pins for comparison
······················· xor···· InpStates, Probe_mask wz,nr···· 'Set Z flag ONLY if switch is made
············· if_z····· mov···· Probe_Sw,#1···················· 'Set probe flag to ON
············· if_nz···· mov···· Probe_sw,#0···················· 'Set probe flag to OFF
······················· 'Set counters and trigger times
······················· mov···· A1_PrevCnt,Cnt
······················· mov···· A1_CurCnt,MinInt
······················· mov···· A1_TrigTime,MinInt
······················· Adds··· A1_TrigTime, A1V_Delay········· 'Add in delay amount
······················· mov···· NewMoveFlag, #0················ 'Default to use existing move data
······················· 'Millisecond timer
······················· mov···· mSecPrevCnt,Cnt
······················· mov···· mSecCurCnt,MinInt
······················· mov···· mSecTrigTime,MinInt
······················· Adds··· mSecTrigTime, mSecDelay········· 'Add in delay amount

······················· mov···· NewMoveFlag, #0················ 'Default to use existing move data
······················· mov···· Hub_Index, PAR
······················· mov···· P_A1P_AbsPos, Hub_Index
······················· add···· Hub_Index , #4
······················· mov···· P_A1P_TarPos , Hub_Index
······················· add···· Hub_Index , #4
······················· mov···· P_Param_Dir , Hub_Index
······················· add···· Hub_Index , #4
······················· mov···· P_A1V_Delay , Hub_Index
······················· add···· Hub_Index , #8
······················· mov···· P_To_Go , Hub_Index·······························
······················· add···· Hub_Index , #4
······················· mov···· P_Target_VelSps , Hub_Index
······················· add···· Hub_Index , #4
······················· mov···· P_Acc_RateSpsS , Hub_Index
······················· add···· Hub_Index , #4
······················· mov···· P_Dec_RateSpsS , Hub_Index
······················· add···· Hub_Index , #8
······················· mov···· P_Cur_VelSps , Hub_Index
······················· add···· Hub_Index , #4
······················· mov···· P_Dist_2_Decel , Hub_Index
······················· add···· Hub_Index , #4
······················· mov···· P_Terminal_VelSps , Hub_Index
······················· add···· Hub_Index , #12
······················· mov···· P_Home_SW , Hub_Index
······················· add···· Hub_Index , #4
······················· mov···· P_NewMoveFlag , Hub_Index
······················· add···· Hub_Index , #4
······················· mov···· P_Axis_Stop, Hub_Index
'······················· add···· Hub_Index , #4
'······················· mov···· P_Hold , Hub_index
······················· add···· Hub_Index , #12
······················· mov···· P_IsHoming , Hub_Index
························
'----------------------------------------------------------------------------------------------------
'----------------------------------------------------------------------------------------------------
'----------------------------------------------------------------------------------------------------
'----------------------------------------------------------------------------------------------------


WaitForMCMReady········ mov···· Hub_Index, par················· 'reset pointer
······················· add···· Hub_index, #60················· 'increment to variable
······················· rdlong· McmReady,Hub_Index············· 'write Home_SW state to Ax_Status
······················· cmp···· McmReady,#0 Wz
······· If_Z··········· jmp···· #LoadConfig
······················· jmp···· #WaitForMCMReady··············· 'Endless loop waiting for ready
LoadConfig············· mov···· Hub_Index, par
······················· add···· Hub_index, #88················· 'increment to variable
······················· rdlong· CLC_State, Hub_index··········· 'read motor reversing parameter
······················· mov···· Hub_Index, par················· 'prepare for read from hub memory
······················· add···· Hub_Index,#84·················· 'adjust index pointer
······················· rdlong· EncPointer, Hub_index·········· 'read pointer to encoder position

'----------------------------------------------------------------------------------------------------

LoadCommand············ mov···· Hub_Index, par················· 'prepare for read from hub memory
······················· add···· Hub_Index,#64·················· 'adjust index pointer
······················· rdlong· NewMoveFlag, Hub_index········· 'read variable
······················· cmp···· NewMoveFlag, #0 Wz············· 'Wz = 0 if no new move data
······· if_z··········· jmp···· #Determine_Dir

Update_Params·········· rdlong· A1P_TarPos, P_A1P_TarPos·········· 'read target position
······················· rdlong· Param_Dir, P_Param_Dir··········· 'read motor reversing parameter

······················· rdlong· Target_VelSps, P_Target_VelSps······· 'read target velcoity from hub
······················· rdlong· Acc_RateSpsS, P_Acc_RateSpsS········ 'read acceleration rate from hub
······················· rdlong· Dec_RateSpsS, P_Dec_RateSpsS········ 'read deceleration rate from hub

Reset_NewMoveFlag······ mov···· NewMoveFlag, #0················ 'Set NewMoveFlag back to zero
······················· wrlong· NewMoveFlag, P_NewMoveFlag········· 'write variable to hub

Determine_Dir·········· cmps··· A1P_TarPos,A1P_AbsPos wc······· 'compare target to current position
······· if_c··········· jmp···· #Set_Rev······················· 'Target is <= current - move reverse
·······
Set_Fwd················ mov···· A1P_delta,DeltaPlus············ 'Make counter increase in pos direction
······················· cmp···· Param_Dir, #0 wz··············· 'Check direction parameter
······· if_z··········· andn··· outa,A1D_pinmask··············· 'Set direction pin to low
······· if_nz·········· or····· outa,A1D_pinmask··············· 'Set direction pin to high
······················· jmp···· #Counter
·······················
Set_Rev················ mov···· A1P_delta,DeltaMinus··········· 'Make counter decrease in neg direction
······················· cmp···· Param_Dir, #0 wz
······· if_nz·········· andn··· outa,A1D_pinmask··············· 'Set direction pin to low
······· if_z··········· or····· outa,A1D_pinmask··············· 'Set direction pin to high
·················································· ············· 'Check direction parameter
Counter················ mov···· ElapsedCnt,A1_PrevCnt·········· 'copy prevCnt into ElapsedCnt·····
······················· mov···· IntCnt,Cnt····················· 'Copy Cnt into IntCnt
······················· subs··· IntCnt,ElapsedCnt·············· 'Subtract IntCnt from ElapsedCnt, IntCnt equals cycles since last check
······················· mov···· A1_PrevCnt,Cnt················· 'Copy Cnt into PrevCnt to reset it
······················· adds··· A1_CurCnt, IntCnt·············· 'Add IntCnt to CurCnt to update it

MsecCounter············ mov···· mSecElapsed,mSecPrevCnt········ 'copy prevCnt into ElapsedCnt·····
······················· mov···· mSecIntCnt,Cnt················· 'Copy Cnt into IntCnt
······················· subs··· mSecIntCnt,mSecElapsed········· 'Subtract IntCnt from ElapsedCnt, IntCnt equals cycles since last check
······················· mov···· mSecPrevCnt,Cnt················ 'Copy Cnt into PrevCnt to reset it
······················· adds··· mSecCurCnt, IntCnt············· 'Add IntCnt to CurCnt to update it

VelControl············· cmps··· mSecCurCnt,mSecTrigTime Wc······ 'compare current time to trigger time
······· if_c··········· jmp···· #FetchEncoder
·······················

FetchVelControlData···· rdlong· Target_VelSps,P_Target_VelSps
······················· rdlong· Dist_2_Decel, P_Dist_2_Decel········ 'Read distance to decel from hub
······················· rdlong· Terminal_VelSps, P_Terminal_VelSps····· 'Read Terminal velocity from hub
'······················· rdlong· Hold, P_Hold

'HoldSkip1·············· cmp···· Hold, #1 wz
'······················· mov···· Local_Hold, #0····················· 'Turn local hold off
'······· if_nz·········· jmp···· #CheckDecelTime···················· 'feed hold not active move along
'······················· cmp···· Cur_VelSps, #60· wc················ 'stop if less than 60 SPS
'······· if_c··········· mov···· Local_Hold, #1····················· 'Turn on local hold
'······· if_c··········· jmp···· #ResetmSecTimer···················· 'Jump over ACC & DEC

CheckDecelTime········· cmp···· To_Go,Dist_2_Decel Wc·········· 'is distance to go < distance to decel·······················
······· if_C··········· mov···· Target_VelSps,Terminal_VelSps·· 'Set taget vel to terminal vel············

Acc_Dec_Decision······· cmp···· Cur_VelSps,Target_VelSps Wz,Wc· 'Compare velocities
······· if_c_or_z······ jmp···· #Accelerate···················· 'Cur_VelSps <= Target_VelSps
······· if_nz·········· jmp···· #Decelerate···················· 'Cur_velSps > Target_VelSps
······················· jmp···· #ResetmSecTimer················ 'Cur_velSps = Target_VelSps

Accelerate············· add···· Cur_VelSps,Acc_RateSpsS
······················· cmp···· Cur_VelSps,Target_VelSps Wz,Wc· 'Compare velocities
······· if_nc_and_nz··· mov···· Cur_VelSps,Target_VelSps······· 'overshot, make same
······················· wrlong· Cur_VelSps, P_Cur_VelSps····· 'Write Cur_VelSps to hub memory
······················· jmp···· #ResetmSecTimer

Decelerate············· sub···· Cur_VelSps,Dec_RateSpsS
······················· cmp···· Cur_VelSps,Target_VelSps Wz,Wc· 'Compare velocities
······· if_c··········· mov···· Cur_VelSps,Target_VelSps······· 'overshot, make same
······················· wrlong· Cur_VelSps, P_Cur_VelSps····· 'Write Cur_VelSps to hub memory
······················· jmp···· #ResetmSecTimer
································
ResetmSecTimer········· mov···· mSecPrevCnt,Cnt
······················· mov···· mSecCurCnt,MinInt
······················· mov···· mSecTrigTime,MinInt
······················· Adds··· mSecTrigTime, mSecDelay········· 'Add in delay amount

FetchEncoder··········· cmp···· CLC_State,#1 Wz················ 'check if closed loop control is on
······················· mov···· Hub_Index, par················· 'prepare for read from hub memory
······················· add···· Hub_Index,EncPointer··········· 'adjust index pointer
······················· rdlong· Encoder_Pos, Hub_index········· 'read encoder position

······················· wrlong· Encoder_Pos,P_A1P_AbsPos··········· 'write the value into A1P_AbsPos

FetchAbsPos············ rdlong· A1P_AbsPos, P_A1P_AbsPos·········· 'read variable


······················· 'check home/limit switch here··· NOTE-SIGNAL LOW MEANS SWITCH IS MADE!
HomeLimitSW············ mov···· InpStates,ina·················· 'copy the ina reg to InpStates for comparisions
······················· and···· InpStates,Home_Sw_mask········· 'Exclude all other pins for comparison
······················· xor···· InpStates, Home_Sw_mask wz,nr·· 'Set Z flag ONLY if switch is made
············· if_z····· mov···· Home_Sw,#0····················· 'Set home_Sw to OFF
············· if_nz···· mov···· Home_sw,#1····················· 'Set home_Sw to ON

······················· rdlong· IsHoming,P_IsHoming············· '
······················· cmp···· IsHoming, #1 wz················ 'test if in homing routine
············· if_nz···· jmp···· #LimitHandler·················· 'not homing, normal OT switch handler
······················· cmp···· HomeStage, #0 wz··············· 'if stage = 0 = looking for limit switch
············· if_z····· jmp···· #HomeStage0
······················· cmp···· HomeStage, #1 wz··············· 'if stage = 1 = Switch was made
············· if_z····· jmp···· #HomeStage1

LimitHandler··········· wrlong· Home_SW,P_Home_SW·············· 'write Home_SW state to Ax_Status
······················· Rdlong· Axis_Stop,P_Axis_Stop·············· 'Read axis stop variable
······················· jmp···· #Test4Step

HomeStage0············· cmp···· Home_Sw, #0 wz················· 'check if switch was made
············· if_z····· mov···· HomeStage, #1·················· 'switch was made adjust homestage to step 2
············· if_z····· mov···· HomeReverse, #0················ 'Set var to zero
············· if_z····· subs··· HomeReverse,A1P_TarPos········· 'subtraction 0-target position to invert value
············· if_z····· mov···· A1P_TarPos, HomeReverse········ 'move inverted value into target position···············
······················· jmp···· #Test4Step
·······················
HomeStage1············· cmp···· Home_Sw, #1 wz················· 'check if axis moved off switch
············· if_z····· mov···· A1P_TarPos,A1P_AbsPos·········· 'make target position = current position
············· if_z····· mov···· HomeStage, #0·················· 'reset home stage
············· if_z····· mov···· IsHoming,#0···················· 'reset IsHoming flag to zero

Test4Step·············· cmp···· IsHoming, #1 wz
······· if_z··········· jmp···· #Test4Step_2··················· 'skip over home switch test
······················· cmp···· Home_sw,#0 Wz·················· 'Compare Home_Sw state to ON
······· If_z··········· jmp···· #LoadCommand
Test4Step_2············ cmp···· Axis_Stop, #1 Wz··············· 'Check if any other axis is overtraveled
······· If_z··········· jmp···· #LoadCommand
······················· cmps··· A1P_AbsPos, A1P_TarPos Wz······ 'compare if position equals target position
······· if_z··········· jmp···· #LoadCommand··················· 'at position so just skip everything·······
······················· cmps··· A1_CurCnt,A1_TrigTime wc······· 'Compare if it is time to step
······· if_c··········· Jmp···· #LoadCommand··················· 'not yet, skip over to check on other axis

TargetRange············ Mov···· Off_Pos, A1p_AbsPos
······················· subs··· Off_Pos, A1P_TarPos
······················· abs···· Off_Pos, Off_Pos
······················· cmp···· Off_Pos, #10 Wc
······· If_nc·········· jmp···· #ResetCounter
······················· mov···· A1V_Delay, SlowVel
······················· wrlong· A1V_Delay, P_A1V_Delay

ResetCounter··········· mov···· A1_CurCnt, MinInt·············· 'reset counter
······················· mov···· A1_time,cnt···················· 'Sets time = to count
······················· adds··· A1_time,Pulse_time············· 'add pulse time to time to create a delay

······················· or····· outa,A1S_pinmask··············· 'Set step pin high
······················· waitcnt A1_time,Pulse_time············· 'waits for time to pass, Pulse_time added to time automaticaly

UpdateDelay············ rdlong· A1V_Delay, P_A1V_Delay··········· 'read variable
······················· mov···· A1_TrigTime,MinInt············· 'reset trigtime to min integer value
······················· Adds··· A1_TrigTime, A1V_Delay········· 'Add in delay amount

······················· mov···· To_Go,A1P_TarPos··············· 'copy Absolute position into to_go
······················· Subs··· To_Go, A1P_AbsPos·············· 'Subtract current postion from target position
······················· abs···· To_Go, To_Go
······················· wrlong· To_Go,P_To_Go················ 'write the value into hub memory

······················· andn··· outa,A1S_pinmask················ 'Set step pin low
·······················
······················· Jmp···· #LoadCommand


' Initialized data
ClosedLoop············· Long··· 0··································
Zero··················· Long··· 0
MaxInt················· Long··· 2147483647
MinInt················· Long··· -2147483648
Pulse_time············· Long··· 75 '=2 usecs ontime *** a val of 160 for Pulse_time = .2 usecs = .000002 seconds
DeltaMinus············· Long··· -1
DeltaPlus·············· Long··· 1
'AXIS 1 VARIABLES
A1S_pinmask············ Long··· 0·· 'Step pin
A1D_pinmask············ Long··· 0·· 'Direction pin
Home_Sw_mask··········· Long··· 0·· 'Home switch pin mask
Probe_mask············· Long··· 0·· 'Probe input pin mask
ACU_Active_pinmask····· Long··· 0·· 'Indicator LED pin mask
Pntr_Offset············ Long··· 0·· 'Pointer offset to align with variables in HUB
·················································· ··········
A1D_Direction·········· Long··· 0·· 'Direction setting +1=ON(Fwd), 0=OFF(Rev)unless reversed by configuration parameters
A1D_Prev_Dir··········· Long··· -1· 'preset value for previous direction of motor
A1P_delta·············· Long··· 0·· 'Position delta change based on direction +1(Fwd) or -1(Rev)
A1P_AbsPos············· Long··· 0·· 'Absolute position counter
A1P_TarPos············· Long··· 0·· 'Target position
A1V_Delay·············· Long··· 0·· 'Velocity delay time
A1_TrigTime············ Long··· 0·· 'Trigger time ie, time to step
A1_PrevCnt············· Long··· 0·· 'Intermediate counter for checking laspsed time
A1_CurCnt·············· Long··· 0·· 'Counter used to count up from MinInt to Trigger time
Home_Sw················ Long··· 0·· 'Preset home switch to off, but check again at routine startup!
Home_SW_Flag··········· Long··· 0·· 'Flag used to allow capture @ moment of triggering
Probe_Sw··············· Long··· 0·· 'Preset probe switch to off, but check again at routine startup!
Param_Dir·············· Long··· 0·· 'Parameter for direction reversing 1=reverse it
Axis_Stop·············· Long··· 0·· 'Set to 1 when any axis is in overtravel state
EncPointer············· Long··· 0·· 'pointer to start byte of Encoder Position
CLC_State·············· Long··· 0·· 'if = 1, then closed loop control is on
Off_Pos················ Long··· 0
SlowVel················ Long··· 600_000
McmReady··············· Long··· 99· 'Default to not ready
mSecDelay·············· Long··· 80_000 'equals one millisecond
'mSecDelay·············· Long··· 40_000_000 'equals one millisecond
mSecTrigTime··········· Long··· 0

Target_VelSps·········· Long··· 0
Acc_RateSpsS··········· Long··· 0
Dec_RateSpsS··········· Long··· 0
Cur_VelSps············· Long··· 0
Terminal_VelSps········ Long··· 0
Dist_2_Decel··········· Long··· 0

IsHoming··············· Long··· 0 '0=not active, 1=active
HomeStage·············· Long··· 0 '0=looking for switch, 1=on switch, 2=moving away, 3=off switch
HomeReverse············ Long··· 0
Hold··················· Long··· 0
······················· FIT 496


' Uninitialized data
A1_time················ Res···· 1
A1_CurTime············· Res···· 1
Hub_Index·············· Res···· 1
ElapsedCnt············· Res···· 1
IntCnt················· Res···· 1
To_Go·················· Res···· 1
InpStates·············· Res···· 1
Target_enc············· Res···· 1
Encoder_Pos············ Res···· 1
Enc_Dif················ Res···· 1
NewMoveFlag············ Res···· 1
mSecElapsed············ Res···· 1
mSecPrevCnt············ Res···· 1
mSecIntCnt············· Res···· 1
mSecCurCnt············· Res···· 1
P_NewMoveFlag·········· Res···· 1
P_A1P_TarPos··········· Res···· 1
P_Param_Dir············ Res···· 1
P_Target_VelSps········ Res···· 1
P_Acc_RateSpsS········· Res···· 1
P_Dec_RateSpsS········· Res···· 1
P_Dist_2_Decel········· Res···· 1
P_Terminal_VelSps······ Res···· 1
P_Cur_VelSps··········· Res···· 1
P_Encoder_Pos·········· Res···· 1
P_A1P_AbsPos··········· Res···· 1
P_IsHoming············· Res···· 1
P_Home_SW·············· Res···· 1
P_A1V_Delay············ Res···· 1
P_To_Go················ Res···· 1
P_Axis_Stop············ Res···· 1
P_Hold················· Res···· 1


{
CON
······· _clkmode······· = xtal1 + pll16x
······· _xinfreq······· = 5_000_000
······· _Stack········· = 3000
var
· Long Delay
· Long LastCnt
· Long DeltaCnt
· Long Flag

· Long UpdateFlag···· '00)Flag to indicate that the step/dir/velocity parameters have changed
· Long A1_Pos········ '00)Absolute position counter
· Long A1_TargetPos·· '01)Target position to move to
· Long A1_Dir········ '02)1=fwd 0=Rev
· Long A1_Delay······ '03-00)Number of clock cycles to wait
· Long A1_Delta······ '04-01)+1 or -1, used to increment position counter
· Long A1_ToGo······· '05-02)Dist to go
· Long A1_TarVel····· '06-03)Target Velocity in STEPS PER SECOND
· Long A1_AccRate···· '07-04)Acceleration rate in STEPS PER SECOND/second
· Long A1_DecRate···· '08-05)Deceleration rate in STEPS PER SECOND/second
· Long A1_STD········ '09-06)Steps to declerate
· Long A1_CurSPS····· '10-07)Current Velocity in STEPS PER SECOND/second
· Long A1_Dist2Decel· '11-08)Distance to decelerate
· Long A1_TermVel···· '12-09)Terminal Velocity in SPS
· Long A1_TarEncPos·· '13-10)Target Encoder Position·········
· Long A1_Capture···· '14-11)Captured position from Home or Probe
· Long A1_Status····· '15-12)Status flag reporting from ACU
· Long A1_NewMove···· '16-13)Flag to indicate a new move is loaded
· Long A1_Stop······· '17-14)Stop flag - all axis are set when one axis OT.s
· Long A1_Hold······· '18-15)Feed Hold flag - Feed Hold or Override is at 0%
· Long A1_Spare3····· '19-16)
· Long A1HomeFlag···· '20-17)
· Long A1_EncPointer· '21-18)Pointer to Encoder position
· Long A1_ClosedLoop· '22-19) Use encoder feedback for position counter if = 1
· Long Prog_tarvel_1· '23-20)Programmed target velocity
· Long A1_Diff······· '24-21)Difference between encoder and target - written by CLC
· Long A1_Ratio······ '25-22)Motor steps / encoder steps = ratio x 100 for use in integer math
·
· Long A2_Pos········ ')Absolute position counter
· Long A2_TargetPos·· ')Target position to move to
· Long A2_Dir········ ')1=fwd 0=Rev
· Long A2_Delay······ ')Number of clock cycles to wait
· Long A2_Delta······ ')+1 or -1, used to increment position counter
· Long A2_ToGo······· ')Dist to go
· Long A2_TarVel····· ')Target Velocity in STEPS PER SECOND/second
· Long A2_AccRate···· ')Acceleration rate in STEPS PER SECOND/second
· Long A2_DecRate···· ')Deceleration rate in STEPS PER SECOND/second
· Long A2_STD········ ')Steps to declerate
· Long A2_CurSPS····· ')Current Velocity in STEPS PER SECOND/second
· Long A2_Dist2Decel· ')Distance to decelerate
· Long A2_TermVel···· ')Terminal Velocity in SPS
· Long A2_TarEncPos·· ')Target Encoder Position·········
· Long A2_Capture···· ')Captured position from Home or Probe
· Long A2_Status····· ')Status flag reporting from ACU
· Long A2_NewMove···· '17-13)Flag to indicate a new move is loaded
· Long A2_Stop······· 'Stop flag - all axis are set when one axis OT.s
· Long A2_Hold
· Long A2_Spare3
· Long A2HomeFlag··
· Long A2_EncPointer· ')Pointer to Encoder position
· Long A2_ClosedLoop· ') Use encoder feedback for position counter if = 1
· Long Prog_tarvel_2· ')Programmed target velocity
· Long A2_Diff······· ')Difference between encoder and target - written by CLC
· Long A2_Ratio······ ')Motor steps / encoder steps = ratio x 100 for use in integer math

· Long A3_Pos········ ')Absolute position counter
· Long A3_TargetPos·· ')Target position to move to
· Long A3_Dir········ ')1=fwd 0=Rev
· Long A3_Delay······ ')Number of clock cycles to wait
· Long A3_Delta······ ')+1 or -1, used to increment position counter
· Long A3_ToGo······· ')Dist to go
· Long A3_TarVel····· ')Target Velocity in STEPS PER SECOND/second
· Long A3_AccRate···· ')Acceleration rate in STEPS PER SECOND/second
· Long A3_DecRate···· ')Deceleration rate in STEPS PER SECOND/second
· Long A3_STD········ ')Steps to declerate
· Long A3_CurSPS····· ')Current Velocity in STEPS PER SECOND/second
· Long A3_Dist2Decel· ')Distance to decelerate
· Long A3_TermVel···· ')Terminal Velocity in SPS
· Long A3_TarEncPos·· ')Target Encoder Position·········
· Long A3_Capture···· ')Captured position from Home or Probe
· Long A3_Status····· ')Status flag reporting from ACU
· Long A3_NewMove···· '17-13)Flag to indicate a new move is loaded
· Long A3_Stop······· 'Stop flag - all axis are set when one axis OT.s
· Long A3_Hold
· Long A3_Spare3
· Long A3HomeFlag··
· Long A3_EncPointer· ')Pointer to Encoder position
· Long A3_ClosedLoop· ') Use encoder feedback for position counter if = 1
· Long Prog_tarvel_3· ')Programmed target velocity
· Long A3_Diff······· ')Difference between encoder and target - written by CLC
· Long A3_Ratio······ ')Motor steps / encoder steps = ratio x 100 for use in integer math

· Long A1_Encoder···· ')Encoder register for Axis 1····· THIS IS 43 Variables (172 bytes) past UpdateFlag
· Long A2_Encoder···· ')Encoder register for Axis 2····· THIS IS 44 Variables (176 bytes) past UpdateFlag
· Long A3_Encoder···· ')Encoder register for Axis 3····· THIS IS 45 Variables (180 bytes) past UpdateFlag
· Long ClosedLoop···· ')Closed Loop active flag!········ THIS IS 46 Variables (184 bytes) past UpdateFlag
· Long Interpolation· 'xx-77)Either 1 for linear or 2 for circular
· Long VelocityOverride········ '1% = 10000, 100% = 100,· 200% = 50

· Long Buff_XT······· 'Buffered Target X Pos
· Long Buff_XV······· 'Buffered Target X Velocity SPS
· Long Buff_XA······· 'Buffered X accel rate SPS/s
· Long Buff_XD······· 'Buffered X Decel rate SPS/s
· Long Buff_YT······· 'Buffered Target Y Pos
· Long Buff_YV······· 'Buffered Target Y Velocity
· Long Buff_YA······· 'Buffered Y accel rate SPS/s
· Long Buff_YD······· 'Buffered Y Decel rate SPS/s
· Long Buff_ZT······· 'Buffered Target Z Pos
· Long Buff_ZV······· 'Buffered Target Z Velocity
· Long Buff_ZA······· 'Buffered Z accel rate SPS/s
· Long Buff_ZD······· 'Buffered Z Decel rate SPS/s
· Long Buff_Stat····· 'Buffer status 0=empty 1=full
· Long Min_Vel······· 'Minum velocity used as default SPS
· Long Temp1
· Long MpuCmd
·
· Long A4_tt
· Long CNT_TRIG
· Long LocalCnt
· Long Test_Vel
· Long Test_Flag
· Long AcuDif
· Long Temp99
· Long Temp2
· Long Temp3
· Long EncDest
· Long MyCount
· Long MyCount2
· Long EncDif
· Long Mcu_Status
· Long MpuCmd_xxxx
· Long Axis1Dir
· Long Axis2Dir
· long Tmp_Vel1
· long tmp_vel2
· long tmp_vel3
· long tmp_vel4
· long tmp_Var1
· long tmp_var2
· long tmp_var3
· long tmp_var4
· long tmp_var5
· long tmp_var6
· Byte Byte_MC

· Long A1_Dir_Param
· Long A2_Dir_Param
· Long A3_Dir_Param

· Long Temp10
· Long Temp11
· Long Temp12
· Long Temp13
· Long Temp14
· Long Temp15
· Long Home_Flag
· Long Axis_to_home·· '1=X 2=Y 3=Z 4=C
· Long Prev_VelocityOverride
OBJ

· ACU·········· : "Acu2-11"············· 'Position Control Objects
· VelControl··· : "VCU2-11"········ 'Velocity Control Object
· Encoder······ : "Quadrature_Encoder"····· 'Quadrature encoder object
· SerIO········ : "FullDuplexSerial"······· 'Serial communications object
············ vp : "Conduit"




}

MagIO2
12-18-2009, 10:06 PM
The RES need to be before the FIT otherwise the compiler can't check that CODE and VARIABLES fit into the COG RAM.

That seems to be a Problem:
long tmp_var6
Byte Byte_MC

Long A1_Dir_Param
... as the compiler will reorganize this and your address counting might be different.

This code costs more COG-RAM than necessary:
mov Hub_Index, PAR
mov P_A1P_AbsPos, Hub_Index
add Hub_Index , #4
mov P_A1P_TarPos , Hub_Index
add Hub_Index , #4
mov P_Param_Dir , Hub_Index
add Hub_Index , #4
You can do it that way:
add P_A1P_AbsPos, par
add P_A1P_TarPos, par
add P_Param_Dir, par
....
P_A1P_AbsPos long 0
P_A1P_TarPos long 4
P_Param_Dir long 8
...
This way you could even do the whole add-thing in a loop, as you create 15 pointers.

You can save additional COG-RAM when using all the RAM between entry and waitForMCMReady as uninitialized memory. As you never use that code again you can use it differently after it's execution.

rdlong McmReady,Hub_Index 'write Home_SW state to Ax_Status
cmp McmReady,#0 Wz
If_Z jmp #LoadConfig
is the same as
rdlong McmReady,Hub_index WZ
if_Z jmp #LoadConfig

Neither of those tips might solve your problem .. but that was what jumped into my eye on a first glance .. Analyzing everything might take a while.

Chris_D
12-18-2009, 11:26 PM
Thanks much for the help.· Here is what I tried so far without success...

I moved the fit 496 to the end of the RES statements - program compiled okay, didn't fix problem

I moved that Byte variable which was in the hub memory to the end of the variable list - didn't fix the problem

Will be trying a few other things in your suggestion list in a few moments.

Thanks


Chris

Chris_D
12-18-2009, 11:51 PM
Hmmm, MagIO you found something....

I tried this arrangement.· I like the style and looks more clean and it may have corrected the problem I was having.· Oddly, the changes took MORE memeory according to the VIEW INFO report - 2 Longs to be exact.· Without the changes is was PROGRAM 255 LONGS, with the changes it was PROGRAM 257 LONGS.

I have added severl NOP statements (which caused the problem in the past) and it worked fine. I then added a couple of real logic lines and it too worked fine.



YOUR SUGGESTION...

This code costs more COG-RAM than necessary:
mov Hub_Index, PAR
mov P_A1P_AbsPos, Hub_Index
add Hub_Index , #4
mov P_A1P_TarPos , Hub_Index
add Hub_Index , #4
mov P_Param_Dir , Hub_Index
add Hub_Index , #4
You can do it that way:
add P_A1P_AbsPos, par
add P_A1P_TarPos, par
add P_Param_Dir, par
....
P_A1P_AbsPos long 0
P_A1P_TarPos long 4
P_Param_Dir long 8

THANK A BUNCH - let's hope this solves the problem for good

Chris
·

MagIO2
12-19-2009, 12:47 AM
Can't take more longs! Before you had a mov, a add and a res per pointer. The res won't eat HUB RAM, but the mov and the add. New style you only have a add and a long. So, there should be no difference in HUB-RAM space, but in COG-RAM you only need 2 longs per pointer instead of 3 longs per pointer. (in COG-RAM the res counts again).

Chris_D
12-19-2009, 02:20 AM
I agree 100%, I am only passing along what the VIEW INFO report is telling me (us).· So far so good still though, have been moving along without any more of those same problems.



Chris