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.

TMS320F280x例子Example_posspeed.c中关于变量mech_scaler、SpeedScaler的设定问题?

Other Parts Discussed in Thread: CONTROLSUITE

大侠您好,我的问题如下:

该.c文件中的例程

      pos16bval=(unsigned int)EQep1Regs.QPOSLAT;  // 
      tmp = (long)((long)pos16bval*(long)p->mech_scaler);     // 既然pos16bval是代表单位时间中断内采集QEP的个数,那计算速度应该是个数除以分辨率
      tmp &= 0x03FFF000; //请问下这一步是什么转换?
      tmp = (int)(tmp>>11);     

问题1:mech_scaler 不是例程中所描述的4000吗?如果是,那上述红色部分为什么不是除而是乘?

例程中:

if(EQep1Regs.QEPSTS.bit.UPEVNT==1)                 // Unit position event
 {
  if(EQep1Regs.QEPSTS.bit.COEF==0)               // No Capture overflow
   temp1=(unsigned long)EQep1Regs.QCPRDLAT;   // QCPRDLAT 是采集固定的QEP所用的时间??
  else                      // Capture overflow, saturate the result
   temp1=0xFFFF;

  p->Speed_pr = _IQdiv(p->SpeedScaler,temp1);    // p->Speed_pr = p->SpeedScaler/temp1
  Tmp1=p->Speed_pr;

 ……

}

问题2:这个是在低速下进行的运算,SpeedScaler这个值如何得到的呢,看了例程上的分析看得晕呼呼的,假设QEP是1000线精度的增量编码器,QCPRD=60000,

SYSCLK =60MHZ,CAPCLK = SYSCLK /128,UPEVNT = QCLK/32,求SpeedScaler的解答过程???

 

  •  为何没有工程师回答呢?SpeedScaler, // Parameter :  Scaler converting 1/N cycles to a GLOBAL_Q speed (Q0) 

  • pos16bval=(unsigned int)EQep1Regs.QPOSLAT;  //
          tmp = (long)((long)pos16bval*(long)p->mech_scaler);    
    // 请看头文件定义:int mech_scaler;        // Parameter: 0.9999/total count, total count = 4000 (Q26)

          tmp &= 0x03FFF000;        //这两句是数据格式转换,tmp由Q26转换成Q15,用于后面的计算统一格式
          tmp = (int)(tmp>>11);    


    问题1解答:mech_scaler就是分辨率的倒数(以Q26格式表示)

    例程中:

    if(EQep1Regs.QEPSTS.bit.UPEVNT==1)                 // Unit position event
     {
      if(EQep1Regs.QEPSTS.bit.COEF==0)               // No Capture overflow
       temp1=(unsigned long)EQep1Regs.QCPRDLAT;   // 去看一下QEP的数据手册,这个寄存器是由Unit position event发生来锁存数据的
      else                      // Capture overflow, saturate the result
       temp1=0xFFFF;

      p->Speed_pr = _IQdiv(p->SpeedScaler,temp1);    // p->Speed_pr = p->SpeedScaler/temp1
      Tmp1=p->Speed_pr;

     ……

    }

    问题2解答:
    在.cw文件开头的注释中有计算公式,写得比较清楚,只要你理解了并不难。
    按照你的数据:
    If base RPM  = 6000 rpm
        SpeedScaler = [32*(60MHz/128)*60s/min]/(4000*6000rpm) = 37.5

  • 请问.cw是什么文件,从哪个地方可以找到呢?谢谢!

  • qiang wang,

    我手误打错了,我参考的文件就是Example_posspeed.c , 具体路径是在controlSUITE中:

    C:\ti\controlSUITE\device_support\f2803x\v127\DSP2803x_examples_ccsv5\eqep_pos_speed\Example_posspeed.c

  • 你好!楼主!

    再请教一下:

     Uint32 MechScaler; // Parameter: 0.9999/total count (Q30)
    //(每个脉冲所转过的机械角度?)

    line_encoder=2000(编码器每转输出的脉冲个数?)


    电极4对

    就是这个mechscaler=1/8000=0x00020C4A????计算过程是什么?为什么这样算,为什么是1除以8000呢?百思不得其解!

    难道不应该是mechscaler=360/(2000*4)?即每个编码脉冲所转的角度,

  • 太感谢了,解答的很好