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.

Sine-Wave Code and PWM triggered ADC code

Other Parts Discussed in Thread: TMS320F2809, SPRC835

Hi,

My customer is using a Piccolo F28027 series controller for his motor control and Inverter applications.

He has a few queries as below -

1. Customer needs a PWM (internal) triggered ADC code.

2. Generation of Sinewave code for 3 phase and 1 phase applications (like the ones mentioned above).

Thanks

Suman G.

 

 

  • Hi, 

     

    Please advice. 

     

    Thanks

    Suman G. 

  • Hi, 

    Queries about Piccolo as below -

    1. Customer needs a PWM (internal) triggered ADC code.

    2. Generation of Sinewave code for 3 phase and 1 phase applications (like the ones mentioned above).

    Please reply and advice. 

    Thanks

    Suman G.

  • http://focus.ti.com/docs/prod/folders/print/tms320f2809.html#toolssoftware

    http://focus.ti.com/docs/toolsw/folders/print/tmdsenrgykit.html

    http://focus.ti.com/general/docs/litabsmultiplefilelist.tsp?literatureNumber=spraae3

    http://focus.ti.com/docs/toolsw/folders/print/sprc083.html

    http://focus.ti.com/docs/toolsw/folders/print/sprc194.html

    http://focus.ti.com/docs/toolsw/folders/print/sprc215.html

    http://focus.ti.com/docs/toolsw/folders/print/sprc085.html

    http://focus.ti.com/general/docs/litabsmultiplefilelist.tsp?literatureNumber=spru716c

    http://www.ti.com/lit/zip/sprc835

     

  • The latest PMSM Sinusoidal FOC Application Framework is included in the software release for the New Motor Control Kit.

    http://www.ti.com/lit/zip/sprc922

    it's also helpful to install our "Baseline" software to make sure you have all the other documentation and libraries needed to run the projects.

    http://www.ti.com/lit/zip/sprc675

    The example projects with this show both a PWM triggered (acts as main interrupt) ADC SOC and Space Vector PWM driver from the TI DMC Library.  The library modules include all source code, royalty free.

    This project - like all the DMC Application Frameworks - is built using a library of modular C functions that are then connected together with an INCREMENTAL BUILD concept that allows you to compile and debug each step of the control loop (ex: dummy input to verify SVPWM generation; verify ADC sampling; verifty angle estimators; close inner position loop; etc). 

    This concept is thoroughly explained in the documentation that will install at:

    C:\TI_F28xxx_SysSW\MotorCtrl+PfcKit\2xPM_Motors\~Docs

    The Motor Control Libraries and Frameworks also use IQMath, which allows you to quickly tune your system by selecting the appropriate resolution and dynamic range, not to mention allows you to use a single source set for fixed and floating point versions of our MCUs and integrates better with math based simulators and graphical code generators.

    http://focus.ti.com/mcu/docs/mcuorphan.tsp?contentId=51397

     

  • Hi Chris,

    I have take the code from the links you provided and tried to run using native floating point option on an F28335. The code runs fine in IQ, but as soon as I try to run in float, the ADC stops responding.

    Any suggestions as to where to look?

    I have swapped out the fixed point libs with floating versions (IQmath_fpu32.lib, iqDMC_fpu32.lib), and set MathType to FLOAT_MATH.

    Thanks,

    Tim

  • Tim,

    You state that you have swapped the IQMath libraries and changed the math type. Did you also enable floating point support in the Build Options? You can determine this by looking in the Build Options and seeing if the --floating_support=fpu32 is present. If this is not there, please add this and see if this helps to resolve the issue.

    Regards,

    Tim Love

  • Hi Tim L.,

    Yes, I did enable native floating point support in the Build Options. I also changed the rts2800_ml.lib to rts2800_fpu32.lib in the linker tab, under Libraries.

    Thanks,

    Tim

  • Tim,

    Can you describe a little further on how the ADC is not responding? Is it not getting triggered or are you getting samples but they do not have the appropriate response? Also, which specific library are you attempting to migrate? Is it the PMSM project that Chris has mentioned?

    Regards,

    Tim Love

  • Hi Tim L.,

    The project is "2xPM_Motors.pjt" in the "C:\TI_F28xxx_SysSW\MotorCtrl+PfcKit\2xPM_Motors" folder that Chris mentions, but I'm trying to do floating point using F28335.

    The ADC does get triggered, as evidenced by the incrementing ISRTicker, but the value is always 0. Since changing over to the floating point only involves a few lines, I suspect that memory is corrupted somewhere, but I'm not sure where. Hence the ADC no longer functions.

    The code I have modified are:

    #if MATH_TYPE == IQ_MATH
        clarke1.As=_IQ15toIQ((AdcResult.ADCRESULT0<<3)-_IQ15(0.4985))<<1;
        clarke1.Bs=_IQ15toIQ((AdcResult.ADCRESULT1<<3)-_IQ15(0.4978))<<1;
     #else // MATH_TYPE is FLOAT_MATH
        clarke1.As=(float64)((AdcRegs.ADCRESULT0/2.0L)-(0.4985*32768.0))/16384.0L;
        clarke1.Bs=(float64)((AdcRegs.ADCRESULT1/2.0L)-(0.4978*32768.0))/16384.0L;
    #endif

    and

    #if MATH_TYPE == IQ_MATH
     volt1.DcBusVolt = _IQ15toIQ((AdcRegs.ADCRESULT2>>1));
    #else // MATH_TYPE is FLOAT_MATH
        volt1.DcBusVolt = (float64)(AdcRegs.ADCRESULT2/65536.0L);
    #endif

    So I would not have expected ADC functionality to be touched!

    Tim

  • Tim,

    Since this project is based on the Piccolo devices other things will need to be changed in order for it to work on the F28335. The memory map, ADC, clocking, etc are different. The common factor between these is the ePWM. You shouldn't have to change anything for this. But in general you would need to go through the code and replace the F2802x header files with the F2833x, change the memory map, change the clocking, and change any code that is specific to the Piccolo (internal oscillator configuration, interrupts, ADC configuration, etc.). I have done some work on modifying the F280x ACI3_3 library to the F2833x. I think the attachments may be to big for this forum but if submit a request through the support center I will get them to you.

    http://www-k.ext.ti.com/sc/technical-support/pic/americas.htm

    Regards,

    Tim Love

  • Hi Tim L.,

    I will submit a resquest through Support as you suggested. I have the code working for the F28335 in IQ mode but would like to eventually run in native floating mode.

    I will wait for your response after the Support request.

    Thanks,

    Tim

  • Tim,

    I will look for you request and respond. I am a little suprised the project is working with the IQ without any memory, adc settings, etc changed.

    Regards,

    Tim Love

  • Hi Tim L.,

    Sorry for the misunderstanding. I did have to modify all that to get the project working. But once I switched over from IQMath to native float, the ADCs stopped responding.

    Thanks,

    Tim

  • Tim,

    I did receive your service request. I had you request this when I thought you weren't changing the other code. I was just going to send you what I did. You have already done this though. Now regarding changing the IQ calls, you do not need to change any code when switching to floating point. You can leave the IQ conversion calls in there. You only need to change the math type in the header file. Did you try just this without changing any of the IQ calls?

    Regards,

    Tim Love

  • Hi Tim L.,

    I have tried changing just the math type in the header file, but still not getting the output I expect. I then started from the beginning, and see one area where things start to go wrong.

    In the motor example, using BuildLevel1, there is a call to set "rc1.SetpointValue",

    rc1.TargetValue = SpeedRef1;

    I have rebuilt iqDCM_ml.L28 using the FLOAT_MATH define in the header (is this necessary?), and when I check "rc1.SetpointValue", I get zero instead of what I entered in Watch window (i entered 0.25 float for "SpeedRef1").

    If I use the original "iqDMC_ml.L28" with the IQ_MATH define in the header, the value of "rc1.SetpointValue" is 3.42793e-36 with input value of 0.25 for "SpeedRef1" (expecting 0.25 for "rc1.SetpointValue").

    Thanks,

    Tim

  • Hi Tim L.,

    The above was done without using the fpu32 compiler switch in Build Options.

    Thanks,

    Tim

  • Hi Tim L.,

    I found the bug for the above issue. See attachment.

    Thanks,

    Tim

  • As I continue with porting the motor application code to floating point, I discover new mysteries.

    As part of my debugging, I placed the following lines of code into BuildLevel1 right after the call to  ipark1.calc(&ipark1),

    float64    testSine = sin(0.5);
    float64    testCosine = cos(0.5);

    If I now enter a value for ipark1.Qs (0.2), the main loop stops. Re-entering 0.0 for ipark1.Qs allows main loop to run again. If ONLY sin or cos is called, then the main loop is not affected. I have math.h included.

    Anyone have any ideas why this is happening?

    Thanks,

    Tim

  • Tim said:
    float64    testSine = sin(0.5);
    float64    testCosine = cos(0.5);

    I don't know if this is contributing to the problem, but I just noticed - the sin and cos will return a 32-bit float not a 64 bit.

    -Lori

  • Hi Lori,

    Thanks, that was the problem, after changing to float32, the main loop hang problem is fixed. But I was still getting strange values, so I swapped out the iqDMC_ml.28 library with a rebuilt one using FLOAT_MATH define in "IQmathLib.h". This gave me decent values, but I got the 'hang" problem back! So I'm suspecting memory somewhere is getting stepped on again. I will look into that and post what the issue is, after I find it.

    Tim

  • The code now hangs after executing the following line in svgen_dq.c,

    // Convert the unsigned GLOBAL_Q format (ranged (0,1)) -> signed GLOBAL_Q format (ranged (-1,1))
        v->Ta = _IQmpy(_IQ(2.0),(v->Ta-_IQ(0.5)));

    I can't see anything suspicious, yet.

    Tim

  • Upon closer inspection, the problem occurred before the svgen_dc module. It was actually in the ipark module. (It seems some kind of overflow occurred in the svgen_dc module, allowing a memory corruption to stop the main loop.)

    I moved the code in the ipark module to execute inline instead of calling the iqDMC library, and things worked as expected. This same library works in IQ_MATH mode for the ipark calc function. Some kind of stack overflow?