Shop OBEX P1 Docs P2 Docs Learn Events
PASM: Can I add/sub/cmp on FRQA/B?? — Parallax Forums

PASM: Can I add/sub/cmp on FRQA/B??

Alex.StanfieldAlex.Stanfield Posts: 198
edited 2012-10-03 13:10 in Propeller 1
The Propeller manual states that FRQA can be used as any other regular register, however I'm apparently seeing different behavior in PASM on FRQA when using it in ADD, SUB or CMP statements.

Any experience on this?

Alex

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-10-03 11:14
    frqa can be treated like any other register. What kind of anomalous behavior are you seeing? Examples?

    -Phil
  • Alex.StanfieldAlex.Stanfield Posts: 198
    edited 2012-10-03 11:51
    frqa can be treated like any other register. What kind of anomalous behavior are you seeing? Examples?

    -Phil

    Here's the routine that troubles me, if you un-comment the first and last 'mov' statements (with sFRQA) and replace FRQA with sFRQA in the in-between statements the routine gets to the "_Running" phase with the same parameters, as it's now it jumps from "_Starting " to "_Stopping"

    Thanks for taking a look
    Mon_JOB
                  
                  mov       wphsb, PHSB             'Save current value for PHSB
                  mov       qsteps, wphsb
                  sub       qsteps, lst_phsb WZ     'Get number of steps elapsed
            if_z  jmp       #Mon_JOB_ret            'No change -> exit
                  mov       lst_phsb, wPHSB         'Save for next checking
    
    
            '***Step ocurred so adjust position and check job boundaries---------------------
                  mov       dsteps, qsteps
                  test      pn, #$100        WZ     'Z=1 if pn positive
            if_nz neg       dsteps, dsteps
                          
            '***Inc/Dec motor position-------------------------------------------------------
    updpos        adds      0-0, dsteps 'pn         'Update motor pos                
                  sub       cs_Steps2Go,qsteps WC,WZ'Decrement pending steps         
            if_be mov       FRQA, #0                'Stop Pulses
       '     if_be mov       PHSA, #0                'De-assert clk line
            if_be mov       cs_Steps2Go, #0         'Catch overflows (excess steps)
            if_be jmp       #:exit                  'Get out & reset job       '
    
    
            '***Check job boundaries---------------------------------------------------------
              '    mov       sFRQA, FRQA
    '*************************************************************************************************
    :Chk_Starting cmp       cs_motSts, #_Starting WZ'*** STARTING PHASE ******************************
            if_ne jmp       #:Chk_Running
    
    
                  add       Nramp, qsteps           'Add steps in ramp (used in STOP command)
    
    
                  mov       t1, nxt_1ms             'Check if 1msec elapsed
                  sub       t1, cnt
                  cmps      t1, #0     WC           'C=1 if time is up
            if_nc jmp       #:SkipFStart
                  add       nxt_1ms, _1ms           'Set next period
            
                  add       FRQA, Ramp_1ms          'Acc change to FRQA 
                  maxs      FRQA, FRQ_max WC
            if_c  jmp       #:SkipFStart            'Max speed NOT reached, get out
    
    
                  mov       cs_motSts, #_Running    'Change state to Running
                  mov       N2, pstep
                  sub       N2, Nramp               'Nramp updated in "Mon_JOB"
    
    
    :SkipFStart
    
    
                  cmp       wPHSB, N2 WC,WZ         'Got to stopping phase?
            if_ae mov       cs_motSts, #_Stopping   '=> go directly to stopping phase
            if_ae mov       nxt_1ms, _1ms
            if_ae add       nxt_1ms, cnt
    
    
    
    
    '*************************************************************************************************
    :Chk_Running  cmp       cs_motSts, #_Running  WZ'*** RUNNING PHASE *******************************
            if_ne jmp       #:Chk_Stopping
    
    
                  tjnz      sv_run, #:exit  'if RUN in progress keep running
    
    
                  cmp       wPHSB, N2 WC,WZ         'Got to stopping phase?
            if_ae mov       cs_motSts, #_Stopping   '=> go directly to stopping phase
            if_ae mov       nxt_1ms, _1ms
            if_ae add       nxt_1ms, cnt
     
    '*************************************************************************************************
    :Chk_Stopping cmp       cs_motSts, #_Stopping WZ'*** STOPPING PHASE ******************************
            if_ne jmp       #:Exit
    
    
                  mov       t1, nxt_1ms             'Check if 1msec elapsed
                  sub       t1, cnt
                  cmps      t1, #0     WC           'C=1 if time is up
            if_nc jmp       #:SkipFStop
                  add       nxt_1ms, _1ms           'Set next period
            
                  sub       FRQA, Ramp_1ms          'Acc change to FRQA
                  mins      FRQA, FRQ_min 
    
    
    :SkipFStop
            '****Slowing down then keep running when fmax reached-------------------------------------
                  test      flags, #_f_slowdown WZ  'Are we slowing down after a _NewSpeed?
            if_z  jmp       #:skip_slowdown
            
                  cmp       FRQA, FRQ_max WC,WZ
            if_be mov       cs_motSts, #_Running    'Go back to running phase since we reached the 
                                                    'slowdown limit after _NewSpeed
            if_be andn      flags, #_f_slowdown     'Reset flag for slowdown
            if_be jmp       #:Exit
                                                                    
    :skip_slowdown
            '**** If job was STOPPED then slowdown until fmin and then stop --------------------------
                  test      flags, #_f_stop WZ
            if_z  jmp       #:skip_stop
    
    
                  cmp       FRQA, FRQ_min WC,WZ     'Cancel motion when Fmin reached
            if_be mov       FRQA, #0                'Reset job when we get to the main loop
            if_be mov       cs_Steps2Go, #0
    '        if_be mov       PHSA, #0                'de-assert clk line
                  
    :skip_stop        
            '      sub       Nramp, #1  WZ           'Decrease ramp steps (used in STOP command)
            '      mins      Nramp, #0  WC           'Limit Nramp to 0 or greater
     '   if_z_or_c mov       FRQA, #0                'Stop job
        
            '**** EXIT section------------------------------------------------------------------------
    :Exit
                  tjnz      cs_Steps2go, #Mon_JOB_ret1
    
    
    chkpos        test      0-0, Scale_msk WZ       'Finished on fullstep boundary?
            if_nz add       cs_Steps2go, #1         'NO->add 1 more step
            if_nz mov       FRQA, FRQ_min           'Set fmin for remaining steps
    
    
    Mon_JOB_ret1        
             '     mov       FRQA, SFRQA
            
    Mon_JOB_ret   ret
    

    Alex
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-10-03 11:55
    Don't forget that multi-step changes to frqa such as your
                  sub       FRQA, Ramp_1ms          'Acc change to FRQA
                  mins      FRQA, FRQ_min 
    

    will affect phsa after each step if the counter is running. That might not be the behavior that you want or expect.

    -Phil
  • Alex.StanfieldAlex.Stanfield Posts: 198
    edited 2012-10-03 13:10
    Don't forget that multi-step changes to frqa such as your
                  sub       FRQA, Ramp_1ms          'Acc change to FRQA
                  mins      FRQA, FRQ_min 
    

    will affect phsa after each step if the counter is running. That might not be the behavior that you want or expect.
    l

    Agreed, but it doesn't matter in this case, those max/min statements are just to keep the upper/lower limits, and at the operating frequency it's not noticeable.

    Alex
Sign In or Register to comment.