This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28377S: Count PWM Cycles for Stepper Motor

Part Number: TMS320F28377S
Other Parts Discussed in Thread: CONTROLSUITE

Hi -

I'm using the F28377S to drive stepper motors by converting a trajectory/profile velocity into a PWM frequency during each position control interrupt.  This works fairly well, but  does not end the move at exactly the correct number of steps (which may be okay for the application or not - not sure yet).  I would like to count the PWM cycles as the move is progressing.  Looking through the reference manual and forum, I see that this could be possible.  I would like to do this in hardware with one of the on-board modules (eCAP, TZ, capture/compare system, XBAR, etc.), but need some guidance on how to do this.  I would like to avoid using an interrupt to increment a counting variable.

Thanks-

Mary

  • Just loop the signal back to ecap inputs.

    ECAP example may be available at
    C:\ti\controlSUITE\device_support\F2837xS\v210\F2837xS_examples_Cpu1

    This can be a good starting point.
  • Hi Ramesh-

    Thank you for your response.  I connected the PWM output signal into GPIO8 and set it up as an input XBAR (INPUT7SELECT) for ECAP1 and am now getting stepper counts in the ECAP module.

    Next, I would like to stop the PWM in software when the counts reach a certain number.  Can I rout the same GPIO pin to to TZ1 and stop it that way?

    Thanks again-

    Mary

  • Hi Mary,

    I don't think using this pin as a TZ pin is what you are looking to do. You would end up tripping the PWM as soon as the PWM started.

    Stopping after a number of cycles is a bit tricky, but you should be able to do it with your ECAP or PWM interrupt and the appropriate loading of the shadow registers in the action qualifier to put the the PWM into a constant state. There is also the option of using a software forced trip via the TZFRC register, but the shutdown will likely occur in the middle of a switching cycle. You would need to evaluate if that would be acceptable for your application.

    Regards,
    Kris
  • Hi Mary,

    Another option may be to use the eQEP peripheral.  It is the device's best pulse counter.  It's primary purpose is to interface with incremental encoders.
    (eCAP is really best seen as a something that can measure a square-wave - duty/period)

    The eQEP can then be set up to generate an interrupt after so many counts (that you can define).  Probably easiest to set the amount of steps you want to generate to QPOSMAX and let it be your interrupt.  The main challenge I think you'd face is keeping the QEP counting aligned to any writes to QPOSMAX as you move to a new sequence.


    Thank you,
    Brett

  • Hi -

    Thanks for your responses.  I'm already using the eQEPs for encoders.  The encoder resolution is much coarser than the step resolution (working with legacy hardware) so I wanted to be able to count steps as well.  

    This is what I ended up doing and it works well.  I fed the PWM outputs into GPIO INPUTXBARs set up as eCAPs.  I use all 4 CEVTs to count rising edges.  I moved the counting routine into the CLA and have it run continuously.  I Initialize the counts and events at the beginning of a move and then watch the counts.  When the steps get to within a certain number of steps before the end of a move, I change the PWM period from the profiled value to 1 step per motor-contol ISR until the final number of steps equals the total number of steps in the move.

    To externally verify that my counts were accurate, we used a scope that is capable of edge counting.  My method's count matched that of the scope at several distances and velocities.  

    I'm very happy with the outcome and must say that I really like this F28377S processor.

    Thanks for your help-

    Mary