Because of the Thanksgiving holiday in the U.S., TI E2E™ design support forum responses may be delayed from November 25 through December 2. Thank you for your patience.

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.

Speed calculation of DC fan motor using QEI module

Other Parts Discussed in Thread: TM4C123GH6ZRB

Hi 

    I am using Tiva  TM4C123GH6ZRB micro controller .Using QEI module  for calculation of the speed. as per the formula (rpm =  (clock * (2 ^ VELDIV) * SPEED * 60) ÷ (LOAD * ppr * edges)).

For  getting the SPEED  using his API  QEIVelocityGet(QEI1_BASE).But  SPEED is always constant even after change the fan speed.Could you please help me ,what could be the issue?I ma new to  QEI module.

clock is 80Mhz and ppr 100. Here is my code

uint32_t get_fan_speed( ){
uint64_t velcount, rpm;
//Enable the QEI module

//The GPIO PIN peripheral  enabled for QEI module

//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);

//
// The QEI peripheral  enabled for use.
//
// SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI1);

//
//Configure the pin for QEI
//
GPIOPinConfigure(GPIO_PG0_PHA1);


//
//Set the GPIO PIN to QEI type
//
GPIOPinTypeQEI(GPIO_PORTG_BASE, GPIO_PIN_0);


//
//Initial Disable the QEI module
//

QEIDisable(QEI1_BASE);

//
//Configure the QEI
//

QEIConfigure(QEI1_BASE,(QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP),0xF9F);

//
//Initial Disable the QEI Velocity
//

QEIVelocityDisable(QEI1_BASE);

//
//Configure the QEI velocity
//

QEIVelocityConfigure(QEI1_BASE,QEI_VELDIV_1,8000000);

//
// Enable the QUI velocity
//
QEIVelocityEnable(QEI1_BASE);

//
// Enable the QUI module
//
QEIEnable(QEI1_BASE);

velcount = QEIVelocityGet(QEI1_BASE);

System_printf("\nvelcount =%d\n",velcount);

rpm = (240 *velcount)/(400);//According to the formula of rpm = (clock * (2 ^ VELDIV) * SPEED * 60) ÷ (LOAD * ppr * edges) as per data sheet
//clock = 80000000Hz,VELDIV = QEI_VELDIV_1,SPEED = velcount,load = 80000000/4 = 200000000 ,ppr = 100 ,edges =4
System_printf("\n***rpm = %d",rpm);

return rpm;
}

