Shop OBEX P1 Docs P2 Docs Learn Events
Help SPIN to ASEM — Parallax Forums

Help SPIN to ASEM

Julian800Julian800 Posts: 31
edited 2010-03-09 05:52 in Propeller 1
I am new to microcontroller. I just did some code use counter to generate clock for stepper with ramp. I need code run faster, But I am not familiar with assembly. ·Could someone help me to write some assembly code to do same thing?
·
pub Ramp (freq) | preFreq, tempFreqReg , RampSpeed
·
····· RampSpeed: =53687
····· tempFreqReg:= NcoFrqReg(freq)
·
····· if tempFreqReg <> frqa
······· repeat·· until tempFreqReg == frqa
·········· if tempFreqReg > frqa
··············· frqa :=· frqa + RampSpeed <# tempFreqReg
···············
·········· elseif· tempFreqReg < frqa·
··············· frqa := frqa· - RampSpeed #> tempFreqReg
···············
·····················
········· waitcnt(clkfreq/1_000 + cnt)
·
·········
PUB NcoFrqReg(frequency) : frqReg
{{
Returns frqReg = frequency × (2³² ÷ clkfreq) calculated with binary long
division.· This is faster than the floating point library, and takes less
code space.· This method is an adaptation of the CTR object's fraction
method.
}}
·
·frqReg := fraction(frequency, clkfreq, 1)
·
·
PRI fraction(a, b, shift) : f
·
· if shift > 0························ 'if shift, pre-shift a or b left
··· a <<= shift······················· 'to maintain significant bits while
· if shift < 0························ 'insuring proper result
··· b <<= -shift
·
· repeat 32··························· 'perform long division of a/b
··· f <<= 1
··· if a => b
····· a -= b
····· f++··········
··· a <<= 1 ··

Comments

Sign In or Register to comment.