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.

LAUNCHXL-F280049C: ePWM

Part Number: LAUNCHXL-F280049C
Other Parts Discussed in Thread: CONTROLSUITE, C2000WARE

Hi Team,

We would like to ask your help regarding this inquiry that is related to the E2E thread below.

e2e.ti.com/.../launchxl-f280049c-launchpad-for-foc-application

According to our customer,
With your help I have solved many problems. Now I have a new question
For my control loop, I must use determine quantity of ePWM signals to drive the stepper motor. 
I still do not find how to generate determine quantity of signals, in particular, every loop, it may generate a different number of ePWM signal.
 
Please give me some advice.
 
and this function
#define DELAY_US(A)  F28x_usDelay(((((long double) A * 1000.0L) / (long double)CPU_RATE) - 9.0L) / 5.0L)
is there a corresponding mathematical formula?
Regards,
Danilo
  • Hi Danilo,

    Our expert will get back to you on this issue by monday.

  • Let's look at the two different questions:

    1. The question below, Are you trying to generate a SET number of PWM pulese?

    For my control loop, I must use determine quantity of ePWM signals to drive the stepper motor. 
    I still do not find how to generate determine quantity of signals, in particular, every loop, it may generate a different number of ePWM signal.

    2.A re you trying to see how the math in this function works?

    and this function
    #define DELAY_US(A)  F28x_usDelay(((((long double) A * 1000.0L) / (long double)CPU_RATE) - 9.0L) / 5.0L)
    is there a corresponding mathematical formula?
  • DELAY_US(A)  F28x_usDelay(((((long double) A * 1000.0L) / (long double)CPU_RATE) - 9.0L) / 5.0L)

    This function F28x_usDelay was written in assembly and all of the delay caused by the SW overhead was calculated. Thats how the 9 and 5 were deternined. There is a short description of it in the SW files.

  • I will let respond to your motor control question.

  • For my control loop, I must use determine quantity of ePWM signals to drive the stepper motor. 

    What algorithm and example codes are you using? Why do you need to know the quantity of ePWM signals to drive the stepper motor?

    Generally, we use a fixed PWM frequency to implement the motor drive including the stepper motor, and the quantity of ePWM signals will be variable according to the running speed of the motor.

    You may refer to the example code for stepper motor in controlSUIT, although the example is based on F2803x.

    C:\ti\controlSUITE\development_kits\DRV8412-C2-KIT_v131\Stepper

  • Hi Yanming,

    Please see the response of our customer below.

    Hello, Thanks for reply. 
    yes, I am trying to generate a SET number of PWM pulse.
    I use the powerSTEP01 as driverboard, which is by STMicroelectronics produced. That is most used for open loop control.
    To achieve the FOC logic, the driveboard must be controlled in Step-clock mode. 
    Only in the step-clock mode can the stepper motor runs like synchron motor.
    The current Amplitude will be direct set, and the driverboard will output 2 phase current. Herne, the current electrical position is the second controlled value, to maintain the load angle is pi/2.
    [Step-clock mode: In Step-clock mode the motor motion is defined by the step-clock signal applied to the STCK
    pin. At each step-clock rising edge, the motor is moved one microstep in the programmed direction and absolute position is consequently updated.]
     
    The FOC process:
    1. read the Motor physical rotor position using the eQEP mode
    2. calculate the rotor electrical position, and it is expressed in microsteps, as RP
    3. according the motor direction calculate the current electrical position(CP) to maintain the load angle(LA) is pi/2, both are expressed in microsteps. 
    4. update the current electrical position to target position (CPt), using very high frequency epwm signals, I use 1MHz, at the 1MHz, the current electrical position can be changed but the rotor dose not response. After the current reach the target position, the load angle is pi/2, then the rotor will rotate because of the torque. Then the program runs into next control loop.
     
    every control loop, the program will calculate the rotor electrical position(RP), target current electrical position(CPt) and refer to the actual current electrical position(CP), and at last, calculate the ST=CPt-CP, the ST represent the differential electrical position, which is expressed in microsteps.
    Hence, the program must generate a set number of ePWM signals to update the current position in every loop. And the value must be precise.  
    Have you understood my inquiry?
    Regards,
    Danilo
     
  • Are you using a fixed frequency PWM? and what's the duty cycle of the PWM? Will the duty cycle be changed according to control loop? Is the PWM output used for the FET gate driver of the stepper motor power module?

    You can refer to the example ex2, 3, 11, or 13 in C2000Ware to set the period or compare registers to achieve the ePWM signals desired frequency and duty.

    C:\ti\c2000\C2000Ware_<version>\driverlib\f28004x\examples\epwm

  • Hi Yanming,

    According to our customer,

    For my project, the PWM signals are used to change the electrical Position in Motor.  The PWM output is not used for the FET gate driver of the stepper motor power module, the corresponding function is by a driver board achieved.  I use a fixed frequency PWM with 50 duty cycle, which will be not changed in control loop.

    The ePWM Mode in C2000 have be configured and it can now output a PWM signal with a fixed frequency.

    I have read all example code, and also read the Application Report ”Sensored Field Oriented Control of 3-Phase Permanent Magnet Synchronous Motors Using TMS320F2837x”. However, the FOC loop I used is different because the different Hardware.

    I have tried many ways but still I do not find a algorithms to generate a set number of PWM signals.

    Ideal the CPU runs a timer code, and the number of PWM signals is proportional to time period.

    I have tried use the code  “DELAY_US(A)”  as a Timer to generate the PWM signals, but the A must be a constant, yet the number of PWM signals is not constant, the value will variate in [0,31].

    If A is a variable, the code DELAY_US is not usable.

    Regards,

    Danilo

  • Does the customer have any example waveform to show what they need? They may enable the ePWM interrupt directly to count the number and then turn off/on the output, which can generate the exact the number of PWM signals.

  • Hi Yanming,

    Here is the comment of our customer.

    Thanks for the quickly reply.

    The picture is my requested PWM signals. The number of PWM signals is the key, and it is not constant.

    the PWM output is turned off/on through enable/disable the EPWM Clock, it that right?

    Ok, I will try again the ePWM interrupt. But how to count the number? I do not find such a code. In the example code the ePWM interrupt function realize change of duty cycle.

    Regards,

    Danilo

  • the PWM output is turned off/on through enable/disable the EPWM Clock, it that right?

    You may take a look at the example as mentioned above. You can count the number of PWM signals, turn on/off the PWM output in the ISR. You can fix the PWM duty with 50% by setting a value like half of the period value (TBPRD) to CMPA/B withouting changing again.

    C:\ti\c2000\C2000Ware_<version>\driverlib\f28004x\examples\epwm

  • Hi Yanming,

    I received another follow up inquiry from our customer.

    about generate a particular number ePWM pulses
    I have found a new way. configure CLB as a Counter, when a particular number ePWM pulses is created, the CLB generate a signal to cut off the ePWM mode. 
    I have read the CLB Tool Users Guide.pdf and some example code, but the code of CLB is unlike the ePWM example.
    Could you give me some advise, which necessary code are needed to configure the counter? 
    I want ePWM2 output pwm signals to CLB Counter, after counting, then CLB feedback a signal to mein "main" function. 
    Regards,
    Danilo
  • I dont' think it's necessary to use the CLB. The required PWM should be easy to generated by EPWM module directly.

    Yes, you can use CLB if you want that can generate more flexible waveform. You can find a few examples in the C2000Ware for CLB includes PWM enhancement function.

  • Hi Yanming,

    as the the comment of your product specialist, I have generated a particular number of PWM signals use Event Interrupt 3.2.
     
    the Code of _interrput is following: 
    Uint16 PulseIntCount=0;
    __interrupt void epwm2_isr(void)
    {
       if (PulseIntCount != 30)
         {
           PulseIntCount++;
         }
       else
         {
           EPWMCLK_Disable();
         }
       //-- Clear INT flag
         EPwm2Regs.ETCLR.bit.INT = 1;
       //-- Acknowledge this interrupt to receive more interrupts from group 3
         PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
    }
     
    the code intend generate 30 pulses, and then close the PWM Clock to shut down the PWM mode.
    But the result is always more than 2 pulse, then means, it will generate 32 pulses. I have tried other number, such as 0, 5, 12, but I got 2, 7, 14 pulse. 
    Is there something missing?
     
    And also you recommend me use Trip Zone submode to close PWM signals.  I have studied the examples. 
     
    The PWM Mode was configured 
     
    //- Configure Trip Zone Mode
       EALLOW;
      //-- Enable TZ1 as one cycle-by-cycle trip sources
       EPwm2Regs.TZSEL.bit.CBC1 = 1;
      //-- Set Trip Zone Action
       EPwm2Regs.TZCTL.bit.TZA = TZ_HIZ;
       EPwm2Regs.TZCTL.bit.TZB = TZ_HIZ;
      //-- Enable TZ interrupt
       EPwm2Regs.TZEINT.bit.CBC = 1;
       EDIS;
     
     
    How can I in the above interrupt function trigger the Trip Zone, I think set a GPIO as TZ1 in the code trigger, but it is unavailable.
    Please give me some advise, thank you.
    Regards,
    Danilo
  • Don't need to enable any interrupt for the Trip Zone, just need to use the follow codes to disable the PWM output

    EALLOW;
    EPwm2Regs.TZFRC.bit.OST = 1;
    EDIS;

    And then use the codes below to enable the PWM output again when need the PWM output.

    EALLOW;
    EPwm2Regs.TZCLR.bit.CBC = 1;
    EPwm2Regs.TZCLR.bit.INT = 1;
    EDIS;

    Or you don't need to enable/disable the PWM output, just need to set the EPwm2Regs.CMPA.half.CMPA  >  EPwm2Regs.TBPRD to force the PWM output to high/low, and then set EPwm2Regs.CMPA.half.CMPA as an active value to enable  the PWM output.

    But the result is always more than 2 pulse, then means, it will generate 32 pulses. I have tried other number, such as 0, 5, 12, but I got 2, 7, 14 pulse. 
    Is there something missing?

    You may change the counting threshold according to get the PWM output pulse you need.

  • Hi Yanming,

    Please see the response of our customer below.

    Thanks for your help, so that I can use ePWM mode successful create a specific number of pwm signals.

    Now I want to use one interrupt epwm2_isr to generate the PWM signals, another higher interrupt, for example, epwm2_tz_isr or timer0_isr to do the control calculation.

    I have read the guide for interrupt nesting and the example code: swpriortized_interrupts_cpu01.

    First, the CPU should entry the interrupt 3.2 epwm2_isr; it runs some code, then entry the higher interrupt 2.2 epwm2_tz_isr.

    I think I should in “main function” set the interrupt 3.2, then in that modify the interrupt 2.2

    I have some questions about the code

    1.  “IER |=M_IN3” and ““IER &=M_IN3”  I am aware, OR operation is setting the bit for the interrupt which need to be enabled, and AND operation is to clear the enable bits for other interrupts. Dose those two lines here conflict?
    2. To entry the interrupt 2 , I think the line should be IER |=M_IN2, not 3
    3. In my opinion, after the “EINT”, the program should entry the higher interrupt 2.2, after that, the program will produce the interrupt 2, which means, my code should be inserted in the area “// Insert ISR Code here…”.  Is that right?
    4. Is those last two lines necessary?

    That will be great, if you have some detailed example codes.

    Regards,

    Danilo

  • Hi Yanming,

    According to our customer,

    Finally, I finished the control loop. There is no need to use interrupt nesting.

    Now I will run some tests, I need the program record or download some state variables when the program runs, then the state variables are plotted over time.

    Is there a component in CCS to achieve that task?

    I have posted this additional inquiry in the E2E link below.

    e2e.ti.com/.../launchxl-f280049c-record-or-download-some-state-variables

    Regards,

    Danilo

  •  “IER |=M_IN3” and ““IER &=M_IN3”  I am aware, OR operation is setting the bit for the interrupt which need to be enabled, and AND operation is to clear the enable bits for other interrupts. Dose those two lines here conflict?

    IER |=M_IN3 -> This enables the current interrupt channel, which hardware disables by default on receiving an interrupt. IER &=M_IN3 disables all the interrupts for which user has configured a lower priority than the current interrupt

    To entry the interrupt 2 , I think the line should be IER |=M_IN2, not 3

    If you have configured the priority levels correctly, the provided piece of code will ensure all interrupts with higher priority is able to nest the lower priority interrupts. User just need to make sure they are using the correct macros. For interrupt x.y, use the macros MINTx, M_INTx, MGx_y, the macros are defined in such a way that all lower priority interrupts would be disabled.

    In my opinion, after the “EINT”, the program should entry the higher interrupt 2.2, after that, the program will produce the interrupt 2, which means, my code should be inserted in the area “// Insert ISR Code here…”.  Is that right?

    Yes, if there is a pending 2.2 interrupt after EINT, it will automatically branch to INT2.2 ISR. In INT3.2 ISR you should have the code for serving INT3.2 only

    Is those last two lines necessary?

    That is added for demo purposes only. This allows users to see the order in which interrupts were serviced

    Regards,

    Veena