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.

[参考译文] TMS570LS3137:正交脉冲发生器

Guru**** 2551110 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1298105/tms570ls3137-quadrature-pulse-generator

器件型号:TMS570LS3137

使用   编码器正交的示例代码,对于 输入 我 已经 生成了     它们之间90度相移 的方波脉冲, 现在 我 需要  找到 方向 以及  RPM , 我会发送 我的来源 如果 任何 修改 需要请更正我  

#include "HL_sys_common.h"

/* USER CODE BEGIN (1) */
#include "HL_sys_core.h"
#include "math.h"
#include "HL_sci.h"
#include "HL_eqep.h"
#include "HL_etpwm.h"






#define UART sciREG1

void sciDisplayText(sciBASE_t *sci, uint8 *text, uint32 length);

  uint8 ppr = 30U;
uint16 frequency = 2000U;
  uint16 RPM= 0;
uint8 deltaT = 0U;
 uint8 velocity = 0;
  uint8 speed = 0;
 double pi = 3.14;
   uint32 channelA = 0U;
    uint32 channelB = 0U;
    uint8 direction;
  uint32   prevchannelA = 0U;
  uint32   prevchannelB = 0U;


/* USER CODE END */

/** @fn void main(void)
*   @brief Application main function
*   @note This function is empty by default.
*
*   This function is called after startup.
*   The user can use this function to implement the application.
*/

/* USER CODE BEGIN (2) */
 void pulse_width(void)
 {
     etpwmInit();
        etpwmSetClkDiv(etpwmREG1,   ClkDiv_by_1,  HspClkDiv_by_1);
          etpwmSetTimebasePeriod(etpwmREG1, 37499U);
          etpwmSetCount(etpwmREG1, 19750U);
          etpwmSetCounterMode(etpwmREG1, CounterMode_Up);
          etpwmStartTBCLK();

         etpwmInit();
              etpwmSetClkDiv(etpwmREG2,  ClkDiv_by_1,  HspClkDiv_by_1);
              etpwmSetTimebasePeriod(etpwmREG2, 37499U);
              etpwmSetCount(etpwmREG2, 20008U);
              etpwmSetCounterMode(etpwmREG2, CounterMode_Up);
              etpwmStartTBCLK();

 }
/* USER CODE END */

int main(void)
{
/* USER CODE BEGIN (3) */
    QEPInit();
    sciInit();
    _enable_interrupt_();

    pulse_width();

        /* EQEP initialization based on GUI Configuration. */


        /* Enable Position Counter */
        eqepEnableCounter(eqepREG2);

        /* Enable Unit Timer. */
        eqepEnableUnitTimer(eqepREG2);

        /* Enable capture timer and capture period latch. */
        eqepEnableCapture(eqepREG2);


        while(1)
        {
          /* Status flag is set to indicate that a new value is latched in the QCPRD register. */
          if((eqepREG2->QEPSTS & 0x80U) != 0U)
          {

            deltaT = eqepREG2->QCPRD;
            velocity = (ppr / deltaT);
  RPM =  ((frequency * 60)/ ppr);
   speed =   (( RPM * ( 0.92 * pi) *60 )/1000) ;

            /* Clear the Status flag. */
               eqepREG2->QEPSTS |= 0x80U;
          }

           channelA =  etpwmREG1->TBCTR ;
           channelB = etpwmREG2->TBCTR ;
            if (channelA > channelB) {
              if (prevchannelA <= prevchannelB)
                {
                direction = 1;                         /* if   its  channelA is greater than channel B its moving Forward direction  */
              }
            } else if (channelA < channelB) {
              if (prevchannelA >= prevchannelB)
                {
                direction = 2;                         /* if   its  channelA is less than channel B its moving Reverse direction  */
              }
            }

            prevchannelA = channelA;
            prevchannelB = channelB;

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Jeev、

    我在您的代码中看不到任何问题、但您可以将 pulse_width 函数代码简化为如下所示:

    void pulse_width (void)
    {
    etpwmInit();
    etpwmSetClkDiv (etpwmREG1、ClkDiv_By_1、HspClkDiv_By_1);
    etpwmSetTimebasePeriod (etpwmREG137499U);
    etpwmSetCount (etpwmREG119750U);
    etpwmSetCounterMode (etpwmREG1 Mode_Up);

    etpwmSetClkDiv (etpwmREG2、ClkDiv_By_1、HspClkDiv_By_1);
    etpwmSetTimebasePeriod (etpwmREG237499U);
    etpwmSetCount (etpwmREG220008U);
    etpwmSetCounterMode (etpwmREG2,Mode_Up);

    etpwmStartTBCLK();

    除了这一点,我没有任何其他发现。

    --
    谢谢。此致、
    Jagadish。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    什么修改 我  需要做  pulse_width 函数 , 作为 wella 在需要 寻找          方向,如果通道 A 线索通道 B 它的正向方向   ,否则它应该是反向,对于 这个 逻辑 如何 写 一个 代码  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Jeev、

     我  需要 在 pulse_width 函数中进行哪些修改 ,

    这只是一个小小的修改,请比较我之前分享的代码和你的代码,我的意思是不需要调用"etpwmStartTBCLK"和"etpwmInit"两次。

    如果 通道 A   主  信道 B  其 正向,否则它 应该  反向,对于 这个 逻辑 如何 写 一个 代码 

    QEPSTS 寄存器中的 QDF 位将提供驱动的状态。

    如果该位为1、则表示通道 A 引线于通道 B;如果该位为1、则表示通道 B 引线于通道 A。

    --
    谢谢。此致、
    Jagadish。