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.

TMS320F28335: Adding EPWM in my working code for sometime as START UP signal for my connected hardware

Part Number: TMS320F28335
Other Parts Discussed in Thread: C2000WARE

Dear Community members,

I posted a thread some days ago related to my EPWM, ECAP and pid routine code implementation where EPWM is a major concern. This thread was resolved and my code is working too for a task.(Please find the code below). This time I need to change a little bit. 

Firstly I want the ePWMA & ePWMB to be run fiirst for some time around 2-3 sec, 

Then it  must shift to my NORMAL WORKING CODE which is running good (where eCap takes the signal from the function generator in terms of Period or duty cycle and then it process the while loop for my pid routine code in the main function and then generates the ePWM signals accordingly at one time).

The reason for doing this is to generate a startup ePWM signals for 2-3 sec first without capturing signals so that the connected hardware will run smoothly for some time and then after 2-3seconds, the startup signal should STOP and start taking the signals from the functions generator using eCap. 

Problem is that I am confused where I should add this startup ePWM routine code in my main function (I guess just after the Setup_ePWM1(); Line 85) and then put some delay for 3 seconds, After this delay,  startup ePWM routine code will never run again because the startup signal would have initialized the connected hardware and then it must move/shift to my normal working code for further instructions(ecap>pid_while_epwm all at one time). (Remember: this startup signal must run one time and it shouldn't be executed again.)

For delay, I guess delay(...); is used in terms code.

Working Code is attached here:

Please suggest accordingly

Kind Regards

Arsalan

  • Hi Arsalan,

    I should add this startup ePWM routine code in my main function (I guess just after the Setup_ePWM1(); Line 85) and then put some delay for 3 seconds, After this delay,  startup ePWM routine code will never run again because the startup signal would have initialized the connected hardware and then it must move/shift to my normal working code for further instructions

    That would be a good approach to do it since anything outside of the while loop should just be ran once. After you setup your ePWM you can call the startup routine.

    Remember: this startup signal must run one time and it shouldn't be executed again.

    Anything before the while loop will only be ran once ,adding the delay should solve your problem.

    Best,

    Ma

  • Hi Ryan,

    Thanks for your reply. Always helpful !

    I tested my code (please find attached below). For delay,  I use "For loop" from Line 90-Line 129 for the startup ePWM signals just after the initilization of epwm(Setup_ePWM1,2();). and the next line after For Loop is the eCap initiallization(Setup_eCap();.

    Result: I got PWM signals first as a startup after debug (green button). Then I turn on the function generator to capture the signals for my normal working tasks(ecap->pid->pwm). This works fine. Thanks.

    Question is for my For Loop,

    for(j = 0; j<90000; j++);... choosing a value for 90000 means how many seconds of delay? because i tried several values for j and not all values works in the loop. I need only 3 seconds of delay. so how can I calculate this j value for 3 secs? 

    Also,  can you suggest the delay routine or function lines in terms of code for generating delays? I have never used the delay function before in programming. I can have an option to use delay function instead of For Loop.

    The code is attached here:

    Please suggest accordingly.

    Regards

    Arsalan

  • Hi Arsalan,

    how can I calculate this j value for 3 secs?

    Instead of using this for loop where the 3s calculations may vary, have you tried using this macro defined in the C:\ti\c2000\C2000Ware_x_xx_xx_xx\device_support\f2833x\common\include\DSP2833x_Examples.h called DELAY_US()?

    An example that uses this delay is under C:\ti\c2000\C2000Ware_5_00_00_00\device_support\f2833x\examples\sci_autobaud\Example_2833xSci_Autobaud.c

    Best,

    Ma

  • Hi Ryan,

    Thanks for your reply.

    From the examples: C:\ti\c2000\C2000Ware_5_00_00_00\device_support\f2833x\examples\sci_autobaud\Example_2833xSci_Autobaud.c

    where L stands for nano seconds for clock rate ( Like 150MHz , 6.67L>6.67nano seconds) . So in my code I use this function DELAY_US(3000000000L); -> for 3 seconds.

    Firstly this gives me warning. 

    Secondly, this function DELAY_US(3000000000L); I am using just after the startup PWM signals generation in the main function. The oscilloscope shows the startup PWM signals but it doesn't follow the time of 3 sec. after that I need to stop this signal or turn off my startup ePWMs. (for this I need to write some code to deactivate the ePWMs just after the DELAY function DELAY_US(3000000000L);  Could you please suggest how can I do this to deactivate epwms? After that it must shift to my further routine code (setup eCap--pid while loop..epwms etc...).

    the code is attached here:

    Please suggest accordingly.

    Thanks

    Arsalan

  • Hi Arsalan,

     DELAY_US(3000000000L);

    The warning is because you're giving a value that is too large. If you are wanting a 3s delay, you can try this

    DELAY_US(3000000L);

    Please set a breakpoint at this line, and as you step over it, record approximately how many seconds have passed for it to go to the next line. This should give you ~3s delay after PWM initializaiton.

    Could you please suggest how can I do this to deactivate epwms?

    Yes, you can turn off your PWMs using a software one shot trip after you finish the 3s delay to turn off PWMs. Please look at the Example_2833xEPwmTripZone.c located in the C2000WARE

    Best,

    Ma

  • Hi Ma,

    Thanks for your reply.

    Please set a breakpoint at this line, and as you step over it, record approximately how many seconds have passed for it to go to the next line. This should give you ~3s delay after PWM initializaiton.

    The delay function works at breakpoint and I can note down the delay. 

    Yes, you can turn off your PWMs using a software one shot trip after you finish the 3s delay to turn off PWMs. Please look at the Example_2833xEPwmTripZone.c located in the C2000WARE

    I will check and work on this part soon. For the time I am resolving this issue.

    Thanks

    Regards

    Arsalan