I'm currently working with embedded system implemented on SMT32F103C8T6 Blue Pill microcontroller based on FreeRTOS. I want to control the velocity and position of DC motor using PID controller. For the position control, i got no problem at all. But, for the velocity control, i'm confused on how do i get the time difference for calculating the sum of error (for integral controller) and delta of error (for derivative controller). sum_error += current_error * delta_time; diff_error = (current_error - prev_error)/delta_time;
In most applications, we could use time = millis() - prevMillis;. But in FreeRTOS, we shall not use millis, as it would disturb the task schedulling of the RTOS.
So, is there any other way to get the time difference? Notes: I've tried using a constant value of 0.01 (ms), but it doesn't work (the PID controller seems not working).