Shop OBEX P1 Docs P2 Docs Learn Events
How do you calculate if delta time has elapsed in PASM? — Parallax Forums

How do you calculate if delta time has elapsed in PASM?

turbosupraturbosupra Posts: 1,088
edited 2012-03-23 10:57 in Propeller 1
Through searching, I saw an example that used frqa and phsa, but I tried that and it did not work and then I realized I am already using frqa and frqb as counters for something else :)

In spin I would do something like (cnt-timeStamp > clkfreq)

I tried to do the same in pasm, but I don't know if this is a legal operation, I tried to do something with sub, but that didn't work either. Also, do I have to use if_C_OR_Z for each line after a compare, since there is no indentation or brackets in pasm?

gapCntAsm is just an incrementing counter based on certain conditions and it does increment because I can see it doing so in the terminal
                        cmp     (cnt-timeStamp), #delta  WZ,WC      'test if delta time reached or exceeded, C should be 1 or Z should be 1
if_C_OR_Z               mov     gapCntAsmPeak, gapCntAsm ' copy the gapCnt to gapCntPeak
if_C_OR_Z               wrlong  gapCntAsmPeak, gapCntAsmPeakptr ' update the hubram value
if_C_OR_Z               mov     timeStamp, cnt    


' -------------------------------------------------------------------------------------------------- 

delta                   long    80_000_000                

Thanks for reading my newb question.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-03-23 08:20
    You have "cmp (cnt - timeStamp), #delta WZ,WC". What this statement means is "cmp addressOfCnt-addressOfTimeStamp, #addessofDelta". What you probably want is:
              MOV   temp,CNT                  ' Get current system clock value
              SUB   temp,timeStamp         ' Subtract saved clock value
              CMP   temp,delta   WZ,WC   ' Compare to time difference and set flags
    

    You do have to have the condition on each line where you want it to take effect. It's perfectly legitimate to have one condition on two lines, then none, then another on a line, etc.
  • turbosupraturbosupra Posts: 1,088
    edited 2012-03-23 08:45
    Thank you Mike ... that was exactly what I wanted and is so obvious now that you've typed it out :)
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-03-23 10:57
    I'd think in most cases the z flag wont ever get set (or at least not very often). Most examples I've seen just use the c flag.

    I personally just use the c flag because I think it simplifies the coding a bit.
Sign In or Register to comment.