Help. Shared Variables to and from a spin routine to a assembly routine
krazyideas
Posts: 119
Well Hello all.
Ok Well I have been working on a program for my Dad for a couple of months now. This is the First program that I have ever tryed to build. And I want to get it done before Christmas so it can be his Present. But I'm haveing a hard time trying to get it to work right.·
I have most everything else working right, but these two Assembly programs are the core of it and I need your guys help to get it right.
These programs don't run at the same time. The frist one runs and then when a command is triggered in a spin program it switches to the second one. What I'm doing is takeing·the pluses from a analog·out put and makeing them digital and then running his motor with the digital outputs so we can adjust·it on·the fly while it is running.·
The princibles that I have in this program·I am very sure·will work, his motor is pretty simple, but I·need help getting the bugs out of these programs. I'm running 6 sets of these programs one set in one cog and so on to cog 6 Then cog seven controls the 6
Any help would be wonderful and apprecheated
Thanks
Dat
ReadFireTime1·····ORG······· 0
······················· COGID····· ID1
······················· or······ ··· dira, OutPutPin1················ ·· 'Set output pin······················
······················· mov······· CTRA,#0
······················· movi···· ·· CTRA,#%11111····················
······················· mov······· FRQA,#1
·································································
: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
······················· waitpne··· WindowPin1, WindowPin1········ 'Window ends
······················· andn······ ·outa, OutPutPin1················· 'Relay pluse···
······················· mov······· ·WinEnd1, PHSA···················· 'Mark turn off····
······················· sub········ ·WinEnd1, WinStart1············· 'Leangth of window
·······················
······················· wrlong···· I need to put WinStar1 into a Varuble I use in a Spin program
······················· wrlong···· I need to put WinEnd1 into a Spin program variable also.
·······················
······················· jmp #:Relay1··································· · 'Loop endlessly
·······················
WinStart1····· long····· 0·········· 'Mark
WinEnd1······· long····· 0·········· 'Mark
TurnOn1······· long····· 0·········· '# of cnt's to wait before turn on
TurnOff1······· long····· 0·········· '# of cnt's to Stay on before turn off
ID1·· ············long····· 0·········· 'CogID
MarkerPin1···· long····· |< 9······· 'Zero mark pin
WindowPin1····long····· |< 0······· 'Window mark pin
OutPutPin1···· long····· |< 12······ 'Output pin
Dat
ExicuteFireTime1···ORG······· 0
························ or········ dira, OutPin1················· 'Set output pin
:FireingLoop1······ rdlong· ?????
······················· rdlong· ??????
·······················
······················· WAITPEQ··· Mark1, Mark1
······················· mov·········· syncdelay1, cnt··············· 'Set Zero
·······················
······················· add·········· syncdelay1, TurnOn1·· I need to read this from a spin program····· (TurnOn1)
······················· waitcnt····· syncdelay1, TurnOff1· I need to read this from a spin program also (TurnOff1)
·······················
······················· or············ outa, OutPin1
······················· waitcnt····· syncdelay1, 500··············· 'When cnt = syncdelay output Low
······················· andn········· outa, OutPin1
·······················
······················· jmp········· #:FireingLoop1················ 'Loop endlessly
syncdelay1····· long····· 0·········· 'Register to control waits between commands
OutPin1· ··· ··· long····· |< 12······ 'Output pin
Mark1······ ···· long····· |< 9······· 'Zero mark pin
Ok Well I have been working on a program for my Dad for a couple of months now. This is the First program that I have ever tryed to build. And I want to get it done before Christmas so it can be his Present. But I'm haveing a hard time trying to get it to work right.·
I have most everything else working right, but these two Assembly programs are the core of it and I need your guys help to get it right.
These programs don't run at the same time. The frist one runs and then when a command is triggered in a spin program it switches to the second one. What I'm doing is takeing·the pluses from a analog·out put and makeing them digital and then running his motor with the digital outputs so we can adjust·it on·the fly while it is running.·
The princibles that I have in this program·I am very sure·will work, his motor is pretty simple, but I·need help getting the bugs out of these programs. I'm running 6 sets of these programs one set in one cog and so on to cog 6 Then cog seven controls the 6
Any help would be wonderful and apprecheated
Thanks
Dat
ReadFireTime1·····ORG······· 0
······················· COGID····· ID1
······················· or······ ··· dira, OutPutPin1················ ·· 'Set output pin······················
······················· mov······· CTRA,#0
······················· movi···· ·· CTRA,#%11111····················
······················· mov······· FRQA,#1
·································································
: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
······················· waitpne··· WindowPin1, WindowPin1········ 'Window ends
······················· andn······ ·outa, OutPutPin1················· 'Relay pluse···
······················· mov······· ·WinEnd1, PHSA···················· 'Mark turn off····
······················· sub········ ·WinEnd1, WinStart1············· 'Leangth of window
·······················
······················· wrlong···· I need to put WinStar1 into a Varuble I use in a Spin program
······················· wrlong···· I need to put WinEnd1 into a Spin program variable also.
·······················
······················· jmp #:Relay1··································· · 'Loop endlessly
·······················
WinStart1····· long····· 0·········· 'Mark
WinEnd1······· long····· 0·········· 'Mark
TurnOn1······· long····· 0·········· '# of cnt's to wait before turn on
TurnOff1······· long····· 0·········· '# of cnt's to Stay on before turn off
ID1·· ············long····· 0·········· 'CogID
MarkerPin1···· long····· |< 9······· 'Zero mark pin
WindowPin1····long····· |< 0······· 'Window mark pin
OutPutPin1···· long····· |< 12······ 'Output pin
Dat
ExicuteFireTime1···ORG······· 0
························ or········ dira, OutPin1················· 'Set output pin
:FireingLoop1······ rdlong· ?????
······················· rdlong· ??????
·······················
······················· WAITPEQ··· Mark1, Mark1
······················· mov·········· syncdelay1, cnt··············· 'Set Zero
·······················
······················· add·········· syncdelay1, TurnOn1·· I need to read this from a spin program····· (TurnOn1)
······················· waitcnt····· syncdelay1, TurnOff1· I need to read this from a spin program also (TurnOff1)
·······················
······················· or············ outa, OutPin1
······················· waitcnt····· syncdelay1, 500··············· 'When cnt = syncdelay output Low
······················· andn········· outa, OutPin1
·······················
······················· jmp········· #:FireingLoop1················ 'Loop endlessly
syncdelay1····· long····· 0·········· 'Register to control waits between commands
OutPin1· ··· ··· long····· |< 12······ 'Output pin
Mark1······ ···· long····· |< 9······· 'Zero mark pin
Comments
your appell to look into your code sounds to me a little bit like "do it ALL for me"
As more concrete your questions are the more people are willing to help.
So could you please describe what is happening and what is your guess what the reason might be
the basic hint for communicate via variables is
if you call the cognew-command there are two parameters
the second one is for handover a pointer to a hub-adress
see this thread
Assembly, step by step
step 3 and step 4
make a try on your own, write some democode and if it does not work as expected come back to the forum
with your democode attached and a concrete question
best regards
Stefan
I was more trying to say that I was in a hurry and that some comments to get me going down the right path would be appreceated. And to know if I was even on the right path or even close to haveing the bugs worked out of my programs, or if it is just not probale that I will get it done in time for Christmas.
Sorry to sound lazy and like I didn't want to do the work.
I really don't have a very good idea at programing. I have just been looking at the book, I look up a command and then try and make it work.
I was hopeing for someone to tell me that I was getting close and point me in the right direction.
Sorry bout the confusion.
Thank you Stefan for the help though.
Once again sorry I will try to be more clear next time
Take care
you have some comments inside your ASM-code but is still very helpful if you describe in complete sentences what you want to do
and you have to do it IN DETAIL
Bugs that are caused by a misunderstanding of how a command works can't be found by short comments of the commands
best regards
Stefan
Now your code looks much better. On bug: mov PHSA,#0 (the # is important)
Here are some code snippets that show you how to pass the pointers for the Spin variables.
Im still not shure if your overall concept does what you want, but without more information it's up to you.
Does Spin manipulate the Start time ore Window time before starting the Fireing cogs?
Andy
OK, so I got as far as I could with the help that you guys have given me. This time I will try and tell you excatly what I am trying to do.
My dad is building an electric motor and he can make it spin. The problem is that his mechanical timeing device that he has does not allow him to be able to tune the motor at all.
What he has is a disk with big magnets in it and then 6 sets of electro coils, 2 on either side of the disk. He runs his motor from 2000 RPM to 4000 RPM.
So what I am trying to build for him is a program that allows him to be able to adjust his timeing while his motor is running.
I have two driver programs. One that just relays and measures the puleses from his mechancal timeing, and another that ignors his timeing and just mimics and adjusts the puleses from his mechanical timeing.
I have 6 sets of these two programs, one set for each coil. And I run each set in it's own cog to keep the speed of the programs up. Nice and short. The two never run at the same time.
The one program is like the start up program, it just relays and measures his puleses. While the second one is the running program, it mimics the first without the pulse from the mechanical timeing. Allowing me to adjust the timeing while the motor is running. Going from anolog timeing to digital timeing.
Then I have another program running in it's own cog that is measureing how many counts are in one degree of rotation, which is what I use to advance or retarde the timeing. I measure the counts it take for one degree of rotation so that if the motor slows down or speeds·up I still change the timeing by the same amount.
I have another program that is running the adjusting of the pulse's
Comeing to a total of useing all 8 cogs.
I still have some other things that I want to do. So I have another propellor chip. I have the Demo board and the PDB that I am useing.
In the Demo board I am running
-an RPM gage on a computer screen
-an indicator of what degree each coil is turning on and off at on a TV screen
-and a mini seral cable that I made.
So I'm useing 6 cogs there.
The mini seial cable I made uses 6 pins. I have it output a seires of highs and lows on those 6 pins depinding on what key on the keyboard I press. I hooked up that mini serial cable to 6 pins on the PDB to control my varubles. I know that it works because I hooked it all up and was makeing leds turn on and off on the PDB.
I have not tested the RPM gage and the indicator program yet but it is lowest on the food chain of what need's to work
I call the Demo Board program Master1, and the PDB program Master2
So Master1 works well enough for me
Master2 is where my problems are.
Cog 1, Runs the start up program that starts the other cogs and then waits for a·dip switch on pin 21 to go high·then it switches from the first driver program (ReadFireTime1, and 2 and 3 ect) to the second driver program (ExicuteFireTime1,and 2 ect)
after which it starts running the pulse adjusting program which is the reciver for my mini serial cable. I have delays in that program so that a led will light up when the PDB recives a key from the Demo board and will only count it as one change. Then if the dip switch makes pin 21 goes low then it returns to the ReadFireTime programs.
Cog2, Runs the program that give me the counts in one degree of rotation to adjust the pulses with
Cogs 3 through 8 Run my driver Programs
I do belive that most everything is working right except for my driver programs.
What I need to happen is the pulses from the ReadFireTime programs that are stored in WinStart1, WinEnd1, ect to be stored in global variables TurnOn1, TurnOff1, ect.
So that when I switch from the ReadFireTime programs to the ExicuteFireTime programs, I can adjust TurnOn1, TurnOff1, ect and then send them to the ExicuteFireTime Cogs or my driver programs, allowing me to change at will when each pulse turns on and how long it stays on for.
Now in the driver programs I have a zero mark that is 180 degrees from the begging of the pulse where the counter starts at zero, this is so that if there is a small error in the pulse it is not multiplyed with each rotation, but is contained only in that one rotation which allows each pulse to·turn on at the same·degree each rotation and then adjust it with the keyboard through my mini seral cable reciver program.
Also this sloves the problem of switching between my driver programs and keeping in the right timeing, other wise by the time that I switched from ReadFireTime to ExicuteFireTime I would be way off and be starting retarded and it wouldn't work.
Something else is The reason that I use the CNTA is so the when I am subtracting the counts of when pulses turn on and off I never end up trying to subtract 4 billion from 700 or something like that, because I reset the PHSA counter each loop. So my mesurements are always right
So I think that is as clear as I can get. I'm really bad at getting across what I mean to say, you can ask my wife.
Let me know what you think,
I finaly got my computer to attach files so it will be easyer to read this time around
Also I know that there are probly a thousand better ways to do this but I just need help to get this to work so if it can work Please help me get on the right path
Thanks so much for the help guys. There is NO way I could even get this far with out all the help I have gotten from you vetrans.
I hope I'm close.
http://forums.parallax.com/showthread.php?p=768643
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
first of all did you take a look into this link ?
http://forums.parallax.com/showthread.php?p=647408 ?
This link shows an example how values can be exhanged between assembler-code and SPIN-code
OK i can see it's a real complex project.
My way to understand it is to get an overview (which you gave by your posting above) and then
dividing the project in small SUB-projects.
Do I understand right:
It is an electrical motor. It has six coils that have to be switched on/off in a well defined way to keep the motor running?
You use one program to just analyse the switch-on/off-timings of an existing motor-control ?
A second program is used to switch on/off the six coils by using the propeller-chip ?
and you want to change the timelengths of the ON-phase, the OFF-phase to do a fine-tuning of the motor?
You want to be able to change these ON/OFF-timelengthes manually ?
and by watching the rotation-speed when the speed reaches a maximum?
or do you want to reach a maximum of effectivity?
Anyway - first thing I would do is
I would check what is the shortest timelenght that has to be measured?
quick guessing: 4000 RPM / 60 seconds = 67 RPS = 0,015 seconds = 15 Milliseconds
on degree of rotation 15 ms / 360° = 41 microseconds
How many steps does the counter do within 41 microseconds?
How big is the error caused by the resolution of the counter?
How big is the change of the timelength
How do I have to configure the counter to measure timelenght from
yeah from what start-frequency ? 0,1Hz, 1Hz, 10 Hz?
If I do NOT change the configuration of the counter what resolution do I get?
Is this resolution good enough for the maximum speed? (41 MICRO-Seconds)
Then checking the analyse-program does it measure the timelenghtes right?
I would do this by using a simple rectangle-wave-generator build with an OP-Amp or an NE555 or something similar
or with a cog ! I would measure the ON-time and visualise it in any way (serial output to PST.EXE, or TV)
Then I would compare the measured timelenght of the programm with the measured timelenght seen on an oscilloscope
(as an oscilloscope is a very good reference)
Second best would be to use a prebuild and well-testet frequency-measuring-object for the propeller
does this thing get the same results?
And then make INTENSIVLY tests with it:
what does it measure if IO-PIN is DISconnected ?
what does it measure at 0,1 Hz ? (every 10 seconds ONE pulse)
what does it measure at 1 Hz , 2Hz, 10 Hz, 100Hz, 200Hz ?
41 microseconds is a frequency of 1/0.000041 = 24390 Hz
So you have to measure up to 25000 Hz
AFTER having made sure that all this is measuring with a good enough precision
I would go on with the next step
Next step is to reproduce the same timings as the existing motor-control is producing.
This will be checked by using an oscilloscope too.
This means comparing the ON/OFF-signal of the existing motor-control with the
signal produced by the propeller with parameters measured with the propeller
measuring the ON/OFF-signals of the existing motor-control
The basic princip is:
keep variable factors as low as possible.
Variable factors here mean EVERYTHING that could by changing
NOT only SPIN-variables !
If too many factors are floating around without your control you never will get reproducable results
or find a bug.
It's a good idea to start with a quick try to make it work all at once. But if it does NOT work after a short time
you have to switch to small sub-projects and realize them step by step.
best regards
Stefan