using muliple cogs regarding Org Fit and Res
in Propeller 1
Hello,
I am working with multiple cogs in assembly, and have some questions on org,fit and res
basically where to place the fit org and res
when i run this code only two of the outputs work (two cogs output)
should the org offset for each cog like org 0 for the first, org 496 for the second and so on, should fit be at the end of each assembly routine, prior to the next org
and since the variables are accessable to all three should all the variables be assigned in the last cog start, does it matter where i place the res
anyway, I included the code
thanks in advance.
regards
Jeff
I am working with multiple cogs in assembly, and have some questions on org,fit and res
basically where to place the fit org and res
when i run this code only two of the outputs work (two cogs output)
should the org offset for each cog like org 0 for the first, org 496 for the second and so on, should fit be at the end of each assembly routine, prior to the next org
and since the variables are accessable to all three should all the variables be assigned in the last cog start, does it matter where i place the res
anyway, I included the code
thanks in advance.
regards
Jeff
CON
_CLKMODE = xtal1 + pll16x
_XINFREQ = 6_200_000
VAR
long routine1_cog, routine2_cog
long synctime1 'global var for both cogs
long synctime2 'global var for both cogs
long synctime3 'global var for both cogs
OBJ
pst : "Parallax Serial Terminal"
PUB main : tm
pst.Start(57_600)
waitcnt((clkfreq*1) + cnt)
pst.Str(String("Starting Cog ..... ",pst#NL))
' waitcnt((clkfreq*2) + cnt)
'synctime := CNT + 200000 'sync at now + 1 sec
synctime1 := 100000 'sync at now + 1 sec
routine1_cog := cognew(@lfs_heater,@synctime1) ' Start a Cog with our assembly routine, no stack
pst.Str(String("Cog Value1: "))
pst.Dec( routine1_cog)
pst.Str(String(" ",pst#NL))
' is required since PASM requires we explicitly
' assign and use memory locations within the Cog/Hub
' waitcnt(tm += 80_000)
synctime2 := 20740
routine1_cog := cognew(@lfs_heater1,@synctime2) + 1 ' Start a Cog with our assembly routine, no stack
pst.Str(String("Cog Value2: "))
pst.Dec( routine1_cog)
pst.Str(String(" ",pst#NL))
' is required since PASM requires we explicitly
' assign and use memory locations within the Cog/Hub
' main loop - repeats forever
synctime3 := 100000
routine1_cog := cognew(@lfs_heater2,@synctime3) + 1 ' Start a Cog with our assembly routine, no stack
pst.Str(String("Cog Value3: "))
pst.Dec( routine1_cog)
pst.Str(String(" ",pst#NL))
' is required since PASM requires we explicitly
' assign and use memory locations within the Cog/Hub
' main loop - repeats forever
repeat
DAT
org 0
LFS_heater
mov addr,par
rdlong _synctime1, addr
mov Time, cnt ' Prime our timer with the current value of the system counter
add Time, _synctime1 ' Add a minimum delay ( more on this below )
waitcnt Time, #20 ' Start waiting
mov dira, Both_P2_P4_P8_output ' Pin24 ' Set our Pin to an output
mov outa,Both_P2_P4_P8_low
rdlong Delay, #0
:keep_checking1
test Just_input_pin24,ina wz ' test for pin 24
if_z call #Off_Signal_Base1
if_nz call #On_Signal_Base1
'
jmp#:keep_checking1
Off_Signal_Base1
mov Time, cnt ' Prime our timer with the current value of the system counter
add Time, Period200us ' Add a minimum delay ( more on this below )
waitcnt Time, #14 ' Start waiting
xor outa, Pin2
waitcnt Time,#12
xor outa, Pin2
waitcnt Time,#24
xor outa, Pin2
waitcnt Time,#24
xor outa, Pin2
waitcnt Time,#49
xor outa, Pin2
waitcnt Time, #49
xor outa, Pin2
waitcnt Time, #24
xor outa, Pin2
waitcnt Time, #24
xor outa, Pin2
Off_Signal_Base1_ret ret
On_Signal_Base1
mov Time, cnt ' Prime our timer with the current value of the system counter
add Time, Period200us ' Add a minimum delay ( more on this below )
waitcnt Time, #10 ' Start waiting
xor outa, Pin2
waitcnt Time,#40
xor outa, Pin2
waitcnt Time,#75
xor outa, Pin2
waitcnt Time,#50
xor outa, Pin2
waitcnt Time,#25
xor outa, Pin2
waitcnt Time,#25
xor outa, Pin2
On_Signal_Base1_ret ret
org 0
LFS_heater1
mov addr,par
rdlong _synctime2, addr
mov Time, cnt ' Prime our timer with the current value of the system counter
add Time, _synctime2 ' Add a minimum delay ( more on this below )
waitcnt Time, #20 ' Start waiting
or dira,#%1
rdlong Delay, #0
:loop1 xor outa, #%1
nop
nop
nop
jmp#:loop1
org 0
LFS_heater2
mov addr,par
rdlong _synctime3, addr
mov Time, cnt ' Prime our timer with the current value of the system counter
add Time, _synctime3 ' Add a minimum delay ( more on this below )
waitcnt Time, #20 ' Start waiting
or dira, Both_P4_output' Pin24 ' Set our Pin to an output
or outa,Both_P4_low
rdlong Delay, #0
:keep_checking2
test Just_input_pin26, ina wz 'test for pin 26
if_z call #Off_Signal_Hopper2
if_nz call #On_Signal_Hopper2
jmp#:keep_checking2
Off_Signal_Hopper2
mov Time, cnt ' Prime our timer with the current value of the system counter
add Time, Period200us ' Add a minimum delay ( more on this below )
waitcnt Time, #14 ' Start waiting
xor outa, Pin4
waitcnt Time,#12
xor outa, Pin4
waitcnt Time,#24
xor outa, Pin4
waitcnt Time,#24
xor outa, Pin4
waitcnt Time,#49
xor outa, Pin4
waitcnt Time, #49
xor outa, Pin4
waitcnt Time, #24
xor outa, Pin4
waitcnt Time, #24
xor outa, Pin4
Off_Signal_Hopper2_ret ret
On_Signal_Hopper2 mov Time, cnt ' Prime our timer with the current value of the system counter
add Time, Period200us ' Add a minimum delay ( more on this below )
waitcnt Time, #10 ' Start waiting
xor outa, Pin4
waitcnt Time,#40
xor outa, Pin4
waitcnt Time,#75
xor outa, Pin4
waitcnt Time,#50
xor outa, Pin4
waitcnt Time,#25
xor outa, Pin4
waitcnt Time,#25
xor outa, Pin4
On_Signal_Hopper2_ret ret
Pin2 long |< 2 ' Encde PIN to a bit mask
Pin4 long |< 4 ' Encde PIN to a bit mask
Pin3 long |< 3 ' Encde PIN to a bit mask
Period200us long 20000 ' 200 us
Input_2_4_Mask long %00000000_0001_0100
Just_input_pin24 long %00000001_00000000_00000000_00000000
Just_input_pin26 long %00000100_00000000_00000000_00000000
Both_P2_P4_P8_output long %00000000_00000000_00000001_00010100
Both_P2_P4_P8_low long %00000000_00000000_00000000_00000000
Both_P2_output long %00000000_00000000_00000001_00000100
Both_P2_low long %00000000_00000000_00000000_00000000
Both_P4_output long %00000000_00000000_00000000_00010000
Both_P4_low long %00000000_00000000_00000000_00000000
temp1 long 0
Delay res 1
Time res 1
_synctime1 res 1
_synctime2 res 1
_synctime3 res 1
addr res 1

Comments
You should group your variables with the cog code that accesses them. Variables such as addr, Time and Delay should have unique names for each cog so they don't conflict with each other. As an example, use addr, addr1 and addr2 for your three cogs.
"fit" is entirely optional. It generates a compiler error if the current cog address before the fit exceeds the fit value. It's so you get compiler errors and not mysterious runtime errors when you try using more cogram than there is.
"res" is like long, but it doesn't take up any hubram, only cogram, to save hubram. When the compiler finds one, it increments its idea of the current cogram address, but not its idea of the current hubram address. As a result, they could contain anything when loaded. Because of how they work, they generally need to go after everything else in a cog. You can, however, put code that will be loaded into a different cog immediately after a "res".