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.

average current control with piccolo f28027

Other Parts Discussed in Thread: CONTROLSUITE

Hello,

i am a newbie to F28027 and i am currently working on an university project i am trying to implement a current control for a flyback converter. Could some please give me a starting point ? like any examples that i can refer in control suite which uses average current ? 

I want to measure the average inductor current so my idea is to trigger the adc soc at middle of the on time like shown in the figure. I want to do this inside the interrupt routine of the PWM can someone please give me an idea on how to trigger the adc soc at the middle of on time or atleast during the rising edge of pwm?

thanks

adcpwm.docx

  • Srinivisan,

    The flyback topology is a pretty basic one we don't often see with C2000.  It's easy to generate the waveforms you need for it.  In your diagram I'm assuming the plot is of primary winding current.  In the attached document I've added a couple of diagrams which I think will help.  The bottom one shows the kind of PWM pattern which I think you want.

    The PWM could be generated using an asymmetric time-base, with CMPA controlling the duty cycle, and CMPC (for example) triggering an ADC.  If CMPC is always kept at half CMPA it will trigger the sample at the mid-point of the PWM ON-time.

    There are many examples in controlSUITE based on F28027.  One which would be a good starting point is "Example_280xAdcSoc" at:

    C:\ti\controlSUITE\development_kits\C2000_LaunchPad\f2802x_examples\adc_soc

    You'll need to configure the PWM pins and setup CMPA to trigger the ADC.  The device documentation will guide you through how to do that.

    Regards,

    Richard

    adcpwm (1).docx

  • Srinivasan,

    By the way, if you haven't already done so, I recommend working through the online version of the Piccolo 1-day workshop, based on F28069.  You can find the recordings here:

    https://training.ti.com/c2000-mcu-1-day-workshop-8-part-series

    Regards,

    Richard

  • Hello Richard

    Thank you so much for your help and suggestions ! Actually I implemented the PI controller with my hardware and the closed loop is working but struggling with some noise issues. I'll try to implement the current loop once I solve these issues. Yeah that is exactly what i am wanted to do.
    I have some doubts can you please clarify it

    PWM_setSocAPulseSrc(myPwm, PWM_SocPulseSrc_CounterEqualZero); means SOC is triggered when CTR =0 right?
    PWM_setSocAPulseSrc(myPwm, PWM_SocPulseSrc_CounterEqualCmpCIncr); means SOC is triggered when CTR=CmpC
    PWM_setSocAPulseSrc(myPwm, PWM_SocPulseSrc_CounterEqualPeriod); means SOC is triggered when CTR=TBRD right?
    So i can do something like this
    PWM_setSocAPulseSrc(myPwm, PWM_SocPulseSrc_CounterEqualCmpCIncr); means SOC is triggered when CTR=CmpC

    inside the routine

    CMPA= duty (calculated using the PI)
    CMPC=CMPA/2;
    rough idea...

    Please correct me if i am wrong thank u...
  • Hello Richard,

    i finally realized Assembly is the way to go for high speed execution of ISR. I saw the examples of Multicolor RGB led, VMC and HVLLC. I learnt C2000 can run 2p2z controller at switching frequency (1/3rd for rgbled ex.). I really like this idea !!! i am finding it really hard to understand on how to create and call an ISR in asm. Is it also possible to use it with Software driver or should i use it only with direct register access? Can you please suggest a book or application note on how to implement this ?
    I would also like to know how to call "nets" like in this doc
    www.epc.com.cn/.../ti_digital.pdf

    thank you
  • Hello Srinivasan,

    I agree.  I think the best resource for learning about the DP library structure and use is the on-line recordings of the C2000 digital power supply workshop.  You can find these at:

    https://training.ti.com/c2000-digital-power-supply-workshop-4-part-series

    In section 2, Hrishi talks about how to connect library blocks to form a control loop.  I think you will find something useful there.

    Regards,

    Richard

  • Many thanks for your reply. I already referred the pdf version of the document. I really like the software architecture of executing critical applications in assembly than C, but the presentation never talks about how they are implementing it ? He talks only about the GUI  and how to set parameters in open and closed loop. CAn you please give me a tutorial or application note in which it is shown how to execute time critical code in ISR ? 

    I am really struggling trying to understand. Also I tried read some examples on how to create a C callable assembly file but it works but the problem is the same the assembly file is not optimized and takes the same time to execute. When i tried to create an ASM file of my code i found that just PI controller takes more than 100 lines of assembly code while the 2p2z.asm used in examples are just few lines.

    I also do not understand why are all the variables in Long type format ? I am using float and when i  pass float to asm it gives me crazy result.

    Also the VMC example doesnt seem to be working on my piccolo it always enters an illegal ISR i am lost now !!!! do i need the kit to get it working ?

    My board doesnt connect to the gui !!!!

    I tried commenting out all the gui code and set the duty to 50 % hard code but the controller enters an illegal isr all the time.

     I just dont know what to do, it would be great if you could help me out.  

  • Srinivasan,

    Sorry to hear you're having difficulties. I recommended Hrishi's videos to show the architecture of the digital power library, and how it's used to build efficient digital power control loops. However, to do the hands-on labs you will need the same board used in the workshop. The workshop is based on CCS - you shouldn't need anything else. Which board and GUI are you referring to please?

    I think the method you referred to for creating an assembly file involves compiling a C interrupt or function and then taking code from the generated assembly file. Probably the reason you are getting such a lot of assembly code is the additional context saving which the compiler inserts. Hand coded assembly will be much more efficient because the programmer knows in advance which CPU resources to protect and can optimise the code. Therefore I don't normally recommend this method. You're better off using the DP library code in the workshop, or in one of the development kit examples in controlSUITE.

    BTW, you mention you are using "float" types in your code. The device you are using (F28027) is a fixed-point machine which won't handle floating-point data efficiently. If you want to do this in floating-point I recommend changing to something like an F28069 which has hardware FPU support.

    I don't know if I've answered all your questions clearly so please post back if anything's still unclear.

    Regards,

    Richard

  • Dear Richard,

    Thank you for your reply. I really appreciate it. I am using Piccolo F28027 and I referred TMDSRGBLEdKIT-LED example, my boards doesnt connect to GUI at all. Also I commented out most of the code just leaving the ISR but the dsp enters into illegal loop all the time. Even the pwm modules are not initiated i set them to 50% hard code values.

    Yes you are right i created an assembly file from my C file and tried to analyze the ISR and shockingly my ISR much bigger than the 2p2z.asm file.
    I agree with you too i would also like to use the DP library but it's really hard to understand it and use it the way i want it. Can you please recommend me a tutorial/ doc that shows how to initialize DP library and use it? I am currently reading the document provided tried following step by step now i am getting these warnings, i dont know what is going on.

    Description Resource Path Location Type
    creating output section "ADCDRV_1ch_Section" without a SECTIONS Example_F2802xLaunchPadDemo C/C++ Problem
    creating output section "CNTL_2P2Z_Coef" without a SECTIONS Example_F2802xLaunchPadDemo C/C++ Problem
    creating output section "CNTL_2P2Z_Section" without a SECTIONS Example_F2802xLaunchPadDemo C/C++ Problem
    creating output section "ISR_Section" without a SECTIONS Example_F2802xLaunchPadDemo C/C++ Problem
    creating output section "PWMDRV_2ch_UpCnt_Section" without a SECTIONS Example_F2802xLaunchPadDemo C/C++ Problem

    For now i just want to do the following

    initialize system (in C)
    set clock and peripherals (in C)
    set ADC and PWM (in C)
    declare the adc isr routines (in C)
    set the coefficients of 2p2z (in C)
    call the 2p2z.asm from the isr routine
    then set the duty (in asm or C)
    to give you an example this is something i am looking for

    #include "DSP28x_Project.h" // DSP28x Headerfile
    #include "IQmathLib.h"
    #include "DPlib.h"

    extern long 2p2z(ref,fdbk)

    _iq ref,fdbk;

    void main(){
    systeminit();
    init_ADC();
    init_PWM();
    init_interrupt();
    DP_init();
    set _2p2z_coefficients();
    ref=_IQ(1.25);
    while(1)

    {

    }
    }

    adc_isr(){
    fbk=Adc.readresult1();
    duty=2p2z(ref,fbk);
    PWM_setCmpB(myPwm2,duty*4);
    Acknowledge interrupt;
    } Actually i am not using float type sorry i am using IQ math library. My pi controller can reach upto 66 KHz without any divisions that is ok. This is my code
    err_5=_IQ(1.25)-_IQ(ADC_readResult(myAdc, ADC_ResultNumber_1));
    A_5 = _IQmpy(err_5,_IQ(5)); // kp*err
    B_5 = _IQmpy(err_5,_IQ(500)); //ki*err

    v_5 = k_5 + _IQmpy(_IQ(1/25000), (B_5 ));// v(n)=v(n-1)+ki*err*(1/Fs)
    k_5 = _IQsat(v_5,_IQ(50.0),_IQ(5.0)); //saturating integrator
    Vpi_5=_IQsat((A_5+v_5),_IQ(50.0),_IQ(5.0));// output of pi= kp*err+integrator output this sets the duty

    duty=_IQtoF(Vpi_5); // when commented the speed of the loop is 66 Khz else drops to 25 Khz
    PWM_setCmpB(myPwm2,duty*4);

    this command takes a lot of time and slows down the whole process. This code is similar to PI controller from IQ library.
    Could you please suggest a way to avoid using _IQtoF if i dont use _IQtoF the duty cycle doesnt work if i do i have to compromise on speed. I hope you know what i mean ?

    Could you please tell me this can i get faster execution if i increase the clock ? i mean if i go with a device that has higher clock ? like delfino 2337 or like piccolo 2069 ?
  • rinivasan,

    Now I understand you are using the RGB LED development board with F28027. I'm not very knowledgable on that board, but I can see from the source files in controlSUITE that the code is based on the DP library, and that there are multiple 2P2Z controllers involved. If you are aiming for LED control, can you just use the source files for the kit? I don't think you need the GUI - you just load the project into CCS and run it. That way you should be able to use the 2P2Z modules without modification; and they will be fast.

    What you have been doing is running the code for the F2802x LaunchPad on the RGB board. The reason you have these error messages is there are missing section definitions. Code and data in the DP library modules are loaded into memory according to section definitions in the assembly files included in the project. In the .cmd file used in the RGB kit, you'll see:

    Net_terminals: > dataRAM,PAGE = 1
    ISR_data: > dataRAM,PAGE = 1
    Controller: > dataRAM,PAGE = 1
    Controller2: > dataRAM,PAGE = 1

    This is where the linker command file is placing data from the DP library into memory. Those lines are not present in the command file for the LaunchPad because those example projects are not using the DP library, and this is why the errors appear.

    I wish there were a good tutorial on how to setup and use the DP library, but unfortunately there isn't. Frankly the easiest way forward will be if you can base your work on the RGB project in controlSUITE.

    From the IQmath documentation, the IQ to float conversion should only be taking about 22 cycles. The line following it is probably where all the time is being lost.

    duty=_IQtoF(Vpi_5); // when commented the speed of the loop is 66 Khz else drops to 25 Khz
    PWM_setCmpB(myPwm2,duty*4);

    Once again, if you can base your code on the RGB kit it will be much more efficient. You can of course speed up execution with a faster device, but you should be able to reach 66kHz with this device with no problem.

    Regards,

    Richard

  • Srinivasan,

    Just wanted to add that there is a description of how to setup and use the DP library modules in the device/Doc directory in control suite.  The latest document for F28027 is attached.  I thought this might help.

    Regards,

    Richard

    DPLib.pdf

  • Hello Richard,

    Thank you for your fast reply. Yes I saw the cmd files and changed mine accordingly now those warnings have disappeared.
    You mean to say this line is taking a lot of time ?
    PWM_setCmpB(myPwm2,duty*4);
    Yes you are right I really want to make my code based on the RGB code but it is really hard. I am trying my best !!!
  • Hello Richard,
    I am using this document thank you so much.
    Could you please give me an idea on how to implement the following

    initialize system (in C) (check)
    set clock and peripherals (in C) (check)
    set ADC and PWM (in C) (check)
    declare the adc isr routines (in C) (check)
    set the coefficients of 2p2z (in C) (check)
    call the 2p2z.asm from the isr routine (have no clue)
    then set the duty (in asm or C) (have no clue)
    to give you an example this is something i am looking for

    extern long 2p2z(ref,fdbk)

    long ref, fdbk;

    void main(){
    systeminit();
    init_ADC();
    init_PWM();
    init_interrupt();
    DP_init();
    set _2p2z_coefficients();
    ref=_IQ(1.25);
    while(1)

    {

    }
    }

    adc_isr(){
    fbk=Adc.readresult1(); //get fdbk
    duty=2p2z(ref,fbk); //call 2p2z from isr
    PWM_setCmpB(myPwm2,duty*4);
    Acknowledge interrupt;
    }
    I hope you know what i mean ?
    I think this will reduce other complexities and make it simpler, this way also i will be still using the dp library.
    is it possible to do this ? Please help thank you.
  • Srinivasan,

    The lighting kit code is written using C structures to access the registers, however it looks like you prefer a method using the driver library in the LaunchPad examples. I regret there isn't any example code which does this, so it will take some work.

    Probably the best way is to start with the LaunchPad examples and then integrate the DP initialization code as you need it from the lighting kit example. Then, you'll have to set up a C ISR and make a function call into the assembly ISR.

    You'll need to:
    - set up a C ISR and map its' address to the trigger (see line 827 in the lighting kit code, or "adc_isr" in the LaunchPad code)
    - declare the assembly function in your C code:
    void ISR_Run();
    - replace the final IRET instruction in the assembly function with LRETR
    - add a call to the function in the C ISR
    ISR_Run();

    You'll also need to add the DP sections to the linker command file, which was mentioned in an earlier post. This way you'll be able to keep the initialization code and macros from the DP library, yet have a C framework using the Driver Lib.

    Honestly I would not regard this as a task for a novice because you will be merging two very different ways of coding. I's detailed work and I don't think it will be straightforward. A far better way to proceed is to base your work on the Lighting Kit code. It's tested, efficient, and will be a good deal easier to get working as you want. What is the reason for not doing that?

    Regards,

    Richard

  • Richard,

    Many thanks for your quick reply. I will follow your advice and try to base my code on the Lighting Kit code. I also agree with you on that.
    I was trying to implement my own controller but now i think i'll stick to this. I was having a hard time trying to understand the example project but i kind of understand the concept used. Also when i upload the kit example to my piccolo in debug mode it enters into illegal isr i have no clue why. I commented out most part of gui interface and hard set the values example duty to 50 and observed the registers in debug mode i was getting crazy results so i was confused.

    Btw I implemented both voltage and current loop like you suggested in the word doc and i think it works not sure yet. I am able to regulate output voltage and load but my step response is really bad. I am trying to regulate 12V when i step load it (300 mA) the output voltage drops to 8V not sure if has something to do with inner current loop or sampling rate.
    My sampling rate for both loops are 25 khz.
    What would you recommend i have 3 possible path now
    1) increase the sampling rate by keeping the Lighting kit as an example ?
    2) use embedded code generators like simulink, vsim ?
    3) change the board to f2069 or f28337 ? (quick, dirty and expensive )
    i am really confused !!!
  • Srinivasan,

    Can you describe your hardware setup as you have it now please?  Are you doing everything on the LED board and with the example code?  If so, what is the load?  Thanks.

    Regards,

    Richard