turbosupra

04-07-2012, 06:08 PM

Hi,

I have a method (actually two) that are written in spin, they works well but they are too slow for what I need. Unfortunately they involve a lot of math and I'd like to add even more math, and from what I've read in the manual, PASM math/comparisons are pretty difficult for a PASM beginner.

Also I'm about to start trying to translate them to PASM and I'm used to troubleshooting with the PST, how do you debug PASM?

PUB calculateCrankRpm(localCrankPeriod) | elapsed

elapsed := -cnt

l_previousNum8 := l_previousNum7

l_previousNum7 := l_previousNum6

l_previousNum6 := l_previousNum5

l_previousNum5 := l_previousNum4

l_previousNum4 := l_previousNum3

l_previousNum3 := l_previousNum2

l_previousNum2 := l_current

l_current := localCrankPeriod

if (l_timeStampCrank == 0)

l_timeStampCrank := (cnt + clkfreq)

if (l_previousNum8 <> 0 and l_previousNum7 <> 0 and l_previousNum6 <> 0 and l_previousNum5 <> 0 and l_previousNum4 <> 0 and l_previousNum3 <> 0 and l_previousNum2 <> 0)

l_previous7average := ((l_previousNum8 + l_previousNum7 + l_previousNum6 + l_previousNum5 + l_previousNum4 + l_previousNum3 + l_previousNum2)/7)

if (((l_current/10)*100) > ((l_previous7average/10)* 110)) or (((l_current/10)*100) < ((l_previous7average/10)*90))

' GAP exists if current greater than 110% of average or current less than 90% of average

l_gapTimePrevious := l_gapTime

l_gapTime := cnt

l_current := l_previous7average

else

if (((clkfreq/l_current)*60)/36) < 200

pst.str(string("crap2"))

pst.char(13)

else

l_toothRpm := (((clkfreq/l_previous7average)*60)/36)

elapsed += cnt - 544

PUB calculateCamRpm(localCamPeriod)

if(localCamPeriod) <> 0 and l_pstReadCamWheel == 1

l_previousCam6 := l_previousCam5

l_previousCam5 := l_previousCam4

l_previousCam4 := l_previousCam3

l_previousCam3 := l_previousCam2

l_previousCam2 := l_currentCam

l_currentCam := localCamPeriod

{pst.dec(l_previousCam6) ' 2324128 ' 2323968 ' 4546304 ' 2324128

pst.char(13)

pst.dec(l_previousCam5) ' 2323968 ' 4546304 ' 2324128 ' 2323968

pst.char(13)

pst.dec(l_previousCam4) ' 4546304 ' 2324128 ' 2323968 ' 4546304

pst.char(13)

pst.dec(l_previousCam3) ' 2324128 ' 2323968 ' 4546304 ' 2324128

pst.char(13)

pst.dec(l_previousCam2) ' 2323968 ' 4546304 ' 2324128 ' 2323968

pst.char(13)

pst.dec(l_currentCam) ' 4546304 ' 2324128 ' 2323968 ' 4546304

pst.char(13)

pst.char(13)} '(average) ' 2768499 ' 3212934 ' 3212966

' 4546304 is 1.65% of 2768499 and 2323968 is 83% of 2768499

' 4546304 is 1.42% of 3212934 and 2323968 is 72% of 3212934

' 4546304 is 1.42% of 3212966 and 2323968 is 72% of 3212966

if l_previousCam6 <> 0 and l_previousCam5 <> 0 and l_previousCam4 <> 0 and l_previousCam3 <> 0 and l_previousCam2 <> 0

l_CamToothAverage := ((l_previousCam6+l_previousCam5+l_previousCam4+l_p reviousCam3+l_previousCam2/5))

'if (((l_currentCam/10)*100) =< ((l_CamToothAverage/10)*105)) and (((l_currentCam/10)*100) => ((l_CamToothAverage/10)*95))

if (((l_currentCam/10)*100) =< ((l_CamToothAverage/10)*170)) or (((l_currentCam/10)*100) => ((l_CamToothAverage/10)*70))

