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.

TMS570LC4357: QUADRATURE PULSE GENERATOR

Part Number: TMS570LC4357
Other Parts Discussed in Thread: HALCOGEN

sir now i need to find speed  , in quadrature pulse generator providing  input  to  pin epeqA  and  epeqB   , how  to find speed  what will be  configuration should be in halcoGen  ,  input is  tiime period  20millisecond , frequency is 50 hz  , i attach my code , for that  what configuration we should , will u help me 

#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"
#define UART sciREG1
#define clkfreq 75000000
#define PPR 30U
uint16 data_buffer[10];
void sciDisplayText(sciBASE_t *sci, uint16 *text, uint32 length);
uint16 eqepReadCapturePeriodLatch (eqepBASE_t *eqep);
uint32_t posCountValBef;
uint32_t posCountValAft ;
uint16 deltaT = 0U;
uint8 pi = 3;
uint8 D = 1 ;
uint8 circumference ;
uint8 velocity = 0;
uint16 frequency ;
uint16 RPM= 0;
uint16 Distance = 0;
uint16 speed = 0;
uint16 period ;
uint8 direction;
uint16 status;
uint16 time_period ;
void wait(uint32 time);
#define INDEX 10
/* 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) */

/* USER CODE END */

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

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

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

/* Enable capture timer and capture period latch. */
eqepEnableCapture(eqepREG2);
/* Read the position counter value before the index event */
posCountValBef = (uint16)eqepReadPosnCompare(eqepREG2);
/* Status flag is set to indicate that a new value is latched in the QCPRD register. */
if((eqepREG2->QEPSTS & 0x80U) != 0U)
{
period = eqepREG2->QCPRDLAT;
deltaT = eqepREG2->QCPRD;
posCountValAft = (uint16)eqepReadStatus(eqepREG2);
velocity = (PPR / deltaT);
/* Assign value in period register into period variable */
circumference = (double) (D * pi); /* cirumference of wheel ,convert Diameter into meter then used */
frequency = (uint16)((1000000U)/(uint16)(time_period)); /* to convert microsec to sec */
RPM = (uint16)((frequency * 60)/ PPR); /* multiply of 60 for convert sec into min */
Distance = (uint16)(( circumference * RPM )/60); /* divide 60 to convert Min to Sec */
speed = (uint16) (( RPM * circumference *60 )/1000); /* Multiply of 60 to convert min into hour & divide 1000 for m into Km */
/* Read the position counter value after the index event */

if (posCountValAft > posCountValBef) {
direction = 1; /* Direction is farward */
} else {
direction = 2; /* Direction is backward */
}

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

thank you 

jeeva

  • Hi Jeeva,

    You calculated time period right, from that you can easily calculate the frequency(1/T). And now from frequency you can easily calculate the speed or velocity of the motor.

    Velocity = Frequency for Minute / (Encoder lines * 4)

    As you can see in above example, the frequency is 400Hz and 500-line encoder motor they are using right, so 

    Velocity = 400*60/(500*4) = 12 RPM.

    So, try to calculate in the same way.

    --
    Thanks & regards,
    Jagadish.

  • ok sir , i will share my halcogen configration as well as code also   in this cannot able to upload file , what shall i do , if i click insert option then upload if press , file /URL is    not  allow  like this notification is getting

    thank you 

  • dear sir i email u  source file and  halcogen please find that respose as soon as possible it is my request sir

    thank you 

    jeeva

  • Hi Jeev,

    Can you send through private chat?

  • 4048.HL_sys_main.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    /** @file HL_sys_main.c
    * @brief Application main file
    * @date 11-Dec-2018
    * @version 04.07.01
    *
    * This file contains an empty main function,
    * which can be used for the application.
    */
    /*
    * Copyright (C) 2009-2018 Texas Instruments Incorporated - www.ti.com
    *
    *
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    *
    * Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer.
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    quadrature.c.docx

    sir halcogen file is not supporting so i made in word document and i have sent

  • Just try to zip entire project and attach it?

  • Quadrature_pulse.zip

    in that source file  main.c  have source code and quadrature.HCG  

  • 3858.Quadrature_pulse.zip

    in that source file  main.c  have source code and quadrature.HCG

  • Thank you Jeev, I will test it and will provide you an update ASAP.

  • dear  sir  i have  code  and  halcogen  pass two days back , u told that will test  and  update , but still no update get sir , due that   quadrature speed calculation  is  pending  sir , please response as  much  as   possible .

  • Hi Jeev,

    First of all, apologies for the delay, i was stuck with some other important issues as well.

    I understood why you are getting different results for delta period in debugging. This is because we should not measure the values in debug, If you set the breakpoints and try to measure the period register value, then only first value will be correct if you kept the breakpoint and run it then on second iteration you won't get the correct value, this is because at breakpoint the input quadrature pulses will not get stop they will keep on running the eQEP module so the period register value will increase even at the breakpoint also, and after you click run some random value will be in the period register and that will get moved to the period register.

    And i also created one example project:

    1. In this project what i did was i created Quadrature waveforms of frequency 50Hz with 90 degrees phase shift using RTI and GIO modules. Here what i did was i divided 20mS(50Hz) period into four parts and each part of 5mS

    At first 5ms i am toggling GIOA0, at second 5ms i toggled GIOA1, third 5mS i toggled again GIOA0 and at forth 5ms interval i toggled GIOA1. In this way i just created a quadrature waveforms of 50Hz frequency and 90 degrees phase shift.

    2. Now i connected these quadrature waves generated on GIOA0 (A5) and GIOA1 (C2) to the EQEP2A (V2) and EQEP2B (U1) respectively.

    3. And i also modified the code in such way that, i calculated the delta period in microseconds and after that i am calculating the speed in RPM.

    4. After this i did the debug:

    You can see the correct values of the deltaT and speed in RPM after the first hit of the breakpoint

    I got the deltaT value as 5000uS that means 5mS, this is because as we discussed we are applying 20mS quadrature waveforms right that means QCLK will become 5mS and we captured the same period exactly.

    Now using that period, we can easily calculate the RPM of the motor using the given formula. Here i got the RPM as 3000 because i am considering encoder lines as 1 that means for every period of quadrature waveform(QA or QB), i am considering motor rotating 1 revolution. that means as we are applying 50Hz of frequency right so 50 revolutions per second that means per minute the revolutions will become 3000 (50*60).

    I am attaching my code for your reference:

    eQEP_TEST_LC4357.zip

    Remember if you set the breakpoint after period register then only first iteration you will get the correct value, you can do one thing you can remove the breakpoint and keep it in the continuous run and you can suddenly set the breakpoint then you can get the correct results again.

    --
    Thanks & regards,
    Jagadish.

  • dear   sir  (1) if  i  use capture prescaler  value as  128  will it  change  input  what  iam giving  from  quadrature pulse generator , 

    (2) then  iam  quadrature pulse generator as  30 PPR ,  so iam using  formula for RPM =  (frequency *60)PPR  .  its  ok  va sir  beacuse i do no encoder line ,  resolution .  sir if  i use your  formula  what  you used  for calculate speed_RPM  then for encoder line and resolution value will be  same or differ .

    thank you for ur  response 

    jeeva

  • Hi Jeev,

    (1) if  i  use capture prescaler  value as  128  will it  change  input  what  iam giving  from  quadrature pulse generator , 

    Capture prescaler will not change input what you are giving, If you change the capture prescaler value then it will change the capture clock that applied to the capture unit as highlighted below.

    It won't change your input quadrature pulse but it will affect your measured capture period, that is why you should consider this capture prescaler value also for period measurement as below:

    (2) then  iam  quadrature pulse generator as  30 PPR ,  so iam using  formula for RPM =  (frequency *60)PPR  .  its  ok  va sir  beacuse i do no encoder line ,  resolution .  sir if  i use your  formula  what  you used  for calculate speed_RPM  then for encoder line and resolution value will be  same or differ .

    Actually, PPR is inversely proportional with RPM.

    I mean the formula is below.

    RPM = (Frequency * 60) / PPR

    See, in our previous case we applied 50Hz waveform and we got RPM as 3000, right? In this case i considered PPR as one, that means 1 pulse for every revolution.

    But consider if we have 2 pulses for revolution, that means we will get two pulses for every revolution, and we are getting overall 3000 (50*60) pules in a minute right so that our RPM will become 1500 only.

    And also, please note this, in my code i gave one directive called "ENCODER_LINES" right?

    This encoder lines nothing but PPR only, you can give your required PPM at this directive itself to get correct RPM.

    --
    Thanks & regards,
    Jagadish.

  • dear sir  after  executing  the   code  and  halcogen set up  what  u send ,  but even though its  not giving  correct value  one time also , if i give  input by set RPM  100   quadrature  generator  practically it should   give   frequency as 50 Hz  and   time period in microsecond it should get 2000 but instead of that its giving 2222, 24448, 600 , like this  value its giving for  50 RPM its giving  0 ,88, 5  instead  its should get 4000 ,  should i need to change any halcogen set up sir , otherwise any change in code . tell me sir  as soon as possible 

    thank you sir 

    jeeva

  • Hi Jeev,

    No changes required in the code. You can see my results with 50Hz quadrature waveforms which are generated internally with RTI module right?

    There you can see the perfect values. If you are using mu code and not getting proper results means then it should be input issue.

    or else you just copies my .c code into your project then you should also make sure the HALCoGen configurations as well, i made little changes there.

    Please make sure above things then definitely it should work.

    Thanks & regards,

    Jagadish.

  • Dear  sir  in  controller board  i have oin GIOA_0  pin  but  no GIOA_1  so instead of  that iam  try to use GIOA_2  , if  condition of status  is not  allow  to go into  inside . In this should i check ur code .  then  halcogen what u   sent  same thing  only iam using , nothing  i changed .  If  quadrature pulse generator  is  getting  perfect , i check through  oscilloscope also , after giving  to controller in  driver code  register value is not getting  properly , make sure u will response soon , its my request  sir

    thank you & regards,

    jeeva

  •      i have attached  schematic  of  controller which one iam using .  instead  of  that iam trying  to  use  pin 36  gioA_2  bt no use

  • Hi,

    Use J4 header 9 and 10 pins as highlighted below.

    I used these pins only from my launchpad. I connected J4-9(GIOA_1) and J4-10(GIOA_0) with the J10-22(EQEP2B) and J10-21(EQEP2A) respectively. Please try to do the same at your end.

    --
    Thanks & regards,
    Jagadish.

  • dear sir  after conneting  respective  pin which u said  previous thread , i getting  value in deltaT (micro sec) is  102381,40425,44289,70097,58419  , next   while  debuging  if if condition i can able to do only time iteration , second time if try to its not  allowing to inside if condition ,  after closing debug and then if u start to do debug  then only  its allowing me to if condition . iam using same halcogen setup and code also , nothing i have changed .  please reply as much possible sir ,

    thank you,

    jeeva

  • what sir no reply from  u  

  • Hi Jeev,

    I am really confused with your results.

    Are you really using my code?

    Either your testing process or code you took might be wrong!

    I did one screen recording (From the downloading code to the debugging) and please follow the same process.

    --
    Thanks & regards,
    Jagadish.

  • dear sir ,  now  its getting 5000 deltaT  and 3000 speed , while keeping  break point  i need misstake ,  iam  sry sir ,  

    but  same code  instead of  gio and  rti  iam giving  input from  quadrature pulse  generator to epeq2A  and  eqeq2B ,  by setting  RPM = 100  and  giving generated pulse , frequency should get 50 hz , time period "deltaT"  is  2000 should get in micrsecond instead of  that iam getting 5555, 3367, 590, like  this value is gettiing , halcogen and code same iam using  what u  suggested , except gio and  rti position .  If  need i sent screen record also , please make what i did mistake  reply as  soon as posible ,

    thank you ,

    jeeva

  • dear sir  i will attach two video file  one  is  haalcogen and  other one  is  code  and  debug section , please response fast its  my humble request 

    thank you,

    jeevaScreen Recording - Made with FlexClip (1).zip   sir  in  this  i have  set  RPM  as  100  and  gave  pulse to pin eqep2A and eqep2B ,  actually  time period  i should get  2000 in micro second instead  of  that  getting  wrong value  while debuging , please  response fast sit,

    thank you,

    jeeva

  • dear  sry for disbance  , till now  no reply i from   ur .please  fiind  value    and give  me    its  .  corect   value 

  • Hi Jeev,

    but  same code  instead of  gio and  rti  iam giving  input from  quadrature pulse  generator to epeq2A  and  eqeq2B ,  by setting  RPM = 100  and  giving generated pulse , frequency should get 50 hz , time period "deltaT"  is  2000 should get in micrsecond instead of  that iam getting 5555, 3367, 590,

    If you apply 50Hz signal from quadrature pulse, then you will also get 5000 delataT only.

    Actually, for 50Hz signal the time period is equal to 20mS right but as resolution will increase by 4 times, we should get only 5mS value that is 5000 deltaT.

    In your results the first value of 5555 is closer to the 5000 only i mean it looks like correct, actually it is depending on the accuracy of the input. If your input is accurate then you should get exactly 5000 like what we get in RTI case. I am also suggesting you make sure there is a common ground between our TMS570 board and your pulse generator.

    And please don't do step by step debugging and don't consider those values. Please once again watch the screen recording video i shared to you, you can verify how i am verifying the second iteration value (remove breakpoint keep it run in continuous and set break point in run time).

  • sir  i  did  debug how   u  did  in video  which u sent ,  my excepted value  is  for 200 RPM  frequency is   100 Hz   means time period  should get 10 milli sec , if  its 4 time also  its 40000 micro second  in deltaT , instead something different is  getting , i will attach video of  debug 

    thank you,

    jeevaScreen Recording - Made with FlexClip (2).zip

    this  one  clarify  enough for me , reply fast sir , today i need to report  for  this project 

    thank you ,

    jeeva

  • Hi Jeev,

    I saw your video and you are not doing as i mentioned.

    sir  i  did  debug how   u  did  in video  which u sent ,  my excepted value  is  for 200 RPM  frequency is   100 Hz   means time period  should get 10 milli sec , if  its 4 time also  its 40000 micro second  in deltaT

    And your expected deltaT is also wrong, you won't get 40000 value for 100Hz frequency.

    See first understand what is deltaT

    deltaT is the time period between two QCLK pulses.

    If you apply 100Hz quadrature pulses then please calculate QCLK period, it is 2.5mS only. So your deltaT value in this case will become 2500 only. And as i can see your first value it is 2757 it is closer to the 2500. But still you are not debugging as i mentioned, you are just keeping the breakpoint at one place and you are running then you won't get correct values. You didn't watch the screen recording i shared properly.

    If you still have confusion lets plan one live debugging session on tomorrow and i will explain there. Please share your meeting ID.

    --
    Thanks & regards,
    Jagadish.

  • once i will try sir , even though if  i  confuse  means  as  per u should  live debug we will make it sir , thank you very much for support  sir ,

    thank you,

    jeeva

  • dear sir  i have  took  some reading  from quadrature  pulse generator  that excel sheet i  will share u sir , but  not getting accurate value , after making common ground , some how  closer to that value was getting , how  i need to  find distance  and  direction  how should make for distance i will formula D = circumference * RPM ( no of rotation) , for find direction iam trying using  status register some time its giving correct value some time wrong  . please help  me sir ,  

    thank you,

    jeevaSPEED SENSOR RPM COMPARISIONS.xlsx

  • Hi Jeev,

    i have  took  some reading  from quadrature  pulse generator  that excel sheet i  will share u sir , but  not getting accurate value

    It just depends on the accuracy of the input waveform to the eQEP module. You saw the results when we applied the waveforms from RTI module right. If your input is accurate then you will get accurate results.

    how  i need to  find distance  and  direction  how should make for distance i will formula D = circumference * RPM ( no of rotation) , for find direction iam trying using  status register some time its giving correct value some time wrong 

    I think you should not consider applied RPM in the speed measurement.

    So, i just added one more column called measured RPM, this is calculated based on the practical value of the deltaT and i used this RPM in the speed measurement.

    And you will get direction from the QEPSTS[QDF] bit.

    1856.SPEED SENSOR RPM COMPARISIONS.xlsx

    --

    Thanks & regards,
    Jagadish.

  • For  indication  iam  status register 

    const uint8_t QDF = 0; // Assuming QDF is a bit flag within QEPSTS register

    if(eqepREG2->QEPSTS & (1 << QDF))
    {
    uint8_t direction = 1; /* forward direction */
    }
    else
    {
    uint8_t direction = 2; /* Reverse direction */
    }

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

    but  logic  is  fine  sir , but getting  only one  register its  not  changing  sir  if   exchange epe2A epep2B  

  • distance = circumference * measured RPM  it  righr or  wrong  sir

    thank you ,

    jeeva

  • Hi Jeev,

    const uint8_t QDF = 0; // Assuming QDF is a bit flag within QEPSTS register

    if(eqepREG2->QEPSTS & (1 << QDF))

    Why are you verifying 0th bit in the QEPSTS register for QDF flag?

    It is 5th bit, right?

    Please modify your code as below:

    if(eqepREG2->QEPSTS & (1 << 5))
    {
    uint8_t direction = 1; /* forward direction */
    }
    else
    {
    uint8_t direction = 2; /* Reverse direction */
    }

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

    Use above code and test it.

    distance = circumference * measured RPM  it  righr or  wrong  sir

    Right.

    --
    Thanks & regards,
    Jagadish.

  • dear  sir  after iam  testing  and  also getting  same  output  ,  even if  change  pin also  default  getting   1  only after going  modification , i share  screen shot  of  debug

    Thank you ,

    jeeva

  • what  sir no reply ,

    thank you,

    jeeva

  • Hi Jeeva,

    I tested at my end, and it is working:

    Before reversing the eQEP pins (Forward direction):

    After reversing the eQEP pins (Reverse direction):

    I didn't add any additional changes except the direction code to my old code:

    4353.eQEP_TEST_LC4357.zip

    --
    Thanks & regards,
    Jagadish.

  • Thank  you very much sir  it getting , because  of  u  only sir i can able  to complete this project . thank you for your  great support ,

    thank you ,

  • Hi Jeev,

    It's my pleasure to help you. Good to hear that you made it.

    Please click on "Resolved" button for all quadrature issues.

    --
    Thanks & regards,
    Jagadish.