My Big Program
krazyideas
Posts: 119
Hello
Ok well I have been working on this program for a couple of months. This is the first program that I have ever done in my life, which is why I want to hear what any of you guys that know way more and have way more experience then I have to say.
The Goal is to run a electric motor that my dad and I are trying to build.
The max RPM is 4000 but we will be running it at 2000RPM only (if it works)
We have six electro coils that we need to turn on and off and precise times ( degrees in rotation).
We have one mark that we measure, it is a one degree mark which gives us the speed of the·motor and a referance to start from.
And this is what I came up with
And a couple questions, Do I have to use locks if I am useing all 8 cogs that read and write the same variable?? and do all 8 cogs share varubles??
It's a long program and THANKS for any thoughts
CON
······· _clkmode······· = xtal1 + pll16x
······· _xinfreq······· = 5_000_000
OBJ
······· term··· : "tv_terminal"
······· kb····· : "keyboard"
······· text··· : "vga_text"
VAR
··· long fire1········ {how long to wait before turning #1 on}
··· long fire2········ {how long to wait before turning #2 on}
··· long fire3········ {how long to wait before turning #3 on}
··· long fire4········ {how long to wait before turning #4 on}
··· long fire5········ {how long to wait before turning #5 on}
··· long fire6········ {how long to wait before turning #6 on}
···
··· long win1········· {how long #1 is on}
··· long win2········· {how long #2 is on}
··· long win3········· {how long #3 is on}
··· long win4········· {how long #4 is on}
··· long win5········· {how long #5 is on}
··· long win6········· {how long #6 is on}
···
··· long RPM·········· {Rotations Per Minute}
··· long RPM1········· {RPM beging cnt value}
··· long RPM2········· {RPM endind cnt value}
···
··· long degrees······ {maintain degree when switching loops}
···
··· long RPMS· [noparse][[/noparse]20]··· {Stack space for RPM gage}
··· long read· [noparse][[/noparse]20]··· {Stack space for Reader}
··· long f1··· [noparse][[/noparse]20]··· {Stack space for Ffire1}
··· long f2··· [noparse][[/noparse]20]··· {Stack space for Ffire2}
··· long f3··· [noparse][[/noparse]20]··· {Stack space for Ffire3}
··· long f4··· [noparse][[/noparse]20]··· {Stack space for Ffire4}
··· long f5··· [noparse][[/noparse]20]··· {Stack space for Ffire5}
··· long f6··· [noparse][[/noparse]20]··· {Stack space for Ffire6}
PUB Windows·················································· {cog #0}
··· cognew(AssemblyReader, @read)······· {Staring all cogs}
··· cognew(Ffire1, @f1)
··· cognew(Ffire2, @f2)
··· cognew(Ffire3, @f3)
··· cognew(Ffire4, @f4)
··· cognew(Ffire5, @f5)
··· cognew(Ffire6, @f6)
···
··· term.start(12)····································· {Start TV and Keyboard and vga text montior}
··· term.str(string("START FIREING WINDOWS",13))
··· kb.start(26,27)
···
··· waitcnt (cnt + (clkfreq * 3))······················ {gives you time to spin the motor by hand}
···
··· fire1 := degree '* ?······························· {Starting Positions of turn on's}
··· fire2 := degree '* ?
··· fire3 := degree '* ?
··· fire4 := degree '* ? we have not worked thes out yet·'*?
··· fire5 := degree '* ?
··· fire6 := degree '* ?
···
··· win1 := degree '* ?································ {Starting Leangth's of on time}
··· win2 := degree '* ?
··· win3 := degree '* ?
··· win4 := degree '* ?
··· win5 := degree '* ?
··· win6 := degree '* ?
····· repeat until kb.newkey == "l"···················· {Start up loop}·················
·······
······· on1· := (degree * fire1)
······· off1 := (degree * win1)
······· end1 := (degree * (360 - (fire1 + win1)))
·······
······· on2· := (degree * fire2)
······· off2 := (degree * win2)
······· end2 := (degree * (360 - (fire2 + win2)))
·······
······· on3· := (degree * fire3)
······· off3 := (degree * win3)
······· end3 := (degree * (360 - (fire3 + win3)))
·······
······· on4· := (degree * fire4)
······· off4 := (degree * win4)
······· end4 := (degree * (360 - (fire4 + win4)))
·······
······· on5· := (degree * fire5)
······· off5 := (degree * win5)
······· end5 := (degree * (360 - (fire5 + win5)))
·······
······· on6· := (degree * fire6)
······· off6 := (degree * win6)
······· end6 := (degree * (360 - (fire6 + win6)))
·······
······· degrees := degree
·······
······· if begin == 21
·········· dira := %00000000000000000000000010000000 and outa := %00000000000000000000000010000000
··········
··· coginit (ReaderCog, RPMGage, @RPMS)················· {Start RPM gague in another cog}
··· repeat·············································· {Keyboard Controls for adjusting motor while running}
···
····· if kb.newkey···· == "q"
········· fire1 := fire1 + 1· and on1 := (degrees * fire1) and end1 := (degrees * (360 - (fire1 + win1)))
····· elseif kb.newkey == "Q"
········· fire1 := fire1 - 1· and on1 := (degrees * fire1) and end1 := (degrees * (360 - (fire1 + win1)))
····· elseif kb.newkey == "w"
········· fire2 := fire2 + 1· and on2 := (degrees * fire2) and end2 := (degrees * (360 - (fire2 + win2)))
····· elseif kb.newkey == "W"
········· fire2 := fire2 - 1· and on2 := (degrees * fire2) and end2 := (degrees * (360 - (fire2 + win2)))
······elseif kb.newkey == "e"
········· fire3 := fire3 + 1· and on3 := (degrees * fire3) and end3 := (degrees * (360 - (fire3 + win3)))
····· elseif kb.newkey == "E"
········· fire3 := fire3 - 1· and on3 := (degrees * fire3) and end3 := (degrees * (360 - (fire3 + win3)))
····· elseif kb.newkey == "r"
········· fire4 := fire4 + 1· and on4 := (degrees * fire4) and end4 := (degrees * (360 - (fire4 + win4)))
····· elseif kb.newkey == "R"
········· fire4 := fire4 - 1· and on4 := (degrees * fire4) and end4 := (degrees * (360 - (fire4 + win4)))
····· elseif kb.newkey == "t"
········· fire5 := fire5 + 1· and on5 := (degrees * fire5) and end5 := (degrees * (360 - (fire5 + win5)))
····· elseif kb.newkey == "T"
········· fire5 := fire5 - 1· and on5 := (degrees * fire5) and end5 := (degrees * (360 - (fire5 + win5)))
····· elseif kb.newkey == "y"
········· fire6 := fire6 + 1· and on6 := (degrees * fire6) and end6 := (degrees * (360 - (fire6 + win6)))
····· elseif kb.newkey == "Y"
········· fire6 := fire6 - 1· and on6 := (degrees * fire6) and end6 := (degrees * (360 - (fire6 + win6)))
····· if kb.newkey···· == "z"
········· win1 := win1 + 1 and off1 := (degrees * win1) and end1 := (degrees * (360 - (fire1 + win1)))··
····· elseif kb.newkey == "Z"
········· win1 := win1 - 1 and off1 := (degrees * win1) and end1 := (degrees * (360 - (fire1 + win1)))
····· elseif kb.newkey == "x"
········· win2 := win2 + 1 and off2 := (degrees * win2) and end2 := (degrees * (360 - (fire2 + win2)))
····· elseif kb.newkey == "X"
········· win2 := win2 - 1 and off2 := (degrees * win2) and end2 := (degrees * (360 - (fire2 + win2)))
······elseif kb.newkey == "c"
········· win3 := win3 + 1 and off3 := (degrees * win3) and end3 := (degrees * (360 - (fire3 + win3)))
····· elseif kb.newkey == "C"
········· win3 := win3 - 1 and off3 := (degrees * win3) and end3 := (degrees * (360 - (fire3 + win3)))
····· elseif kb.newkey == "v"
········· win4 := win4 + 1 and off4 := (degrees * win4) and end4 := (degrees * (360 - (fire4 + win4)))
····· elseif kb.newkey == "V"
········· win4 := win4 - 1 and off4 := (degrees * win4) and end4 := (degrees * (360 - (fire4 + win4)))
····· elseif kb.newkey == "b"
········· win5 := win5 + 1 and off5 := (degrees * win5) and end5 := (degrees * (360 - (fire5 + win5)))
····· elseif kb.newkey == "B"
········· win5 := win5 - 1 and off5 := (degrees * win5) and end5 := (degrees * (360 - (fire5 + win5)))
····· elseif kb.newkey == "n"
········· win6 := win6 + 1 and off6 := (degrees * win6) and end6 := (degrees * (360 - (fire6 + win6)))
····· elseif kb.newkey == "N"
········· win6 := win6 - 1 and off6 := (degrees * win6) and end6 := (degrees * (360 - (fire6 + win6)))·······················
···
·····
····· term.dec (fire1)······························· {Displying Results on TV for tracking firing positions}
····· term.str(string("·· "))
····· term.dec (fire2)
····· term.str(string("·· "))
····· term.dec (fire3)
····· term.str(string("·· "))
····· term.dec (fire4)
····· term.str(string("·· "))
····· term.dec (fire5)
····· term.str(string("·· "))
····· term.dec (fire6)
····· term.str(string(" ",13))
····· term.str(string(" ",13))
····· term.dec (win1)
····· term.str(string("·· "))
····· term.dec (win2)
····· term.str(string("·· "))
····· term.dec (win3)
····· term.str(string("·· "))
····· term.dec (win4)
····· term.str(string("·· "))
····· term.dec (win5)
····· term.str(string("·· "))
····· term.dec (win6)
····· term.str(string(" ",13))
····· term.str(string(" ",13))
····· term.str(string(" ",13))
····· term.str(string(" ",13))
····· term.str(string(" ",13))
PUB RPMGage··············································· {RPM Gage}
text.start(16)
repeat
· waitpeq (%1000000, |< 0, 0)
· RPM1 := cnt
· waitpne (%1000000, |< 0, 0)
· RPM2 := cnt
· RPM := ((((RPM2 - RPM1) * 360) / clkfreq) * 60)
· text.str (string("RPM· "))
· text.dec (RPM)
Dat
AssemblyReader········· cogid ReaderCog····················· {Cog to stop when "l" is pressed and start RPM gage}
······························
······························ movs CTRA, %0······················ {Monitor pin 0}
······························ movi CTRA, %011010000···········{Set CTRa mode to logic A and PLLa to times 16}
······························
······························ mov begin, 0························ · {Set begin to 0}
:CountA····················mov PHSA, 0························ · {Resets PHSA to 0}
······························
····························· waitpeq 1, |< 0······················ ·{Wait till pin 0 is High}
····························· add begin, 1···························· {add 1 to begin each loop}
···························· ·mov measure1, PHSA················· {Store PHSA in measure1}
····························
····························· waitpne 1, |< 0························ {Wait till pin 0 in not High}
···························· ·NOP
····························· mov measure2, PHSA················· {Store PHSA in measure2}
·······················
····························· sub measure2, measure1············· {Subtract measure1 from measure2 to get clock's passed between}
···························· ·mov degree, measure2··············· {Puts # of clock tick's in degree}
·····························
····························· JMP #:CountA·························· {loop endlessly}
ReaderCog······· word
measure1········ long
measure2········ long
degree········· ·· long
begin············ ·long
DAT
Ffire1························· mov Dira, %00000000000000000000000000000010······· {Set output pin}
·······························
································ waitpeq 1, |< 7··································· {Wait to start}
······························· ·mov time1, cnt···································· {Set base time}
································ sub time1, 8
·······························
:FireingLoop1···············waitcnt time1, on1
······························· mov outa, %00000000000000000000000000000010······· {Pin 1 high}
·······························
······························· waitcnt time1, off1
······························· mov outa, %00000000000000000000000000000000······· {Pin 1 low}
······························· waitcnt time1, end1······························· {Wait time to return to begining of cycle}
··················································································
······························· JMP #:FireingLoop1································ {Loop endlessly}
on1···· long
off1··· long
end1··· long
time1·· long
DAT
Ffire2························· mov Dira, %00000000000000000000000000000100
·······························
······························· waitpeq 1, |< 7
······························· mov time2, cnt
······························· sub time2, 8
·······························
:FireingLoop2··············waitcnt time2, on2
······························· mov outa, %00000000000000000000000000000100
·······························
······························· waitcnt time2, off2
······························· mov outa, %00000000000000000000000000000000
······························· waitcnt time2, end2
·······························
······························· JMP #:FireingLoop2
on2···· long
off2··· long
end2··· long
time2·· long
DAT
Ffire3························· mov Dira, %00000000000000000000000000001000
·······························
······························· waitpeq 1, |< 7
······························· mov time3, cnt
······························· sub time3, 8
·······························
:FireingLoop3···············waitcnt time3, on3
······························· mov outa, %00000000000000000000000000001000
·······························
······························· waitcnt time3, off3
······························· mov outa, %00000000000000000000000000000000
······························· waitcnt time3, end3
·······························
······························· JMP #:FireingLoop3
on3···· long
off3··· long
end3··· long
time3·· long
DAT
Ffire4························· mov Dira, %00000000000000000000000000010000
······························· waitpeq 1, |< 7
······························· mov time4, cnt
······························· sub time4, 8
·······························
:FireingLoop4···············waitcnt time4, on4
······························· mov outa, %00000000000000000000000000010000
·······························
······························· waitcnt time4, off4
······························· mov outa, %00000000000000000000000000000000
······························· waitcnt time4, end4
·······························
······························· JMP #:FireingLoop4
on4···· long
off4··· long
end4··· long
time4·· long
DAT
Ffire5························· mov Dira, %00000000000000000000000000100000
······························· waitpeq 1, |< 7
······························· mov time5, cnt
······························· sub time5, 8
·······························
:FireingLoop5···············waitcnt time5, on5
······························· mov outa, %00000000000000000000000000100000
·······························
······························· waitcnt time5, off5
······························· mov outa, %00000000000000000000000000000000
······························· waitcnt time5, end5
·······························
······························· JMP #:FireingLoop5
on5···· long
off5··· long
end5··· long
time5·· long
DAT
Ffire6························· mov Dira, %00000000000000000000000001000000
······························· waitpeq 1, |< 7
······························· mov time6, cnt
······························· sub time6, 8
·······························
:FireingLoop6···············waitcnt time6, on6
······························· mov outa, %00000000000000000000000001000000
·······························
······························· waitcnt time6, off6
······························· mov outa, %00000000000000000000000000000000
······························· waitcnt time6, end6
·······························
······························· JMP #:FireingLoop6·······························································································································
on6···· long
off6··· long
end6··· long
time6·· long
Ok well I have been working on this program for a couple of months. This is the first program that I have ever done in my life, which is why I want to hear what any of you guys that know way more and have way more experience then I have to say.
The Goal is to run a electric motor that my dad and I are trying to build.
The max RPM is 4000 but we will be running it at 2000RPM only (if it works)
We have six electro coils that we need to turn on and off and precise times ( degrees in rotation).
We have one mark that we measure, it is a one degree mark which gives us the speed of the·motor and a referance to start from.
And this is what I came up with
And a couple questions, Do I have to use locks if I am useing all 8 cogs that read and write the same variable?? and do all 8 cogs share varubles??
It's a long program and THANKS for any thoughts
CON
······· _clkmode······· = xtal1 + pll16x
······· _xinfreq······· = 5_000_000
OBJ
······· term··· : "tv_terminal"
······· kb····· : "keyboard"
······· text··· : "vga_text"
VAR
··· long fire1········ {how long to wait before turning #1 on}
··· long fire2········ {how long to wait before turning #2 on}
··· long fire3········ {how long to wait before turning #3 on}
··· long fire4········ {how long to wait before turning #4 on}
··· long fire5········ {how long to wait before turning #5 on}
··· long fire6········ {how long to wait before turning #6 on}
···
··· long win1········· {how long #1 is on}
··· long win2········· {how long #2 is on}
··· long win3········· {how long #3 is on}
··· long win4········· {how long #4 is on}
··· long win5········· {how long #5 is on}
··· long win6········· {how long #6 is on}
···
··· long RPM·········· {Rotations Per Minute}
··· long RPM1········· {RPM beging cnt value}
··· long RPM2········· {RPM endind cnt value}
···
··· long degrees······ {maintain degree when switching loops}
···
··· long RPMS· [noparse][[/noparse]20]··· {Stack space for RPM gage}
··· long read· [noparse][[/noparse]20]··· {Stack space for Reader}
··· long f1··· [noparse][[/noparse]20]··· {Stack space for Ffire1}
··· long f2··· [noparse][[/noparse]20]··· {Stack space for Ffire2}
··· long f3··· [noparse][[/noparse]20]··· {Stack space for Ffire3}
··· long f4··· [noparse][[/noparse]20]··· {Stack space for Ffire4}
··· long f5··· [noparse][[/noparse]20]··· {Stack space for Ffire5}
··· long f6··· [noparse][[/noparse]20]··· {Stack space for Ffire6}
PUB Windows·················································· {cog #0}
··· cognew(AssemblyReader, @read)······· {Staring all cogs}
··· cognew(Ffire1, @f1)
··· cognew(Ffire2, @f2)
··· cognew(Ffire3, @f3)
··· cognew(Ffire4, @f4)
··· cognew(Ffire5, @f5)
··· cognew(Ffire6, @f6)
···
··· term.start(12)····································· {Start TV and Keyboard and vga text montior}
··· term.str(string("START FIREING WINDOWS",13))
··· kb.start(26,27)
···
··· waitcnt (cnt + (clkfreq * 3))······················ {gives you time to spin the motor by hand}
···
··· fire1 := degree '* ?······························· {Starting Positions of turn on's}
··· fire2 := degree '* ?
··· fire3 := degree '* ?
··· fire4 := degree '* ? we have not worked thes out yet·'*?
··· fire5 := degree '* ?
··· fire6 := degree '* ?
···
··· win1 := degree '* ?································ {Starting Leangth's of on time}
··· win2 := degree '* ?
··· win3 := degree '* ?
··· win4 := degree '* ?
··· win5 := degree '* ?
··· win6 := degree '* ?
····· repeat until kb.newkey == "l"···················· {Start up loop}·················
·······
······· on1· := (degree * fire1)
······· off1 := (degree * win1)
······· end1 := (degree * (360 - (fire1 + win1)))
·······
······· on2· := (degree * fire2)
······· off2 := (degree * win2)
······· end2 := (degree * (360 - (fire2 + win2)))
·······
······· on3· := (degree * fire3)
······· off3 := (degree * win3)
······· end3 := (degree * (360 - (fire3 + win3)))
·······
······· on4· := (degree * fire4)
······· off4 := (degree * win4)
······· end4 := (degree * (360 - (fire4 + win4)))
·······
······· on5· := (degree * fire5)
······· off5 := (degree * win5)
······· end5 := (degree * (360 - (fire5 + win5)))
·······
······· on6· := (degree * fire6)
······· off6 := (degree * win6)
······· end6 := (degree * (360 - (fire6 + win6)))
·······
······· degrees := degree
·······
······· if begin == 21
·········· dira := %00000000000000000000000010000000 and outa := %00000000000000000000000010000000
··········
··· coginit (ReaderCog, RPMGage, @RPMS)················· {Start RPM gague in another cog}
··· repeat·············································· {Keyboard Controls for adjusting motor while running}
···
····· if kb.newkey···· == "q"
········· fire1 := fire1 + 1· and on1 := (degrees * fire1) and end1 := (degrees * (360 - (fire1 + win1)))
····· elseif kb.newkey == "Q"
········· fire1 := fire1 - 1· and on1 := (degrees * fire1) and end1 := (degrees * (360 - (fire1 + win1)))
····· elseif kb.newkey == "w"
········· fire2 := fire2 + 1· and on2 := (degrees * fire2) and end2 := (degrees * (360 - (fire2 + win2)))
····· elseif kb.newkey == "W"
········· fire2 := fire2 - 1· and on2 := (degrees * fire2) and end2 := (degrees * (360 - (fire2 + win2)))
······elseif kb.newkey == "e"
········· fire3 := fire3 + 1· and on3 := (degrees * fire3) and end3 := (degrees * (360 - (fire3 + win3)))
····· elseif kb.newkey == "E"
········· fire3 := fire3 - 1· and on3 := (degrees * fire3) and end3 := (degrees * (360 - (fire3 + win3)))
····· elseif kb.newkey == "r"
········· fire4 := fire4 + 1· and on4 := (degrees * fire4) and end4 := (degrees * (360 - (fire4 + win4)))
····· elseif kb.newkey == "R"
········· fire4 := fire4 - 1· and on4 := (degrees * fire4) and end4 := (degrees * (360 - (fire4 + win4)))
····· elseif kb.newkey == "t"
········· fire5 := fire5 + 1· and on5 := (degrees * fire5) and end5 := (degrees * (360 - (fire5 + win5)))
····· elseif kb.newkey == "T"
········· fire5 := fire5 - 1· and on5 := (degrees * fire5) and end5 := (degrees * (360 - (fire5 + win5)))
····· elseif kb.newkey == "y"
········· fire6 := fire6 + 1· and on6 := (degrees * fire6) and end6 := (degrees * (360 - (fire6 + win6)))
····· elseif kb.newkey == "Y"
········· fire6 := fire6 - 1· and on6 := (degrees * fire6) and end6 := (degrees * (360 - (fire6 + win6)))
····· if kb.newkey···· == "z"
········· win1 := win1 + 1 and off1 := (degrees * win1) and end1 := (degrees * (360 - (fire1 + win1)))··
····· elseif kb.newkey == "Z"
········· win1 := win1 - 1 and off1 := (degrees * win1) and end1 := (degrees * (360 - (fire1 + win1)))
····· elseif kb.newkey == "x"
········· win2 := win2 + 1 and off2 := (degrees * win2) and end2 := (degrees * (360 - (fire2 + win2)))
····· elseif kb.newkey == "X"
········· win2 := win2 - 1 and off2 := (degrees * win2) and end2 := (degrees * (360 - (fire2 + win2)))
······elseif kb.newkey == "c"
········· win3 := win3 + 1 and off3 := (degrees * win3) and end3 := (degrees * (360 - (fire3 + win3)))
····· elseif kb.newkey == "C"
········· win3 := win3 - 1 and off3 := (degrees * win3) and end3 := (degrees * (360 - (fire3 + win3)))
····· elseif kb.newkey == "v"
········· win4 := win4 + 1 and off4 := (degrees * win4) and end4 := (degrees * (360 - (fire4 + win4)))
····· elseif kb.newkey == "V"
········· win4 := win4 - 1 and off4 := (degrees * win4) and end4 := (degrees * (360 - (fire4 + win4)))
····· elseif kb.newkey == "b"
········· win5 := win5 + 1 and off5 := (degrees * win5) and end5 := (degrees * (360 - (fire5 + win5)))
····· elseif kb.newkey == "B"
········· win5 := win5 - 1 and off5 := (degrees * win5) and end5 := (degrees * (360 - (fire5 + win5)))
····· elseif kb.newkey == "n"
········· win6 := win6 + 1 and off6 := (degrees * win6) and end6 := (degrees * (360 - (fire6 + win6)))
····· elseif kb.newkey == "N"
········· win6 := win6 - 1 and off6 := (degrees * win6) and end6 := (degrees * (360 - (fire6 + win6)))·······················
···
·····
····· term.dec (fire1)······························· {Displying Results on TV for tracking firing positions}
····· term.str(string("·· "))
····· term.dec (fire2)
····· term.str(string("·· "))
····· term.dec (fire3)
····· term.str(string("·· "))
····· term.dec (fire4)
····· term.str(string("·· "))
····· term.dec (fire5)
····· term.str(string("·· "))
····· term.dec (fire6)
····· term.str(string(" ",13))
····· term.str(string(" ",13))
····· term.dec (win1)
····· term.str(string("·· "))
····· term.dec (win2)
····· term.str(string("·· "))
····· term.dec (win3)
····· term.str(string("·· "))
····· term.dec (win4)
····· term.str(string("·· "))
····· term.dec (win5)
····· term.str(string("·· "))
····· term.dec (win6)
····· term.str(string(" ",13))
····· term.str(string(" ",13))
····· term.str(string(" ",13))
····· term.str(string(" ",13))
····· term.str(string(" ",13))
PUB RPMGage··············································· {RPM Gage}
text.start(16)
repeat
· waitpeq (%1000000, |< 0, 0)
· RPM1 := cnt
· waitpne (%1000000, |< 0, 0)
· RPM2 := cnt
· RPM := ((((RPM2 - RPM1) * 360) / clkfreq) * 60)
· text.str (string("RPM· "))
· text.dec (RPM)
Dat
AssemblyReader········· cogid ReaderCog····················· {Cog to stop when "l" is pressed and start RPM gage}
······························
······························ movs CTRA, %0······················ {Monitor pin 0}
······························ movi CTRA, %011010000···········{Set CTRa mode to logic A and PLLa to times 16}
······························
······························ mov begin, 0························ · {Set begin to 0}
:CountA····················mov PHSA, 0························ · {Resets PHSA to 0}
······························
····························· waitpeq 1, |< 0······················ ·{Wait till pin 0 is High}
····························· add begin, 1···························· {add 1 to begin each loop}
···························· ·mov measure1, PHSA················· {Store PHSA in measure1}
····························
····························· waitpne 1, |< 0························ {Wait till pin 0 in not High}
···························· ·NOP
····························· mov measure2, PHSA················· {Store PHSA in measure2}
·······················
····························· sub measure2, measure1············· {Subtract measure1 from measure2 to get clock's passed between}
···························· ·mov degree, measure2··············· {Puts # of clock tick's in degree}
·····························
····························· JMP #:CountA·························· {loop endlessly}
ReaderCog······· word
measure1········ long
measure2········ long
degree········· ·· long
begin············ ·long
DAT
Ffire1························· mov Dira, %00000000000000000000000000000010······· {Set output pin}
·······························
································ waitpeq 1, |< 7··································· {Wait to start}
······························· ·mov time1, cnt···································· {Set base time}
································ sub time1, 8
·······························
:FireingLoop1···············waitcnt time1, on1
······························· mov outa, %00000000000000000000000000000010······· {Pin 1 high}
·······························
······························· waitcnt time1, off1
······························· mov outa, %00000000000000000000000000000000······· {Pin 1 low}
······························· waitcnt time1, end1······························· {Wait time to return to begining of cycle}
··················································································
······························· JMP #:FireingLoop1································ {Loop endlessly}
on1···· long
off1··· long
end1··· long
time1·· long
DAT
Ffire2························· mov Dira, %00000000000000000000000000000100
·······························
······························· waitpeq 1, |< 7
······························· mov time2, cnt
······························· sub time2, 8
·······························
:FireingLoop2··············waitcnt time2, on2
······························· mov outa, %00000000000000000000000000000100
·······························
······························· waitcnt time2, off2
······························· mov outa, %00000000000000000000000000000000
······························· waitcnt time2, end2
·······························
······························· JMP #:FireingLoop2
on2···· long
off2··· long
end2··· long
time2·· long
DAT
Ffire3························· mov Dira, %00000000000000000000000000001000
·······························
······························· waitpeq 1, |< 7
······························· mov time3, cnt
······························· sub time3, 8
·······························
:FireingLoop3···············waitcnt time3, on3
······························· mov outa, %00000000000000000000000000001000
·······························
······························· waitcnt time3, off3
······························· mov outa, %00000000000000000000000000000000
······························· waitcnt time3, end3
·······························
······························· JMP #:FireingLoop3
on3···· long
off3··· long
end3··· long
time3·· long
DAT
Ffire4························· mov Dira, %00000000000000000000000000010000
······························· waitpeq 1, |< 7
······························· mov time4, cnt
······························· sub time4, 8
·······························
:FireingLoop4···············waitcnt time4, on4
······························· mov outa, %00000000000000000000000000010000
·······························
······························· waitcnt time4, off4
······························· mov outa, %00000000000000000000000000000000
······························· waitcnt time4, end4
·······························
······························· JMP #:FireingLoop4
on4···· long
off4··· long
end4··· long
time4·· long
DAT
Ffire5························· mov Dira, %00000000000000000000000000100000
······························· waitpeq 1, |< 7
······························· mov time5, cnt
······························· sub time5, 8
·······························
:FireingLoop5···············waitcnt time5, on5
······························· mov outa, %00000000000000000000000000100000
·······························
······························· waitcnt time5, off5
······························· mov outa, %00000000000000000000000000000000
······························· waitcnt time5, end5
·······························
······························· JMP #:FireingLoop5
on5···· long
off5··· long
end5··· long
time5·· long
DAT
Ffire6························· mov Dira, %00000000000000000000000001000000
······························· waitpeq 1, |< 7
······························· mov time6, cnt
······························· sub time6, 8
·······························
:FireingLoop6···············waitcnt time6, on6
······························· mov outa, %00000000000000000000000001000000
·······························
······························· waitcnt time6, off6
······························· mov outa, %00000000000000000000000000000000
······························· waitcnt time6, end6
·······························
······························· JMP #:FireingLoop6·······························································································································
on6···· long
off6··· long
end6··· long
time6·· long
Comments
I took a very quick look at your program. Here are a few comments.
1. You have to initialize "tv_terminal", "keyboard", etc.
2. "tv_terminal" calls "TV" and "Graphics". By the time these are called, it has used up three cogs.
3. Your program tries to start seven additional cogs. There aren't enough cogs left to do this.
There are a number of other issues, but you need to solve these first. If you need help with initializing "tv_terminal" etc., let me know and I'll point you to an example.
Good luck,
Jim
Good first start.
This is not a comment about your program per se but about your approach to programming. You mention that it's your first program; and it is, indeed, a long one. In my early programming days, I programmed like that, too: write the whole thing, then debug it. But I soon learned that I had quicker success — and much more fun! — if I wrote little pieces at a time and got each one working before proceeding to the next one. I recommend that you do the same. You'll have a much more satisfying experience.
And, by the way, yes, you do need to use locks when common variables are being written by more than one cog.
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Just a few PropSTICK Kit bare PCBs left!
Though I think I might have thought of an easyer shorter and more accuerate way of writeing my program.
I'll see what you guys think when I get it more or less done.
Thanks so much
krazyideas