'(768/10)*100 [7600] =< (3812614/10)*170 [40032405] or (768/10)*100 [7600] => (3812614/10)*95 [36219795]

' less than 105% of average or greater than 70% of average

' trigger1/(cba)

' c > b*1.1 and c > a*1.1

if((l_currentCam*100) > (l_previousCam2*110)) and ((l_currentCam*100) > (l_previousCam3*110)) and (l_trigger1 <> true)

if((l_previousCam2*100) < (l_previousCam3*105)) and ((l_previousCam2*100) > (l_previousCam3*95)) ' b < a*1.1 and b > a*.95

l_trigger1 := true

l_trigger2 := false

l_trigger3 := false

' trigger2/(acb)

' a*1.1 < c

if((l_currentCam*110) < (l_previousCam2*100)) and (l_trigger2 <> true)

if(((l_currentCam*100) < (l_previousCam3*105)) and ((l_currentCam*100) > (l_previousCam3*95))) ' a < b*1.05 and a > b*.95

if((l_previousCam2*100) > (l_previousCam3*110)) 'c > b*1.1

l_trigger2 := true

l_trigger3 := false

l_trigger1 := false

' trigger3/(bac)

' b < a*1.05 and b > a*.95 b*1.1 < c

if(((l_currentCam*100) < (l_previousCam2*105)) and ((l_currentCam*100) > (l_previousCam2*95))) and ((l_currentCam*110) < (l_previousCam3*100)) and (l_trigger3 <> true)

if((l_previousCam2*110) < (l_previousCam3*100)) ' a*1.1 < c

l_trigger3 := true

l_trigger1 := false

l_trigger2 := false

if(l_trigger3 == true)and(l_trigger1 == false)and(l_trigger2 == false)

l_calculatedCamRpm := (((clkfreq/((l_currentCam+l_previousCam2+l_previousCam3)/10))*120)/10) ' or ((((clkfreq/1+2+3)*10)*120)/10)

l_trigger3 := false

else

l_currentCam := l_CamToothAverage

I have a method (actually two) that are written in spin, they works well but they are too slow for what I need. Unfortunately they involve a lot of math and I'd like to add even more math, and from what I've read in the manual, PASM math/comparisons are pretty difficult for a PASM beginner.

Also I'm about to start trying to translate them to PASM and I'm used to troubleshooting with the PST, how do you debug PASM?

PUB calculateCrankRpm(localCrankPeriod) | elapsed

elapsed := -cnt

l_previousNum8 := l_previousNum7

l_previousNum7 := l_previousNum6

l_previousNum6 := l_previousNum5

l_previousNum5 := l_previousNum4

l_previousNum4 := l_previousNum3

l_previousNum3 := l_previousNum2

l_previousNum2 := l_current

l_current := localCrankPeriod

if (l_timeStampCrank == 0)

l_timeStampCrank := (cnt + clkfreq)

if (l_previousNum8 <> 0 and l_previousNum7 <> 0 and l_previousNum6 <> 0 and l_previousNum5 <> 0 and l_previousNum4 <> 0 and l_previousNum3 <> 0 and l_previousNum2 <> 0)

l_previous7average := ((l_previousNum8 + l_previousNum7 + l_previousNum6 + l_previousNum5 + l_previousNum4 + l_previousNum3 + l_previousNum2)/7)

if (((l_current/10)*100) > ((l_previous7average/10)* 110)) or (((l_current/10)*100) < ((l_previous7average/10)*90))

' GAP exists if current greater than 110% of average or current less than 90% of average

l_gapTimePrevious := l_gapTime

l_gapTime := cnt

l_current := l_previous7average

else

if (((clkfreq/l_current)*60)/36) < 200

pst.str(string("crap2"))

pst.char(13)

else

l_toothRpm := (((clkfreq/l_previous7average)*60)/36)

elapsed += cnt - 544

PUB calculateCamRpm(localCamPeriod)

if(localCamPeriod) <> 0 and l_pstReadCamWheel == 1

