PDA

View Full Version : How do you calculate if delta time has elapsed in PASM?

turbosupra
03-23-2012, 03:06 PM
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.

Mike Green
03-23-2012, 03:20 PM
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.

turbosupra
03-23-2012, 03:45 PM
Thank you Mike ... that was exactly what I wanted and is so obvious now that you've typed it out :)

Duane Degn
03-23-2012, 05:57 PM
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.