pasm help--timing isn't working right
P!-Ro
Posts: 1,189
Today is actually the first day I've ever worked with pasm, so I'm very new. I've gone through a lot of documentation online as well as the propeller manual but now I've gotten stuck. I was trying to make a simple program to control a servo, but even though it is set up to send the correct 2ms pulse every 20 ms, it crashes to the end of it's range. I changed the values both directions but to no avail, but I shouldn't have to since the spin equivilent is running just fine. My only guess is I have the pause routines set up wrong, hovever I really can't tell. The code I have for sending the signals is below, the full code is attached.
:loop
········ mov···· clock,··· #0
········ add···· clock,··· cnt
········ add···· clock,··· #13
········
········ xor···· outa,···· servopin
········ waitcnt clock,··· duration
········ xor···· outa,···· servopin
········ mov···· clock,··· #0
········ add···· clock,··· cnt
········ add···· clock,··· #9
········ waitcnt clock,···· pause
········ jmp···· #:loop
:loop
········ mov···· clock,··· #0
········ add···· clock,··· cnt
········ add···· clock,··· #13
········
········ xor···· outa,···· servopin
········ waitcnt clock,··· duration
········ xor···· outa,···· servopin
········ mov···· clock,··· #0
········ add···· clock,··· cnt
········ add···· clock,··· #9
········ waitcnt clock,···· pause
········ jmp···· #:loop
spin
677B
Comments
BTW if you do a mov clock,cnt you do not need the preceeding mov clock,#0
Next thing is that #9 may be just too fine to catch the cnt in waitcnt, in which case you will be waiting ~90sec for it go around the 32bit cycle.
Next, you want 20ms. This is way faster than this. Presuming 80MHz clock, 12.5ns clock. mov+add+add+xor+waitcnt = 22+ clocks = ~275+ns. Your delay is only going to be ~0 clock ~(#9 - 4 - 6). Double this for your frequency of 1/450ns = ~2MHz.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
Post Edited (kuroneko) : 7/4/2010 9:12:24 AM GMT
The key with waitcnt is that you must setup the target value (in clock) before the you use it; the second parameter in waitcnt is the new target (i.e., for the next waitcnt).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Post Edited (JonnyMac) : 7/4/2010 2:49:35 PM GMT
And this doesn't fly:
Post Edited (kuroneko) : 7/5/2010 2:14:41 AM GMT
Yep, you're right (again), and I'll fix the other part of my listing.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
······ mov···· time, cnt
······ add···· time, #9
:loop· waitcnt time, delay
······ xor···· outa, pin
······
······ jmp···· #:loop
Is the first wait time·1 clock cycle, and the the second the delay time? If so, is there a way I can leave out the "delay" and just set a value for time? What is the reason for waitcnt adding a value for time for the next pause rather than the current pause?
I'm not sure exactly what value to use for the "9". I think it's a few clocks less, but I'd have to review some of the threads on WAITCNT timing. With this scheme, the time mark is the 2nd cycle (?) of the ADD instruction when the destination operand is fetched. The "9" accounts for the rest of the ADD instruction and the first few cycles of the WAITCNT until it compares the destination operand to the system clock.
Post Edited (Mike Green) : 7/4/2010 5:53:03 PM GMT
·[url=http://www.parallax.com/Portals/0/Downloads/mm/video/Webinar/2009-04-07-Webinar-[03].wmv]http://www.parallax.com/Portals/0/Downloads/mm/video/Webinar/2009-04-07-Webinar-[noparse][[/noparse]03].wmv[/url]
Jim
Mike, I think it has to be 9 or more because the add command takes 4 clock beats, and the the waitcnt takes 4 clock beats, leaving the minimum value of 1 clock beat for pausing. If you add an extra instruction between this, such as xor for toggling a pin, I found that the value needed to be 13+ giving an extra 4 clock cycles for the extra command.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
90 * 2 = Pi
The way I like to think of it is: WAITCNT Target, Reload
When the WAITCNT is reached in your code, the cog waits at that point until the value in the system counter CNT reaches the value in Target. The cog then adds the value of Reload onto the value in Target (which at that instant was the same as the system counter CNT) and carries on with the program. If you then issue another WAITCNT, then execution is again halted until the previously loaded Target is reached. And a new Taget is again calculated.... and so on.
So, another way of saying it is when a WAITCNT is encountered, it will wait until the previously loaded Target is reached.
Hope that helps.
Cheers,
Peter (pjv)
Since I've been programming in assembly for two days now (yes, I know. A long time) I've decided to make some code that is actually useful. Since I got one of the penguins with a reset button problem at the expo, I decided to tether it up to the propeller and make it work. The code posted below allows it to walk forward, and with a little modding should be able to turn as well. Please go ahead and be as rough on my techniques as you want, I'd hate to be doing things wrong long enough to cement it in my mind!
BTW--I have another question about my code. How come the second direction change will reset the first in this code?
·········mov····· dira, tiltpin
········ mov····· dira, stridepin
It took me all day to figure out I had to use "or" instead!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
90 * 2 = Pi
Post Edited (kuroneko) : 7/5/2010 5:32:20 AM GMT
I've written a demo now where it moves forward-backward-turnleft-turnright-repeat. I implemented djnz a couple times, too. It's attached.
Now I'm just thinking of what I should do tomorrow, start objects and to tasks such as play wav music?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
90 * 2 = Pi
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
90 * 2 = Pi