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.
> 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.
First of all, is it necessary to implement this model in discrete domain?
Because I not sure this is a correct step or not. Or just continuous domain implementation is fine?
>you’ll want to adjust the discretization technique to account for the desired gain at 60 Hz.
Is this means the discretization model somewhat have problems cause the db magnitude is nonzero value in the small signal analysis?
>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.
I noticed a problem before, which is the magnitude will change as the time goes. Is this issue give rise to this problem? Therefore, to deal with this problem, I have to turn on “enable wrapping” in discrete integrtor and set the upper limit as 2*pi. Is that
The simulation is showing that the discretization method impacts how the PLL performs. The default discretization method in PLECS for your continuous model implementation shows the additional gain at 60 Hz. There are many references on different discretizaiton methods and several papers on discretizaiton approaches for the SOGI PLL specifically.
Researching this and choosing the correct approach is an engineering decision on your part. PLECS will be helpful in analyzing how the different approaches perform in both the time and frequency domain.
I’d recommend using the wrapping integrator as you outlined. I can’t comment on the problem you noticed, but if the error got worse over time, then the floating point value accuracy could be the cause.
I have modifiied the model by adding a Timer Block and control trigger with ADC, and simulate it with c2000 mcu. The figure below is what I got on d axis component. (SRF in green,SOGI in red)
This relates to data retention in external mode, as I mentioned in my initial post. See the recommendations regarding the total number of scopes, buffer size, and decimation. Refer to this forum post for a more detailed explanation on the how the sample window duration (in seconds) relates to those settings.
From the initial post, I wondering that the small signal analysis shows with discretization have additional gain while without discretization does not have. Is it means without other discretization method is fine in the model ?
I’m also wonder how to generate the frequence response like the figure in the initial post. I know this function is in the “analysis tools” and select 4 different analysis method. Later, add the small signal peturbation at the input and add small signal response at the output. I tried it in my continous model using steady state analysis and it shows that it fails to converge. How to solve this issue in my model?
> I tried it in my continous model using steady state analysis and it shows that it fails to converge.
I believe I used multitone analysis to generate the plots, which achieves steady state by a transient simulation until all disturbances settle. There’s a tutorial on Analysis Tools which might be helpful to better understand how they work.
Your original model will likely not reach steady-state because that requires a periodic operating condition. The states in the integrators never reach a periodic operating condition because they keep integrating towards infinity. That’s another benefit of using the wrapping integrator we discussed above.
> How to export the data to MATLAB at the moment of the event occurs like the figure below ?
The Export to CSV from the scope is the only option at the moment for embedded targets. You can will have to set up your external mode triggers such that you capture the event - for example, set the trigger channel to when the SRF Vd goes below 0.95.
You can also time shift and set a delay. See the following video at T=4:00 on how to configure this. I find dragging the trigger in the active scope window to be most convenient, as explained in the video.
If the event is periodic and you want to capture just one instance, click the “Manual Trigger” option instead of the autotrigger.
> Also, how to design the event occured at a specified time?
It’s not clear to me why the minima is different. One theory is that the Decimation setting is set too high (40) as you are capturing just one sample showing the minimum value. There are 39 samples you may be missing that show the true minimum. I would decrease the decimation to get more samples during the transient event to see if the results are more consistent.
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 + 2pifc). 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.
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)=Kds/(s/Kf + 1) ( from the PID block help, with Kd =1 and Kf = 1/(2pi*fc)).
I was attempting to show a) how to choose Kf per the linked post and b) that discretization techniques might be relevant.