Thanks & Regards

     Durga

  • Hi Durga,

    I have moved your post to the Tiva-C forums to see if they can assist with your firmware. If you have a question about the motor driver, I'll be happy to help.

  • I'm not familiar with the QEI module and the associated TIVA support but that looks wrong.

    Surely initializing the QEI every time you read it is going to re-zero it? 

    Let's see 100ppr *3600 rpm = 360000 ppm = 6 pulses per millisecond and  it seems unlikely to me that code from init finish to read count will take even a single milli-second to run.

    You don't mention what your constant read values are, that may be an important piece of information. My first guess would be zero.

     

    Robert

  • Beyond Robert's well thought comment - quick look @ your code shows:

    //Configure the pin for QEI
    //
    GPIOPinConfigure(GPIO_PG0_PHA1);
    //
    //Set the GPIO PIN to QEI type
    //
    GPIOPinTypeQEI(GPIO_PORTG_BASE, GPIO_PIN_0);
    //
    //Initial Disable the QEI module
    //
    QEIDisable(QEI1_BASE);
    //
    //Configure the QEI
    //
    QEIConfigure(QEI1_BASE,(QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP),0xF9F);

    Note that only one MCU pin has been employed in service of QEI (GPIO_PG0_PHA1) and that you then seek to, "QEI_CONFIG_QUADRATURE" - that combination (one pin & quad config) seems incorrect. (certainly unusual)

    From your MCU manual, QEI Section 21.3, "The QEI module interprets the two-bit gray code produced by a quadrature encoder wheel to integrate position over time and determine direction of rotation.   In quadrature phase mode, the encoder produces two clocks that are 90 degrees out of phase; the edge relationship is used to determine the direction of rotation." 

    From where did you source such code?  And - a link to encoder data-sheet would assist.  While Robert/I (likely) have cap & pipe (a la - one S. Holmes) landscape here is littered w/(long charred) chip bodies, smoke/(fog) - and many call...

  • Hi Robert

    Thanks for response.

    velcount = QEIVelocityGet(QEI1_BASE).This "velcount" is constant ,even after change the speed of the fan.It supposed to change ,after change the speed of the fan as per my understanding but its not changed.Where could be the issue?

    Thanks & Regards

          Durga

     

  • Hi

    Thanks for your respone.

    Our FAN hard-ware having 4-Wired(+ve,-ve,PWM input and F.G signal).Our MCU has 4-gpio pin reservered for fan ,one for +ve,one for  -ve ,one for PWM input and one for F.G signal  input for QEI .According to you ,for QEI initialization and configuration needs 2-GPIO pin .is it correct ? if yes ,our MCU doesn't have extra GPIO pin .That means our mcu can't handle the QEI module.Or any other way to do for calculating the speed of the fan.Could you please help me?

    Thanks & Regards

             Durga

     

  • OK, several thing Durga

    • You definitely have it wired wrong.  Quadrature encoders have two outputs.  These outputs are out of phase in order to provide both direction and speed indication. Depending on whether the QEI inputs implement cross channel filtering you might see a count change (If they implement filtering you will not).  Even if you do see a count change the sign would be indeterminate, it could be either positive or negative.
    • If you only need speed indication there is no need to use a quadrature input, a counter will do the job just as well.
    • You initialize the converter before you read it's value every time, why would you expect to get a valid value?  Effiectively your code does
      • count = 0;
      • velcount = count;
    • This method of reading the value will not work with a counter either

    A QEI is effectively just a slightly more complicated counter. 

    I suggest you read up on quadrature encoders and probably the QEI documentation.

     

    National instruments has an introduction to quadrature encoding although it does not include the cross channel filtering needed to prevent extra counts at rest.

    http://www.ni.com/white-paper/7109/en/

     

    Robert

  • cb1_mobile said:
    Note that only one MCU pin has been employed in service of QEI (GPIO_PG0_PHA1) and that you then seek to, "QEI_CONFIG_QUADRATURE" - that combination (one pin & quad config) seems incorrect.

    Thus latest commentary is derivative from this far earlier posting.  

    Advice offered is sound and highlights the need for, "some attention to detail" demanded by more complex, MCU peripherals. 

  • Hi

     Sorry i am not able get.I gone throug the data sheet but i am little bit confusion.Could you  please explain me detail?

    I want to calculate only RPM,using the formula as per the data sheet.I don't want  position and direction  of fan.

    RPM depends on velocity.In my case velocity is not changed even after change the speed of the fan.The speed of the fan is controled by the PWM.

    Is two input(PhA1 and PhB1) required for 2-channel encremental encoder for RPM calculation?

    do i need to configure two GPIO pin for PhA1 and PhB1 for get only velocity  for calculating the RPM?

    Sorry i am new to this module.If you help ,it will be be great for me.

     

     

     

  • Druga as we have both pointed out the connection is wrong for a quadrature endcoder.

    However since you do not need to know direction, then you can simply use a counter.  Can you configure the input you have the sensor feeding into as a counter rather than a quadrature input.  I would expect that you could but I've been surprised by configuration restrictions before.

    If you expect to need direction in the near future then it is worth struggling through the quadrature setup (including fixing your wiring) otherwise don't bother. It's not doing you much, if any, good.

    Robert

  • Hi Robert

        There is no available API in Tivaware to configure the pin as counter.Is there any way to configure this pin?

    Thanks & Regards

                Durga

  • Durga, a brief look at the documentation suggest to me that all the pins that either phase input of the QEI input can be mapped to can also be mapped to timers and the timers support counting in one of the capture modes.

     

    I have not used the timers in this mode so someone else may be of more help any specifics on that.

     

    Robert

  • Only certain pins w/in any of the MCUs here may be placed w/in "Timer Mode."  Best to survey the Timer chapter w/in MCU manual - usually a complete listing of all (potential) Timer pins will appear.  It may well be that your QEI pin cannot "alternately function" as a timer...

    You must then review the multiple uses of the timer - it is possible to set-up/config as a counter.  It may prove far simpler to employ two timers - one to accumulate the encoder counts - the second to enable that timer-counter for a select time interval.  When that interval expires - you read the timer-counter's value.  Timer-counter is first cleared prior to its enabling. 

    Experimentation via "reduced" frequency - input pulses will prove helpful.  You first must "prove" that you can successfully count.  Then - by enabling that counter for a precise time interval - its straightforward to calculate the counts per unit time.  (i.e. the count rate)  Really are no short-cuts - you must put in the time/effort as presented by Robert & this reporter...  (we surely have...)