DSP PID control

For general Flowcode discussion that does not belong in the other sections.
Post Reply
jollybv
Posts: 136
http://meble-kuchenne.info.pl
Joined: Mon Mar 08, 2021 11:25 am
Location: Cape Town South Africa
Has thanked: 41 times
Been thanked: 12 times

DSP PID control

Post by jollybv »

Hi guys
I'm trying to understand how to do the PID processing in V9, in the ProcessPID macro in the attached file I'm doing the following

DSPInput::AddByte(feedback)

then I'm not sure how to process

ProcessPID=DSPControl::GetPIDPortions(Setpoint)
DSPControl1::Process()

Control=DSPOutput1::Getint()
PWM1::SetDutyCycle(Control)

I have looked at the help file on the PID Control in WIKI and the example is the same as the V7 which dose not work as there is no DSPSystem1 component in V9 so really not sure what to do here.
PID_Control_SPI_V9_test.fcfx
(42.41 KiB) Downloaded 525 times

BenR
Matrix Staff
Posts: 1952
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 510 times
Been thanked: 698 times

Re: DSP PID control

Post by BenR »

Hello,

Many thanks for letting us know. I've reworked the examples for both PID and OnOff control and hopefully the wiki pages are now more up to date.

Having a look at your project file now.

BenR
Matrix Staff
Posts: 1952
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 510 times
Been thanked: 698 times

Re: DSP PID control

Post by BenR »

I've reworked your example file a bit and hopefully it now makes a bit more sense.
PID_Control_SPI_V9_test.fcfx
(42.74 KiB) Downloaded 589 times
At the moment the setpoint and feedback will be fed into the DSP chains as bytes with integer type numbers and so your 0.25 degree increments will be lost. If you want higher precision then one way would be not to multiply the feedback by 0.25 and instead have all your units based on 0.25 degree integers. So a setpoint of 4 would be asking for a temperature of 1 degree.

Hopefully that makes sense ;)

jollybv
Posts: 136
Joined: Mon Mar 08, 2021 11:25 am
Location: Cape Town South Africa
Has thanked: 41 times
Been thanked: 12 times

Re: DSP PID control

Post by jollybv »

Hi Ben

Thanks for the reply, if I'm understanding you correctly what I should do is take RawData * 0 .25 out and multiply the setpoint by 4 this should give me the correct value to process. After processing then divide setpoint by 4 again for it to display the correct setpoint temp value on display and multyply the fedback by 0.25 so i can display the feedback temp.

jollybv
Posts: 136
Joined: Mon Mar 08, 2021 11:25 am
Location: Cape Town South Africa
Has thanked: 41 times
Been thanked: 12 times

Re: DSP PID control

Post by jollybv »

Hi Ben

I"m having a problem with the PWM and the accuracy of the temp its out about 5 degrees which is quite a lot, I think I have done this correct (So a setpoint of 4 would be asking for a temperature of 1 degree) plus the PWM only starts to work when the temp gets close to the setpoint. It is off before the setpoint (so how dose it heat) and after the set point it switches off again which is correct (if it over shoots elements are off). So not sure what is wrong with PWM
PID_Control_SPI_V9_test2.fcfx
(49.56 KiB) Downloaded 455 times

BenR
Matrix Staff
Posts: 1952
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 510 times
Been thanked: 698 times

Re: DSP PID control

Post by BenR »

Hello,

You had some problems with data truncation you were passing values as bytes but your initial setpoint of 78 *4 = 312 which was then passed as a byte which truncated the value to 56.

Here is a program with the bytes replaced with UINTs and hopefully it behaives a bit better for you.
PID_Control_SPI_V9_test2.fcfx
(50.42 KiB) Downloaded 512 times

jollybv
Posts: 136
Joined: Mon Mar 08, 2021 11:25 am
Location: Cape Town South Africa
Has thanked: 41 times
Been thanked: 12 times

Re: DSP PID control

Post by jollybv »

Thanks Ben
I will give it a try and let you know.

Post Reply