I want to precisely emulate a QEP sensor ABZ (or ABI) differential output using 28379D and would like this signal to externally feedback into a QEP conditioning circuit and ultimately back to the MCU. I would like the ability to change the output frequency during run-time and I want the index (Z, from now on) to be aligned with A exactly once per rotation. I believe using three ePWM modules (6 signals total) would be the easiest, but I am open to suggestions.
To generate A and B, I configure them as UpDown counters, link TBPRD and CMPA values and then add a TBPRD/2 phase delay to B. Whenever an output frequency change is desired, TBPRD, CMPA and TBPHS(B) are all updated.
I am finding the biggest challenge to be properly aligning the index when the PPR of the QEP is large (for now, I am using 512, but I'd like a flexible solution). Here are a few things that I have tinkered with, and some challenges that I have had:
QEP Position Interrupts (Janky McJankyPants)
- Configure the PWM module for Z identically to A and ensure shadow-loaded AQs.
- Set the output of Z disabled via AQ.
- Configure the QEP Position compare interrupt to trigger on the PPR-1 PWM period.
- In the interrupt, enable the output of Z using AQs and set the position compare to 0, so that it triggers immediately in the next cycle.
- In the next interrupt, go to 2.
Challenges here:
- Adds a new interrupt and QEP config that will not be in experimental control code (even if on separate core).
- Interrupt frequency can be high at low PPR and/or high frequency outputs.
TBPRD Stretching (Queen of the Janks)
- Configure the PWM module so that the clock divider for Z is PPR - (assume the dividers for A and B are each 1). For PPR=512; ClkDiv=128 and HspClk=4.
- Configure Z as a up (or down) counter and set the AQ so that it gets turned on at the very end (when aligned with A).
Challenges here:
- This solution only works with certain PPRs that can be created with the clock dividers.
- Aligning Z to A will be impossible under certain conditionals as the minimum resolution of Z is PPR times worse than A.
To me, both suck, any suggestions?