Problem With Using PID Library

Hi Everyone, I'm searching about my problem with PID library, but I couldn't find anything helpful.

I'm working on a project in which I have to use PID Library (PID_v1.h). I need to know how can I evaluate my algorithms faster. By "setSampleTime", we have to set time in milliseconds but I need to do my evaluations in Microseconds... Is it possible? If yes, please tell me how.

Thanks for your time

Do you mean that you wish to call the PID function more than 1000 times per second?

If so, how often do you wish to call it?

Have you done some tests to see how much time is required to do a PID calculation?

...R

In fact my sample frequency is about 16Khz and I don't know how long does it take to finish calculation.

I think I can do a test with millis() to determine the calculation time.

So is it possible to change the sample time of PID evaluation?

Find out how long the calc takes - you can measure it using micros.

If it's fast enough you can make a simple tweak to the library to have it use micros instead of millis for its time calculation.

What are you trying to control?

wildbill:
Find out how long the calc takes - you can measure it using micros.

If it's fast enough you can make a simple tweak to the library to have it use micros instead of millis for its time calculation.

thank you, i'll test it. but I don't know how to make changes in library...

I'm trying to read the output current of my converter. Its value is changing so fast (in micros) and I have to know its value to set an appropriate algorithm on it.

You're NOT going to get anywhere near 16K updates/second with the PID library. It does mostly floating point calculations, and takes something near 1mSec per update to do the calculations.

Personally, unless you're controlling something moving at REALLY extreme speed, you're barking up the wrong tree. PIDs RARELY require such a high update rate.

You need to explain what it is you're really trying to do, because you are almost certainly going down the wrong path with your current approach.

Regards,
Ray L.

My converters output current will change by some mathematics equations and generates its Mosfet gate pulse to switch appropriately to my goal.

So I use PID for first step of my control strategy.

In fact, I Simulated my project in Matlab (Simulink), and now I'm trying to do it in real.

So I use PID for first step of my control strategy.

As you will discover, this won't work. But it will be a good learning experience.

Doomaj:
My converters output current will change

We don't know what "converter" you are talking about. Give us the details so we understand the context of your questions.

...R