Help SPIN to ASEM
Julian800
Posts: 31
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 ··
·
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
btw, get to read one of the multiple asm tutorials around and then use the simulator in my sig to test out your code!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit some of my articles at Propeller Wiki:
MATH on the propeller propeller.wikispaces.com/MATH
pPropQL: propeller.wikispaces.com/pPropQL
pPropQL020: propeller.wikispaces.com/pPropQL020
OMU for the pPropQL/020 propeller.wikispaces.com/OMU
pPropellerSim - A propeller simulator for ASM development sourceforge.net/projects/ppropellersim