DSP Component Advise-Guidance

An area to discuss 8-bit PIC specific problems and examples

Moderator: Benj

Post Reply
User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

DSP Component Advise-Guidance

Post by QMESAR »

Hello Ben/ Leigh.
I need your help and wisdom in using the DSP Control Component. I have setup the component as shown here.
FC PID.jpg
FC PID.jpg (23.87 KiB) Viewed 3978 times
[1] Is the Set point Input and connected to Buffer A
[2] is the Feedback signal connected to Buffer B
[3] is the output connected to Buffer C
[4] I have placed a buffer component on the FC Chart.

Now I have the following confusion.
(1) I should load my signal value into the Buffer A and B (setpoint) (FeedBack) before calling the Control Component Correct?
(2) after the execution of the call the PID output will be in Buffer C Correct?
(3) I have to take the output out from Buffer C and load it to my function that needs this value (for example the PWM component) ?
(4) I have made the buffer 1 level deep for A,B and C this I assume will calculate the output on a single input values Correct
(5) Does the component keep track of the error(execute integration)I do not have to do this in my code?
(6) FC link the Setpoint and Feedback together at the E input of the component so I assume the component calculate the Error?
(7) the delta T I should implement myself for example timer interrupt every X mSec and then execute the PID Component to have the T constant
(8) Do I need to set the limits for the output in my code(Anti windup) or does the component do this,I do not see a parameter for this in the PID
Component

Then in general the component is limited to signed and unsigned integers and bytes no floating point or Q15 support ? is this available for the dsPIC Control Component as that is one reason a person would use a dsPIC for it fast execution of control signals with DSP engine and Q15 :D in applications such as SMPS units specially if a person take into account that the dsPIC ADC can be configured to output Q15 format which even help more to speed up the control execution times :D

I appreciate you helping me out here, I do understand this is a bit of heavy stuff for a 8 bit machine however I only need to do this call every Sec so there is time for the small pic to catch up :D

User avatar
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: DSP Component Advise-Guidance

Post by Benj »

Hi Peter,

There are some examples here which may help to get you started.
https://www.matrixtsl.com/wikiv7/index. ... trol_(DSP)
(1) I should load my signal value into the Buffer A and B (setpoint) (FeedBack) before calling the Control Component Correct?
The Feedback buffer needs to be loaded with the current feedback measurement and the setpoint value is loaded via the parameter in the control->process component macro.
(2) after the execution of the call the PID output will be in Buffer C Correct?
Yes that's correct
(3) I have to take the output out from Buffer C and load it to my function that needs this value (for example the PWM component) ?
Yes the output component basically gives you the value so you can assign it to say PWM or whatever you are using.
(4) I have made the buffer 1 level deep for A,B and C this I assume will calculate the output on a single input values Correct
Yes this is probably the best way to use the control component to avoid delays.
(5) Does the component keep track of the error(execute integration)I do not have to do this in my code?
The component tracks things like previous error for you.
(6) FC link the Setpoint and Feedback together at the E input of the component so I assume the component calculate the Error?
The Feedback is fed in using a DSP buffer, the setpoint is fed in using the Process component macro parameter. See Q1.
(7) the delta T I should implement myself for example timer interrupt every X mSec and then execute the PID Component to have the T constant
Yes that's correct, you can use a delay or a timer interrupt if you want your program to do other things in the background.
(8) Do I need to set the limits for the output in my code(Anti windup) or does the component do this,I do not see a parameter for this in the PID
Component
The control output will currently limit itself to the bit depth you have provided without wrapping. If you need addition limits on top then you have to apply these to the output value yourself.
Then in general the component is limited to signed and unsigned integers and bytes no floating point or Q15 support ?
Currently the DSP components will work on any target device regardless of it's in-built functionality and the functionality included in the compiler. It's the Flowcode mentality that you can take code and run it on any supported device as long as it has enough memory etc. Relying on hardware features such as Q15 ADC sampling would likely cause us headaches so we don't include it. You could always write your own components to tackle or add something specific like this. I know Microchip like to use their own fractional data type in their DSP libraries to squeeze out a few more calculations per second but in my opinion this often makes using them horrendous.

Hope this helps and let us know how you get on.

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: DSP Component Advise-Guidance

Post by QMESAR »

Ben.

Thank you very much ,this helps a lot to get started using the Control component. :D
I will work with the examples ,I looked at them yesterday and this is were all the questions started to bug me,with your comments and the examples now it will make more sense for me

User avatar
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: DSP Component Advise-Guidance

Post by Benj »

Thanks Peter,

Hope it goes well and let us know if you have more questions.

There is a page on DSP and some theory here which may also help.
https://www.matrixtsl.com/wikiv7/index.php?title=DSP

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: DSP Component Advise-Guidance

Post by QMESAR »

Hi Ben.
Once again for your help ,I have the PID component running and working however I am a bit in trouble as the setpoint ADC signal has a positive slope and the feedback system have a Negative slope so using the ADC inputs directly is not working so well .

I am a bit confused what to do at the moment as I can not change the sensors on the machine :roll: to have the same slope between Setpoint and Feedback.
If I use a C call with hand written PID which calculate the errors between the two engineering values and then scale back to an PWM Duty cycle is possibly one way, I am just not sure how well this will work in FC(did this many times in Normal C code) I am afraid the debugging will be a problem.
This project is going to Switzerland and I am far away :D
Another way possibly would be the calcualte the temperatures and then scale them to integers values and then feed them to the Control Control Component ? :roll:

Just thought I let you know I have the FC Control Component working :D
1234.jpg
1234.jpg (30.91 KiB) Viewed 3920 times

User avatar
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: DSP Component Advise-Guidance

Post by Benj »

Hi Peter,

Great, glad it's working for you.

Can you invert either the control or the feedback before feeding to the DSP components.

Unsigned Int
value = 65535 - value

signed int
value = 0 - value

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: DSP Component Advise-Guidance

Post by QMESAR »

Hi Ben.

Again thank you for your help :D I changed the slope of the one sensor and the SW is running on the Plant with no issues
the DSP Control functions very well.

Have good time I appreciate your valuable help and advise :D :D :D

Post Reply