Please take a minute to review and accept our Terms of Use.
Welcome to the PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Many technical questions regarding PLECS are answered on the Technical Solutions page of our website. Tutorial videos, specific application examples, and pre-recorded webinars are available on our YouTube page. Please follow us on LinkedIn for the latest Plexim news.

Implementation of DQ transform with TI C2000

0 votes

I am working on implement DSOGI PLL algorithm to perform dq transform on c2000 F280069 controller in external mode.

I use a RT BOX as AC signal to transmit the 3 phase controllable voltage signal from plant subsystem to controller subsystem, and use ADC module to receive the signal in controller side.

The first problem I faced is the value of d axis and q axis are not accurate as I expected (d should be 1 and q should be 0).

I tested it in offline simulation and result looks fine.

I also tested in Codegen mode I found out that if the discretization step size is about 1us , then the value will be more correct. However, only 100us is compatible with mcu.

So I replace my model with z domain blocks. But the value is still not so accurate like offline simulations.

Also,I used the trapzoidal method in my discrete model to generate the quaduature signal.

The second problem is that I try to design a phase jump event with parameter inlining function during simulation.

Hence, I used a controllabe voltage source in my plant subsytem.

and the question is I can not record the response for the event moment.

I know the trigger controls function in external mode. But I still can't get it how to use this function.


Thanks for your help!
asked May 16 by ian (14 points)

1 Answer

0 votes

> I also tested in Codegen mode I found out that if the discretization step size is about 1us , then the value will be more correct. However, only 100us is compatible with mcu.

Like you interpreted, the issue is in the continuous to discrete transformation.  

Note that without a Control Task Trigger in the C2000 model, the system is treated as continuous.  If you add a Timer Block, set the ADC to show the trigger port, and a add Control Task Trigger you'll model the discretized model behavior in your offline simulation.

You can see this in the small signal analysis of the SOGI cell with and without discretization.  Discretizing the system results in a 0.42 dB gain opposed to 0 dB at 60 Hz.  As you have suggested, you'll want to adjust the discretization technique to account for the desired gain at 60 Hz.

> But I still can't get it how to use this function.

Here's a link explaining how to setup triggering in the external mode.

A few relevant points for your application:

  • You want to choose an appropriate trigger signal that will only change once the phase jump occurs (likely frequency or Vd)
  • There is a limited amount of data captured in external mode and you want to capture a signal with slow dynamics relative to your sample rate.
    • You'll want to significantly reduce the number of scopes in your model so you have more samples per scope.
    • You'll want to increase the decimation in the Coder Options + External Mode tab.
    • You can increase the target buffer size in the Coder Options + Target + External Mode tab (e.g. 2000) for additional data.
  • Your angle value is not limited and does not have any roll over.  As the angle increases to very high values over time, the floating point value will lose resolution.  You'll want to adjust your integrator to wrap instead of using the "Mod" approach.
answered May 16 by Bryan Lieblick (1,949 points)

Hello I have another question

I need to implement a derivative function in my model and I found the c-script file for derivatives in the forum.

It can simulate with variable solver. But for running with dsp, it shows poor response.

Are there any other approaches that can be used for derivative function with dsp simulation?

Is PID controller can be treat as a derivative function?


As mentioned in the forum post you linked, derivatives have some less-than-ideal numerical properties when it comes to their practical implementation.  In real-time implementations there is quite a bit of sensitivity to noise.

One approach would be to use a transfer function block with G(s) = s / ( s + 2*pi*fc).  This adds a real-pole such that the derivative action is neutralized above fc.  You should choose fc based on your application.  See the related discussion for the PID blocks.  I would also suggest looking at the discrete PID block's derivative implementation as it implements different discretization techniques for the derivative implementation.

To make use of the derivative in PID, setting Kp,Ki as 0 and Kd=1. And Kf depends on the model.

So the G(s) is a low pass filter to filter noise before proceeding PID controller.

Is what Kf does the same as G(s), both filtering out noise?
What I wrote might be a bit confusing, but essentially the G(s) transfer function above is exactly the same as the derivative term in the PID controller D(s)=Kd*s/(s/Kf + 1) ( from the PID block help, with Kd =1 and Kf = 1/(2*pi*fc)).

I was attempting to show a) how to choose Kf per the linked post and b) that discretization techniques might be relevant.
I take the derivative of sinewave and tune the kd=1, Kf as 1/(2*pi*60))=0.002,however the result just shows a magnitude 0.002 sinewave.

I think the derivative did not take action and what else i need to do with the derivative implementation?