Problem writeing Numbers and pins in Assembly
krazyideas
Posts: 119
Hello
I don't know how to write this quite right.· I don't know how to write the 32 bit binary numbers in 9 bits of space for assmebly code.
I need to know how to write dira,·· and outa high low on desginated pins
This is what I have.
Thanks for any help
Dat
ReadFireTime1·········· COGID one
······················· mov dira, 12···················PROBLEM·· ·'Set output pin······················
······················· movi CTRA, %11111
:Relay1················ waitpeq 1, |< 9············PROBLEM·· ·'Set 0 mark on pin 10
······················· mov PHSA, 0···················· ············· 'Mark 0
······················· waitpeq 1, |< 0···············PROBLEM · ·'Window starts
······················· mov outa, [noparse][[/noparse]12]~~···········PROBLEM · ·'Relay pluse···
······················· mov WinStart1, PHSA········ ············· 'Mark counts to turn on···
······················· mov TurnOn1, WinStart1···· ············· 'Store counts to turn on in turnon
······················· waitpne 1, |< 0···············PROBLEM ·· 'Window ends
······················· mov outa [noparse][[/noparse]12]~···············PROBLEM· · 'Relay pluse···
······················· mov WinEnd1, PHSA························· 'Mark turn off····
······················· sub WinEnd1, WinStart1··················· 'Leangth of window
······················· mov TurnOff1, WinEnd1···················· 'Store Window Leangth
······················· jmp #:Relay1·································· 'Loop endlessly
·······················
WinStart····· Long··· 'Mark
WinEnd······· Long··· 'Mark
TurnOn1······ Long··· '# of cnt's to wait before turn on
TurnOff1····· Long··· '# of cnt's to Stay on before turn off
one·········· word
Dat
ExicuteFireTime1······· mov dira [noparse][[/noparse]12]~~·········PROBLEM·········· 'Set output pin
:FireingLoop1·········· WAITPEQ 1, |< 9··········PROBLEM
······················· mov syncdelay1, cnt······························· 'Set Zero
······················· add syncdealy1, TurnOn1························· 'Set wait till turn on
······················· waitcnt syncdelay1, TurnOff1··················· 'When cnt = syncdelay output High
······················· mov outa [noparse][[/noparse]12]~~················ PROBLEM
······················· waitcnt syncdelay1, DeadZ······················· 'When cnt = syncdelay output Low
······················· mov outa [noparse][[/noparse]12]~···················PROBLEM
······················· jmp #:FireingLoop1·································· 'Loop endlessly
syncdelay1···· Long
Post Edited (krazyideas) : 12/7/2008 12:17:24 AM GMT
I don't know how to write this quite right.· I don't know how to write the 32 bit binary numbers in 9 bits of space for assmebly code.
I need to know how to write dira,·· and outa high low on desginated pins
This is what I have.
Thanks for any help
Dat
ReadFireTime1·········· COGID one
······················· mov dira, 12···················PROBLEM·· ·'Set output pin······················
······················· movi CTRA, %11111
:Relay1················ waitpeq 1, |< 9············PROBLEM·· ·'Set 0 mark on pin 10
······················· mov PHSA, 0···················· ············· 'Mark 0
······················· waitpeq 1, |< 0···············PROBLEM · ·'Window starts
······················· mov outa, [noparse][[/noparse]12]~~···········PROBLEM · ·'Relay pluse···
······················· mov WinStart1, PHSA········ ············· 'Mark counts to turn on···
······················· mov TurnOn1, WinStart1···· ············· 'Store counts to turn on in turnon
······················· waitpne 1, |< 0···············PROBLEM ·· 'Window ends
······················· mov outa [noparse][[/noparse]12]~···············PROBLEM· · 'Relay pluse···
······················· mov WinEnd1, PHSA························· 'Mark turn off····
······················· sub WinEnd1, WinStart1··················· 'Leangth of window
······················· mov TurnOff1, WinEnd1···················· 'Store Window Leangth
······················· jmp #:Relay1·································· 'Loop endlessly
·······················
WinStart····· Long··· 'Mark
WinEnd······· Long··· 'Mark
TurnOn1······ Long··· '# of cnt's to wait before turn on
TurnOff1····· Long··· '# of cnt's to Stay on before turn off
one·········· word
Dat
ExicuteFireTime1······· mov dira [noparse][[/noparse]12]~~·········PROBLEM·········· 'Set output pin
:FireingLoop1·········· WAITPEQ 1, |< 9··········PROBLEM
······················· mov syncdelay1, cnt······························· 'Set Zero
······················· add syncdealy1, TurnOn1························· 'Set wait till turn on
······················· waitcnt syncdelay1, TurnOff1··················· 'When cnt = syncdelay output High
······················· mov outa [noparse][[/noparse]12]~~················ PROBLEM
······················· waitcnt syncdelay1, DeadZ······················· 'When cnt = syncdelay output Low
······················· mov outa [noparse][[/noparse]12]~···················PROBLEM
······················· jmp #:FireingLoop1·································· 'Loop endlessly
syncdelay1···· Long
Post Edited (krazyideas) : 12/7/2008 12:17:24 AM GMT
Comments
Post Edited (Mike Green) : 12/7/2008 12:23:05 AM GMT
Sorry for not just attaching it my computer locks up it I try too
Thanks for any thoughts
Dat
ReadFireTime1·····COGID one
······················· or·········· dira, DirOutPutPin············· 'Set output pin······················
······················· movi······· CTRA, %11111
:Relay1··············waitpeq··· MarkerPin, MarkerPin········· 'Set 0 mark on pin 10
······················· mov········ PHSA, 0························· ·'Mark 0
······················· waitpeq··· WindowPin, WindowPin·········'Window starts
······················· or··········· outa, OutPutPin················ 'Relay pluse···
······················· mov········ WinStart1, PHSA··············· 'Mark counts to turn on···
······················· mov········ TurnOn1, WinStart1··········· 'Store counts to turn on in turnon
······················· waitpne··· WindowPin, WindowPin········'Window ends
······················· andn······· outa, OutPutPin················ 'Relay pluse···
······················· mov········ WinEnd1, PHSA················· 'Mark turn off····
······················· sub········· WinEnd1, WinStart1··········· 'Leangth of window
······················· mov········ TurnOff1, WinEnd1············· 'Store Window Leangth
······················· jmp #:Relay1···························· 'Loop endlessly
·······················
WinStart····· Long··· 'Mark
WinEnd······· Long··· 'Mark
TurnOn1······ Long··· '# of cnt's to wait before turn on
TurnOff1····· Long··· '# of cnt's to Stay on before turn off
one··········· word
DirOutPutPin· long····· |< 12
MarkerPin····· long····· |< 9
WindowPin···· long····· |< 0
OutPutPin····· long····· |< 12
Dat
ExicuteFireTime1······· or····· dira, DirOut······················ 'Set output pin
:FireingLoop1·······WAITPEQ Mark, Mark
······················· mov········ syncdelay1, cnt················· 'Set Zero
······················· add········ ·syncdealy1, TurnOn1·········· 'Set wait till turn on
······················· waitcnt···· syncdelay1, TurnOff1··········'When cnt = syncdelay output High
······················· or············ outa, OutPin
······················· waitcnt···· syncdelay1, 500··············· 'When cnt = syncdelay output Low
······················· andn········ outa, OutPin
······················· jmp #:FireingLoop1·························· 'Loop endlessly
syncdelay1··· Long
·····
DirOut······· long····· |< 12
OutPin······· long····· |< 12
Mark········· long····· |< 9
Post Edited (krazyideas) : 12/7/2008 1:09:50 AM GMT
That helped tons
"movi CTRA,%11111" needs to be "movi CTRA,#%11111".
There are several other instructions that need to have the "#" added to their source field.
"waitpeq 1,WindowPin" needs to be "waitpeq WindowPin,WindowPin".
Similarly, "waitpne 1,WindowPin" needs to be "waitpne WindowPin,WindowPin"
I think these two programs should work now. But I would like to hear what some of you guys that know what your doing have to say.
Thanks for any comments
Dat
ReadFireTime1·····COGID····· one
······················· or··········· dira, DirOutPutPin1················· 'Set output pin······················
······················· movi······· ·CTRA, #%11111
·································································
:Relay1··············waitpeq··· MarkerPin1, MarkerPin1··········· ·'Set 0 mark on pin 9
······················· mov········ PHSA, 0································ 'Mark 0
······················· waitpeq··· WindowPin1, WindowPin1········ 'Window starts
······················· or··········· outa, OutPutPin1··················· 'Relay pluse···
······················· mov········ WinStart1, PHSA··················· 'Mark counts to turn on···
······················· mov········ TurnOn1, WinStart1··············· 'Store counts to turn on in turnon
······················· waitpne··· WindowPin1, WindowPin1········ 'Window ends
······················· andn······· outa, OutPutPin1··················· 'Relay pluse···
······················· mov········ WinEnd1, PHSA····················· 'Mark turn off····
······················· sub········ ·WinEnd1, WinStart1··············· 'Leangth of window
······················· mov········ TurnOff1, WinEnd1················· 'Store Window Leangth
······················· jmp #:Relay1····································· ·'Loop endlessly
·······················
WinStart1····· long····· 5·········· 'Mark
WinEnd1······· long····· 5·········· 'Mark
TurnOn1······· long····· 5·········· '# of cnt's to wait before turn on
TurnOff1······ long····· 5··········· '# of cnt's to Stay on before turn off
one············· word····· 1·········· 'CogID
DirOutPutPin1· long····· |< 12······ 'Set out put pin
MarkerPin1···· ·long····· |< 9········ 'Zero mark pin
WindowPin1···· long····· |< 0······· 'Window mark pin
OutPutPin1····· long····· |< 12······ 'Output pin
Dat
ExicuteFireTime1······· or··········· dira, DirOut1···················· 'Set output pin
:FireingLoop1·········· WAITPEQ··· Mark1, Mark1
···························· mov········ ·syncdelay1, cnt··············· 'Set Zero
···························· add·········· syncdelay1, TurnOn1·········'Set wait till turn on
··························· waitcnt······ syncdelay1, TurnOff1········'When cnt = syncdelay output High
···························· or············ outa, OutPin1
··························· waitcnt······ syncdelay1, 500···············'When cnt = syncdelay output Low
··························· andn········· outa, OutPin1
···························· jmp········· #:FireingLoop1················· 'Loop endlessly
syncdelay1···· long····· 5·········· 'Register to control waits between commands
DirOut1······· long····· |< 12······ 'Set output pin
OutPin1······· long····· |< 12······ 'Output pin
Mark1········· long····· |< 9······· 'Zero mark pin
1) 'COGID one' gets the actual ID to the register 'one'. Why do you need that? 'one' must be defined as long. (word is not possible in the way you have done it).
2) OutPutPin1 and DirOutPutPin1 are the same PinMasks. You need it only 1 time, but use it for DIRA and OUTA.
3) CounterA is not right initialized if you only set the Counter mode. You need also to set the FRQA register:
mov CNTRA,#0
movi CNTRA,#%11111
mov FRQA,#1
But why not use the CNT register, instead of setting up a counter?
4) You store the TurnOn/Off times to Cog registers, which are readable only inside the same cog. If you want use this values in Spin or another assembly cog you need to store theme to the Hub RAM with WRLONG (and read it with RDLONG in the other cog). For that you have to pass a shared HubRAM address to both cogs (in the PAR register).
It will be easier to make this Syncdelay in the same cog as the Window counting.
Andy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
Sorry krazyideas, your code is to complicated for me. It's easier to show you a simpler approach, than go into the details of your code.
I have attached a Spin file which uses only 2 Spin cogs for doing much of what you want (+ 2 cogs for Keyboard and Display).
It's not a ready to use solution, but can give you some more ideas.
It is set up to output 6 pulses on Pins P0..P5 slow enough that you can watch the pulses on 6 connected LEDs. You can change the 6 Pins in a table in the DAT section.
Changing the values is done with Cursor keys and number key 1..6 to select which output should change. Also recording of 6 Marker pins (over 1 turn) is implemented.
Spin is fast enough to control your motor (4000 rpm = 66 turns/second = 15ms for a turn), so no need for Assembly cogs and parameter passing.
To speed the code up for your motor, just set the speed variable to 1000..3000 you can change it 'while running with keys.
Andy