<PID_v1.h> myPID.Compute() function in IntervalTimer on Teensy 3.5

Status
Not open for further replies.

Lorenzo

Well-known member
Hi everybody,

I am trying to use the library <PID_v1.h> in Teensy 3.5. In particular I would like to execute the myPID.Compute(); inside an IntervalTimer function at a frequency of 1 kHz. Inside the function I also increase a counter (motor_control_counter) that I print on the serial monitor every second. The timer seems not to respect the 1000ms.
Does anybody knows what is the maximum delay caused by the PID function?
Why Teensy 3.5 does not stop if the time interval is not respected?

Thank you very much in advance.


Code:
void functionMotorControlTimer()
{
  unsigned long t_setpoint = millis() * 1000;
  float freq = 2.0f;
  float sin_setpoint=2.5f*sin(t_setpoint*2*pi*freq)+10.0f;
  Setpoint1=(double)(sin_setpoint);

  noInterrupts();
  Input1 = (double)(LC_1);
  interrupts();

  myPID1.Compute();

  float Output1b = (75.0f / 1865.0f) + 1865.0f - (float)(Output1);
  Output1b = round(Output1b);
  channel_1 = (uint16_t)Output1b;
  
  motor_control_counter++;
  motor_control_time=millis();
}
 
Status
Not open for further replies.
Back
Top