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.
Hello Guys,
I am a newbie to Piccolo and i am currently designing a switching converter for an university project, i have the following adc routine running at 50KSps. I am trying to implement a simple PI controller inside the ADC routine (i am not sure this is correct but based on reading online materials i think is somewhat done).
My problem is my integrator output saturates and doesnt increment over period of time (actual output of Integrator is sum of past errors) until i declare the variables to be "static". But when i declare the variables to be static my loop samples is reduced to 10KSps. The following is the ADC routine in i have to declare variables in_A and k_5 as static but significantly loosing the loop performance.
Is there any way to design a simple PI controller using F28027 or any example i can refer ? Please kindly help thanks a lot in advance...
interrupt void adc_isr(void)
{ float err_5, A_5,B_5,v_5,Vpi_5=0.0; static float in_A=0, k_5=0.0;
GPIO_toggle(myGpio, GPIO_Number_1);
//discard ADCRESULT0 as part of the workaround to the 1st sample errata for rev0
Voltage1[ConversionCount] =ADC_readResult(myAdc, ADC_ResultNumber_1);
err_5=1.25-3.3*(Voltage1[ConversionCount])/4096;
//if(ConversionCount>1)
A_5 = err_5 * 0.4; //proportional error
/* integrator
B_5 = err_5 * 727.27;
v_5 = k_5 + 0.5/50000 * (B_5 + in_A); //in_A and k_5 has to be declared static
k_5 = v_5;
in_A = B_5;
*/
Vpi_5=v_5+A_5;
Srinivasan,
I think your problem is likely to be because you are emulating floating-point on a fixed-point machine. You don't say which clock speed F28027 part you have, but at 50ksps you probably only have 1,000 or so clock cycles per interrupt. Emulating floating-point will consume a few hundred, which is why your sample rate drops - the controller can't keep up. It probably accounts for the numerical issues you're having too.
If you want to stay with the F28027 and codeyour own PI controller, I strongly recommend doing it using IQ math. You can find more information about the IQ math library in control suite, and there is a PI regulator (pi_reg3.h) built using it in the DMC motor library. If you have controlSUITE installed in the default location, you can find this at:
C:\ti\controlSUITE\libs\app_libs\motor_control\math_blocks\v4.3
If you want to move to a newer floating-point device, such as F2806x, there is a digital controller library at:
C:\ti\controlSUITE\libs\control\DCL\v1_00_00_00
Regards,
Richard
Dear Richard,
Thanks for your quick reply, i also tried IQ math lib and the results are at 8 KSps i am clocking dsp at max of 60 MHz. I'll try to implement PI regulator in the motor library and keep you updated. So if this is a constraint on the device how is it possible to design a PID control or PI with high sampling rate (not sure with this device) ? Am i missing something here.....
And my loop speed reduced only when i use "Static float" type operands inside the routine. Can you please explain me how "Static float or int" reduces the loop speed? I have seen the same with global and arrays (both global and local) thanks!!!
Srinivisan,
A basic PI controller such as the one in DMC library should only consume around 40 CPU cycles or so. If the device were doing nothing else, you should be able to run it at around 1MSPS on this platform.
Therefore I think there must be something going on which isn't obvious from the code. If you can reduce your CCS project to a minimal size and post it here I'll be glad to take a look.
Regards,
Richard
Srinivisan,
I'm going to need the project, not just the code. Can you zip and attach the entire CCS project? That way I can see project settings and hoe the linker is setup. Thanks.
Regards,
Richard
Example_F2802xLaunchPadDemo.rar
Hello Richard,
I tried the PI controller from DMC library but i implemented the sturcture in my code and i still have the same problem output of the integrator is saturating when the error is positive or negative. But the loop speed has increased to 16 Khz.
Please find attached my project.
Srinivisan,
The execution speed is also being influenced by the fact the code is running from flash. I had not realised this before. If you want the ISR to be as fast as possible you should copy it into RAM before executing. There is a good application note (spra958) which describes how to do this, and includes some example code for the F28027.
Take a look at the IQ quantity before you convert it back to float. Is it zero? I think there might be a bug somewhere in the way you're using IQ math.
When a PI controller runs it is normal for the integral path to saturate. The pi_reg4 code includes anti-windup which disables the integrator when the controller output exceeds pre-defined limits. Your original code has a very high integral path gain, so this might be happening very quickly. It's not necessarily a problem providing it's handled correctly in the code.
I still recommend using the PI controller from the DMC library. That is already written in IQmath and is known to work correctly. BTW, you can safely ignore the warning about the missing build attribute - that is expected.
Regards,
Richard
Srinivasan,
You're welcome. Glad to know you're making progress.
There's an easy way to get cycle count numbers using CCS. Set a break-point where you want to start measuring and run the code to that point. Then, in CCS: Run -> Clock - Enable. This puts a clock in the lower right corner of the ODE. Set another break-point where you want to stop measuring and run to that point. The clock shows the cycle count. You reset the counter by double-clicking on it.
I suggest looking again at the code examples for F28027 in controlSUITE. There is one which shows an ADC end-of-conversion interrupt routine (Example_2802xAdcSoc.c). You can change the EPWM1 settings in that code to get the sample rate you want (nothing wrong with that), then add your PI code to the ISR. Again, I recommend using the DMC library code mentioned above.
This way you'll have the controller operating at a known rate and with known code. If you want a flash implementation you can convert it later using the application note I mentioned above. I think that will be an easier route.
I hope this helps.
Regards,
Richard
Hello,
I am working on DC/DC converter and in close loop voltage control I need to implement PI.
So I was looking on your code, why there is multiplication of 727.7..? ..second doubt is if I need to vary my PWM compare as per PI value, what should I do..?
Please share your view.
Thanks in advance.
Hi Srini,
Thank you for the reply.
I am trying to impliment SEPIC and my maximum duty cycle goes up to 70%. I will be needing one PI for voltage and another for current loop control. I am not good at coding anyway I am trying to learn. Do I need to use IQ math library or this simple code will work..?
Please share your view.
Thank you.
Hi,
It depends on the sampling rate of your voltage and current loops. Yes please use IQ math library if you are using F28027 as this is a floating point device if you are using a device with floating point support you dont have to use it. Also make sure to set the global Q value in the IQ math library to match your requirements by default it is 24.
70% is not a problem just saturate the output to 70 or 0.7 depending on how you code the PI.
my issue is with sampling rate of the control loop i am not able to push it to increase.
Hope this helps.
Srini
Srinivasan,
Glad to know you have the control loop working at this frequency. Sorry, I don't have any idea why the ADC is behaving this way. 3.3V is the upper limit of the ADC input on this device. What happens if you apply a fixed mid-range input, say +1.5V, do you still see the same variation?
I strongly recommend opening a new post on this forum because no-one will connect this thread title with a question about the ADC.
Regards,
Richard
Hi Srinivasan,
Since you are working on a research project my suggestion is you go ahead and move to a platform which supports floating-point. If your sample rate issues are connected with the use of float in the code, they should go away then. You will also find it easier to code and test your controller. The Digital Controller Library I mentioned previously will also become feasible.
The alternative - re-writing your interrupt code in assembly - will entail more work and likely take a lot longer to get running.
Regards,
Richard
Hello Richard,
Thank you for the suggestion, i will move to F28069. I am having an issue again with my current loop and i found the culprit is with triggering the ADC sampling i am really confused with my understanding of the soc pulse sources. Can you please give explain or suggest a material that i can read ?
PWM_SocPulseSrc_CounterEqualZero ///CTR = Zero ?
PWM_SocPulseSrc_CounterEqualPeriod // CTR= PRD
PWM_SocPulseSrc_CounterEqualCmpAIncr // CmpA incr ?
PWM_SocPulseSrc_CounterEqualCmpADecr // CmpA dec ?
so could please kindly tell me how do i trigger the soc to sample when CTR= CmpA ?
this is creating a lot of issue on my current loop and causing hissing noise on the transformer.
Hello Srinivasan,
The CMPA & CMPB comparators are capable of distinguishing between a comparator match when the timer is counting up, and a match when the timer is counting down. Sampling and/or edge events can be triggered on one or both conditions. You will have to decide which condition you want to use for sampling.
For example, the attached timing diagram generates complementary pair duty cycle modulated PWM using CMPA (counting up) for edge positioning, and CMPB (counting up) for ADC SOC. This approach allows the ADC sampling point to be positioned away from a PWM edge where the reading might be corrupted by glitches.
If you want CTR=CmpA among the conditions in your post, and you want counting up, you need:
PWM_SocPulseSrc_CounterEqualCmpAIncr
It's a lot of information, but I recommend working through sections 3.2.3 and 3.2.4 in the TRM for this device.
Regards,
Richard
Srinivasan,
Sorry for my delayed reply - I have been out of the office for some time. Can you let me know the switching frequency please?
1) What is your current control strategy? Are you using the internal comparators to implement peak current control, or is this average current control?
2) I do not recommend over-clocking the CPU. You will be operating the device out of spec which means none of the datasheet parameters are guaranteed. The fastest Piccolo device is the F28075 which runs at 120MHz. There are faster C2000 devices in the Delfino family.
3) I'm not familiar with the DC-DC lighting board. I will ask a colleague to comment.
Regards,
Richard
Hi Srinivasan,
3) In the TMDSRGBLEDKIT, the C2000 is running 8 separate control loops. Each loop is approximately controlling the average current through its corresponding boost/SEPIC stage. The board assumes that the DC bus voltage being brought into the board is being controlled.
(It could be feasible for some of the spare cycles in the C2000 device to be used to control this DC bus voltage using an external boost or buck converter. That was not done here)
Hopefully this helps.
Thank you,
Brett