l_previousCam6 := l_previousCam5

l_previousCam5 := l_previousCam4

l_previousCam4 := l_previousCam3

l_previousCam3 := l_previousCam2

l_previousCam2 := l_currentCam

l_currentCam := localCamPeriod

{pst.dec(l_previousCam6) ' 2324128 ' 2323968 ' 4546304 ' 2324128

pst.char(13)

pst.dec(l_previousCam5) ' 2323968 ' 4546304 ' 2324128 ' 2323968

pst.char(13)

pst.dec(l_previousCam4) ' 4546304 ' 2324128 ' 2323968 ' 4546304

pst.char(13)

pst.dec(l_previousCam3) ' 2324128 ' 2323968 ' 4546304 ' 2324128

pst.char(13)

pst.dec(l_previousCam2) ' 2323968 ' 4546304 ' 2324128 ' 2323968

pst.char(13)

pst.dec(l_currentCam) ' 4546304 ' 2324128 ' 2323968 ' 4546304

pst.char(13)

pst.char(13)} '(average) ' 2768499 ' 3212934 ' 3212966

' 4546304 is 1.65% of 2768499 and 2323968 is 83% of 2768499

' 4546304 is 1.42% of 3212934 and 2323968 is 72% of 3212934

' 4546304 is 1.42% of 3212966 and 2323968 is 72% of 3212966

if l_previousCam6 <> 0 and l_previousCam5 <> 0 and l_previousCam4 <> 0 and l_previousCam3 <> 0 and l_previousCam2 <> 0

l_CamToothAverage := ((l_previousCam6+l_previousCam5+l_previousCam4+l_p reviousCam3+l_previousCam2/5))

'if (((l_currentCam/10)*100) =< ((l_CamToothAverage/10)*105)) and (((l_currentCam/10)*100) => ((l_CamToothAverage/10)*95))

if (((l_currentCam/10)*100) =< ((l_CamToothAverage/10)*170)) or (((l_currentCam/10)*100) => ((l_CamToothAverage/10)*70))

'(768/10)*100 [7600] =< (3812614/10)*170 [40032405] or (768/10)*100 [7600] => (3812614/10)*95 [36219795]

' less than 105% of average or greater than 70% of average

' trigger1/(cba)

' c > b*1.1 and c > a*1.1

if((l_currentCam*100) > (l_previousCam2*110)) and ((l_currentCam*100) > (l_previousCam3*110)) and (l_trigger1 <> true)

if((l_previousCam2*100) < (l_previousCam3*105)) and ((l_previousCam2*100) > (l_previousCam3*95)) ' b < a*1.1 and b > a*.95

l_trigger1 := true

l_trigger2 := false

l_trigger3 := false

' trigger2/(acb)

' a*1.1 < c

if((l_currentCam*110) < (l_previousCam2*100)) and (l_trigger2 <> true)

if(((l_currentCam*100) < (l_previousCam3*105)) and ((l_currentCam*100) > (l_previousCam3*95))) ' a < b*1.05 and a > b*.95

if((l_previousCam2*100) > (l_previousCam3*110)) 'c > b*1.1

l_trigger2 := true

l_trigger3 := false

l_trigger1 := false

' trigger3/(bac)

' b < a*1.05 and b > a*.95 b*1.1 < c

if(((l_currentCam*100) < (l_previousCam2*105)) and ((l_currentCam*100) > (l_previousCam2*95))) and ((l_currentCam*110) < (l_previousCam3*100)) and (l_trigger3 <> true)

if((l_previousCam2*110) < (l_previousCam3*100)) ' a*1.1 < c

l_trigger3 := true

l_trigger1 := false

l_trigger2 := false

if(l_trigger3 == true)and(l_trigger1 == false)and(l_trigger2 == false)

l_calculatedCamRpm := (((clkfreq/((l_currentCam+l_previousCam2+l_previousCam3)/10))*120)/10) ' or ((((clkfreq/1+2+3)*10)*120)/10)

l_trigger3 := false

else

l_currentCam := l_CamToothAverage