3 ms·
Just a small correction, related to your specific example. Controlling the motor is a real-time digital control system task, and it needs to be executed at exa
by deepspace 6y ago
Just a small correction, related to your specific example.
Controlling the motor is a real-time digital control system task, and it needs to be executed at exact time intervals, otherwise you introduce noise and instability into the control loop. "Accelerometer has new data" is a terrible trigger for the control loop. You always want to execute the controller at fixed intervals, triggered by a timer interrupt.
Once you enter that timer ISR though, you are correct. You need to run the whole thing, starting with adjusting the PWM according to the result of the previous control loop, then sampling the sensors and finally running the control algorithm, all before exiting the ISR. This is the epitome of a "hard real-time" requirement.
- barbegal 6y ago> Controlling the motor is a real-time digital control system task, and it needs to be executed at exact time intervals This is correct but also the accelerometer data needs to be sampled at the same interval. For this reason, running the control algorithm in lock step with the sensor may be sensible.
- deepspace 6y agoTrue, but sensors do not generally output data at fixed intervals, which is why the most common method is to have the control loop run on a timer interrupt and to have it sample the sensor.