Did anyone implement a controller in dsPIC by this toolbox?

Post Reply
gladiac
Posts: 17
Joined: Fri Jun 27, 2008 11:32 am
Location: Liverpool, UK

Did anyone implement a controller in dsPIC by this toolbox?

Post by gladiac » Mon Dec 08, 2008 2:41 pm

Did anyone implement a controller in dsPIC by this toolbox? I was trying some times but still got some problems. I use dsPIC30f6014A device. If I use 'transfer function' block of Simulink simply or create a 'direct form' model for controllers, they don't work in practice.
direct form.jpg
direct form.jpg (18.89 KiB) Viewed 26763 times
discrete TF.jpg
discrete TF.jpg (2.66 KiB) Viewed 26752 times
Only when I use a simple P, PI or 1st order model, the controller works just OK in practice. Also error tracking is not good in this situation.
one.jpg
one.jpg (11.89 KiB) Viewed 26740 times
For all models, sample time was specified. The 'signal type' was setup as 'double precision', because there was a big number range from reference input to controller output in my case. I'm not sure above modelling and setups are exactly correct. Did anyone have related experiences? And Mr. Lubin, do you have any advice for implementing controller by your toolbox? Thanks for all!

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

Re: Did anyone implement a controller in dsPIC by this toolbox?

Post by LubinKerhuel » Mon Dec 08, 2008 3:11 pm

Hello,
Thanks for the images.

I made many controllers (PID or state space model) that work.

Try to:
- show sample time of each block (use sample time color).
- Check that 1/Z works at the right sample time (should be -1 for inherited or you simulink sample time value) default value is 1 (for 1 second) and is a cause of error!

- Also, note that double are implemented as single in the dsPIC except if you add the block "Compiler Configuration" from the dsPIC blockset and check the box to implement Double in 64bits instead of 32. (But I do not think that is the error, and I would advise to keep 32 bits)

If it did not solved the problem, could you upload the simulink files for theses model?

Lubin

gladiac
Posts: 17
Joined: Fri Jun 27, 2008 11:32 am
Location: Liverpool, UK

Re: Did anyone implement a controller in dsPIC by this toolbox?

Post by gladiac » Mon Dec 08, 2008 4:55 pm

Hi Lubin,

I think I have done the same setup for my models. It's better to upload the model, but always errors occur when I upload a .mdl
file. Anyway, I have sent the model to you by email-lubin@kerhuel.eu, please take a look if possible.

cheers,

gladiac

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

Re: Did anyone implement a controller in dsPIC by this toolbox?

Post by LubinKerhuel » Mon Dec 08, 2008 8:49 pm

Hi Gladiac,

I did not see obvious error the simulink file you sent.
But I could perhaps help anyway. First of all, I will not check the controller stability and so on... I supposed that it is Ok.

I have two remarks:
First, on the use of data type double: despite it is easier to use than fixed point calculation, strange behavior may appears when calculation involving both very large value with very low value appears.

Then, a second remark: the PID implemented has no reset or saturation limits (or anti windup) on the 'I' term. As soon as the controller is switch off (See switch on the model), I supposed that the integrator reach a very high value. Cf to remark 1, you may get into trouble then.

