Go Down

Topic: Current control, update time (Read 430 times) previous topic - next topic

jacko91

Good day folks,

so I want to implement a current  control for a BLCD Motor. The measurement of the current works fine. I implemented a PI Controller. Currently the updated time is about every 3ms, so around 300Hz. For a inner control loop this is way to long. I am using a uno, is there a better and faster arduino board or would you recommend any other board for faster controlling?

Thanks you very much

PaulS

What I would recommend is that you post the code that is too slow. Perhaps there is something it is doing that is not necessary, which could be removed to speed things up.

I don't know what you mean by "updated time". Perhaps an extra d slipped in there, and you meant "update time".
The art of getting good answers lies in asking good questions.

jacko91

Hey,

yes I meant the update time the loop needs.
Code: [Select]
void loop() {
i=map(analogRead(A2),0,1023,0,60);
Setpoint=i;
current_mA = ina219.getCurrent_mA();
shuntvoltage = ina219.getShuntVoltage_mV();
current_filt=0.95*current_filt+0.05*current_mA;
Input=current_filt;
myPID.Compute();
analogWrite(9,255-Output);
//analogWrite(9,255-i);
//Serial.print(Setpoint);
//Serial.print(",");
//Serial.print(Output);
//Serial.print(",");
//Serial.print(millis()-ti);
//Serial.print(",");
ti=millis();
Serial.print(current_filt,3);
Serial.print(",");
Serial.println(Setpoint,3);
}

wildbill

What baud rate are you using? Indeed, why are you serial printing anything at all if speed is an issue?

How often does the PID actually compute anything? - the version I use defaults to a SampleTime of 100ms.

jacko91

Hey,
baud rate 115200
I use serial.print to get the setpoint and the real value to evaluate the parameters of the control.
The PID sample time is set to 15ms.

wildbill

The PID sample time is set to 15ms.
Given this, what's the issue with loop taking 3ms? Do you have a lot more to do that hasn't been written yet? If so, you could do the analogRead and associated calc less frequently - there's no point doing it until the PID needs it. Also, IIRC, I think you can do the analogRead asynchronously.

To answer your original question though, a Teensy or Due run significantly faster than an Uno.

jacko91

Thanks,

yes you are right, it makes no sense to run it more often then the controller. What do u mean with IIRC?
And thanks for the teensy tip, I always thought it was a small and slow arduino, but looking at the specs it looks awesome.

wildbill

IIRC == If I recall correctly

Go Up