I will test in a short time on hardware the pid control with DSP control on flowcode DsPIC.
There is no macro which allow to live control the P, I and D parameters.
Adjusting PID with software(with DSP control properties) is not a recommended method.
Can matrix staff do a macro to live control PID?
It is probably possible to do it in custom code but it will be much more easy with a macro for my students(have somebody already do that?).
If you want to learn how to live adjust you PID parameters with almost no theory, PIDSTOP is a very good website.
You can practice with chopper for example:
http://www.pidstop.com/index.php?r_id=641
PID control with DSP
Moderator: Benj
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: PID control with DSP
Hello,
The P,I and D parameters can be edited by doing the following.
Select the DSP control component and then click on the custom code.
Select the defines function and click the edit button.
Find these lines of code and comment them out by adding "//" to the start of the line.
Should look like this once it has been done.
Below these commented out lines add the following lines of code.
You can then update the parameters at any time in your Flowcode program by using a C icon to copy values from Flowcode variables P, I and D into the C variables.
Let me know how you get on.
The P,I and D parameters can be edited by doing the following.
Select the DSP control component and then click on the custom code.
Select the defines function and click the edit button.
Find these lines of code and comment them out by adding "//" to the start of the line.
Code: Select all
#define %a_PROPORTIONAL %h
#define %a_INTEGRAL %i
#define %a_DIFFERENTIAL %j
Code: Select all
//#define %a_PROPORTIONAL %h
//#define %a_INTEGRAL %i
//#define %a_DIFFERENTIAL %j
Code: Select all
#define join_dsp(b) (%a##b)
MX_UINT8 %a_PROPORTIONAL = %h
MX_UINT8 %a_INTEGRAL = %i
MX_UINT8 %a_DIFFERENTIAL = %j
#define MXP join_dsp(_PROPORTIONAL)
#define MXI join_dsp(_INTEGRAL)
#define MXD join_dsp(_DIFFERENTIAL)
Code: Select all
MXP = FCV_P;
MXI = FCV_I;
MXD = FCV_D;
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 155
- Joined: Sat Mar 28, 2009 5:44 pm
- Location: LYON FRANCE
- Has thanked: 3 times
- Been thanked: 41 times
- Contact:
PID with DSP: not ready to use
I performed some test on motor and as5030 encoder.
The P control work properly but not de PI control!
Here is a simple test program: With a static error you should have an increasing output. That's not the case.
You write in your C code:
But that's not true. See here:
http://electronics.stackexchange.com/qu ... lemenation
You should write:
It is possible to correct the C code with:
The result in flowcode is here:
That better but still not good.
See in a next post...
The P control work properly but not de PI control!
Here is a simple test program: With a static error you should have an increasing output. That's not the case.
You write in your C code:
Code: Select all
Out = P * (Error - Prev_Error + (Error / I))
http://electronics.stackexchange.com/qu ... lemenation
You should write:
Code: Select all
Out = OLD out+P * (Error - Prev_Error + (Error / I))
Code: Select all
%a_OUTPUT_NAME[MXDSP_idx] = OLDval+%a_PROPORTIONAL * (error - errorm1 + (error / %a_INTEGRAL));
OLDval =%a_OUTPUT_NAME[MXDSP_idx];
See in a next post...
-
- Posts: 155
- Joined: Sat Mar 28, 2009 5:44 pm
- Location: LYON FRANCE
- Has thanked: 3 times
- Been thanked: 41 times
- Contact:
Re: PID control with DSP
There are still some problems to solve:
- There is no limit for the output
- error /I=0 when error is small and I is big with integer calculation. This mean that a small static error will not increase the output(we use I especially for small static error).
Example: If error=2 and I=10 then error/I=0.
One solution to solve both problems this is:
Code: Select all
//Out = OLD out+P * (Error - Prev_Error + (Error / I))
NEWval = OLDval+ %a_PROPORTIONAL * %a_INTEGRAL *(error - errorm1) + %a_PROPORTIONAL*error;
tempval=NEWval/%a_INTEGRAL;
if (tempval<-126) {tempval=-126; NEWval=-126*%a_INTEGRAL; }
if (tempval>126) {tempval=126; NEWval=126*%a_INTEGRAL; }
%a_OUTPUT_NAME[MXDSP_idx]=tempval;
//Shift error for next iteration
OLDval =NEWval;
errorm1 = error;
It would be a good idea to add the ouput limit in the DSP control properties.
I don't have time to look at the FFT code:
http://www.matrixmultimedia.com/mmforum ... 009#p46372
I hope that's not the same...
-
- Posts: 155
- Joined: Sat Mar 28, 2009 5:44 pm
- Location: LYON FRANCE
- Has thanked: 3 times
- Been thanked: 41 times
- Contact:
Re: PID control with DSP=not ready to use
Still no news from that post!
Can you correct the PID component: only P is working properly.
Our prototypes could be good DSP demonstrators if you correct your bug quickly.
3 prototypes with PID will be manufacture this year. The students already implement PID without the flowcode DSP components because you didn't correct the bugs...
You still have one possible demonstration with FFT:
http://www.matrixmultimedia.com/mmforum ... 009#p46845
Can you correct the PID component: only P is working properly.
Our prototypes could be good DSP demonstrators if you correct your bug quickly.
3 prototypes with PID will be manufacture this year. The students already implement PID without the flowcode DSP components because you didn't correct the bugs...
You still have one possible demonstration with FFT:
http://www.matrixmultimedia.com/mmforum ... 009#p46845