If your electronic board has an UART that you can connect to your PC, I would suggest using the Tx-Matlab block to see what happen on several variables at the same time. (Convert value into int16 data type before sending through UART.
Block_UART_Tx_Output_Multiplexed_MatlabLabview[1].png
Block_UART_Tx_Output_Multiplexed_MatlabLabview[1].png (782 Bytes) Viewed 26745 times
Lubin
Attachments
controller.mdl
Simulink Model file from Gladiac
(42.31 KiB) Downloaded 803 times

gladiac
Posts: 17
Joined: Fri Jun 27, 2008 11:32 am
Location: Liverpool, UK

Re: Did anyone implement a controller in dsPIC by this toolbox?

Post by gladiac » Mon Dec 08, 2008 9:01 pm

Thank you very much, Lubin! I will try it tomorrow and let you know the result.

gladiac
Posts: 17
Joined: Fri Jun 27, 2008 11:32 am
Location: Liverpool, UK

Re: Did anyone implement a controller in dsPIC by this toolbox?

Post by gladiac » Fri Dec 12, 2008 3:26 pm

Hi Lubin,

I have tried the dsPIC again. First, my controller worked OK on dSPACE before.So the cotnroller should be OK. Second,if I remove the 'saturation' block in model, output signal looks fine on oscilloscope. But on real testing, behaviour is still bad. I'm sitll checking problem include the hardware.

cheers,
gladiac

gladiac
Posts: 17
Joined: Fri Jun 27, 2008 11:32 am
Location: Liverpool, UK

Re: Did anyone implement a controller in dsPIC by this toolbox?

Post by gladiac » Thu Jan 08, 2009 5:47 pm

Hi Lubin,
The low order controller works OK when using the update version toolbox.The high order one doesn't work. Still trying.

gladiac
Posts: 17
Joined: Fri Jun 27, 2008 11:32 am
Location: Liverpool, UK

Re: Did anyone implement a controller in dsPIC by this toolbox?

Post by gladiac » Thu Jan 29, 2009 5:38 pm

Dear Lubin,

Unfortunately, my dsPIC was broken two weeks ago and the new one just come a few days ago. So the problem has been delayed for a long time. Now I use the 'zpk(zeros-poles-gain)' block to implement the high order controller, and that works OK in real testing. Also I tried the 'state-space' block, it performaned like the general 'tf' blcok which doesn't work. Do you have any idea for that phenomenon and What's the difference between 'zpk','ss'and 'tf' block in implementation?

Cheers,

Gladiac

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

Re: Did anyone implement a controller in dsPIC by this toolbox?

Post by LubinKerhuel » Sun Feb 01, 2009 3:17 pm

Hi Gladiac
gladiac wrote:What's the difference between 'zpk','ss'and 'tf' block in implementation?
I did not compared the C implementation of theses block yet. That would be interresting. Could you upload a model with your corrector as starting point to compare ?

Lubin

gladiac
Posts: 17
Joined: Fri Jun 27, 2008 11:32 am
Location: Liverpool, UK

Re: Did anyone implement a controller in dsPIC by this toolbox?

Post by gladiac » Mon Feb 02, 2009 4:35 pm

Hi Lubin,

The file attached is the model of the controller. I put three different blocks with same one controller in it.

Cheers
Gladiac
Attachments
controller.mdl
(38.02 KiB) Downloaded 782 times

malife
Expert
Posts: 56
Joined: Tue Apr 17, 2007 7:24 am
Location: Santa Cruz, CA
Contact:

Re: Did anyone implement a controller in dsPIC by this toolbox?

Post by malife » Wed Feb 11, 2009 8:11 pm

Hello Lubin,
This seems to be quite an interesting comparison, would you post your results if/when you have them to see which is more efficient?

Thanks

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

Re: Did anyone implement a controller in dsPIC by this toolbox?

Post by LubinKerhuel » Wed Feb 11, 2009 9:09 pm

Hello Gladiac, Mariano,

I'am quite overloaded (Working on both the next blockset version and my PhD ...) forgot this thread. Sorry about that.
Thanks Gladiac for the last model you posted. I'll try to have a look next week. (it is not urgent for anybody? )
I'll report results If it is not already done by someone.
As an interresting subject, that could be a case study to add in the wiki pages...

Cheers
Lubin

Tchangov
Posts: 4
Joined: Thu Feb 12, 2009 6:54 pm

Re: Did anyone implement a controller in dsPIC by this toolbox?

Post by Tchangov » Thu Feb 12, 2009 6:58 pm

The controller model presented has problem with the Gain 3; It must be negative...
Gain 3 and Gain 2 MUST be negative...
...and do not try any positive feedback design in your systems unlesss you are designing Variable Structure System Design...
Todor

Tchangov
Posts: 4
Joined: Thu Feb 12, 2009 6:54 pm

Re: Did anyone implement a controller in dsPIC by this toolbox?

Post by Tchangov » Thu Feb 12, 2009 7:08 pm

This Gain -koefficient in the first intrgrator feed back must be negative.
...in both the Plant and the controller.
The controller presented is not performing PI.
If the Gain is negative then we have a first order filter responce added to Proportional K...
Ones you have negative gain ofcourse.
Then you will have an "I" component to "P", which will be working for 0.63 of the Time Cte for this First order structure. And no MORE...

After that - in study State...this 1 Order will add extra proportional actuating...
You will miss the "I" Integral component in PI...therefore, a big Static Error (studyState...Tracking...error.) will never be compensated to be ZERO.
Back to Simulink...
Lubin is right about using Integrators...always limit them...and be ready to reset the Initial Conditions !!!!!
Happy Simulating,
Todor

Tchangov
Posts: 4
Joined: Thu Feb 12, 2009 6:54 pm

Re: Did anyone implement a controller in dsPIC by this toolbox?

Post by Tchangov » Thu Feb 12, 2009 11:23 pm

Tchangov wrote: I have just derived the controller: It present a Proportional Derivative dynamics.




This Gain -koefficient in the first intrgrator feed back must be negative.
...in both the Plant and the controller.
The controller presented is not performing PI.
If the Gain is negative then we have a first order filter responce added to Proportional K...
Ones you have negative gain ofcourse.
Then you will have an "I" component to "P", which will be working for 0.63 of the Time Cte for this First order structure. And no MORE...

After that - in study State...this 1 Order will add extra proportional actuating...
You will miss the "I" Integral component in PI...therefore, a big Static Error (studyState...Tracking...error.) will never be compensated to be ZERO.
Back to Simulink...
Lubin is right about using Integrators...always limit them...and be ready to reset the Initial Conditions !!!!!
Happy Simulating,
Todor

gladiac
Posts: 17
Joined: Fri Jun 27, 2008 11:32 am
Location: Liverpool, UK

Re: Did anyone implement a controller in dsPIC by this toolbox?

Post by gladiac » Mon Feb 23, 2009 5:42 pm

Hi Lubin,
Thanks for your continuing attention.
And Todor,
Your explanation is right. But I don't think it will cause the problem, feedback loop of 'direct form' still can be negative. As 'sign' can be changed straight in 'gain' block. Actually, I put the negative cofficients in 'gain' blocks directly. The problem for the model first uploaded is not the compensator. The reason is my hardware is not supported by Lubin's blockset initially, when Lubin upgrade the blockset for me, the problem was solved. The controller with dsPIC woked fine in real machine testing.

Cheers
Gladiac

Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests