Access current time with high precision within Function-Call Subsystem (Simulink Coder with Nucleo board: External Interrupt block)

2 views (last 30 days)
I am working on estimating the rotor speed of a motor (PMSM) that includes three digital Hall position sensors. The model is flashed into a ST Nucleo board H743ZI2 with Ts=1e-3.
Part of this is the interrupt-based measurement of the three sensors' signals' period duration, which needs to be as accurate as possible (so, not just a multiple of the fundamental sampling time of the model).
On the left you can see the External Interrupt block
and on the right is the content of the Function-Call Subsystem. The unit delay block has sample time -1, so it stores the time value from the last time this Function-Call Subsystem was executed. This way, by just storing the current time (as accurately as possible, so with microsecond precision?), and outputting the difference, the ISR is very fast because no computations have to be done in there internally.
I use three of these structures for the three sensors, in order to obtain an estimate of the current rotor speed from the time between two rising edges.
However, done this way, my model does not compile but gives me no understandable error message (see attachment). My guess is that the "Digital Clock" block inside the Function-Call Subsystem is the issue, because my model works if I use a regular "Clock" block on the top level of the model, a Rate Transition block, and an Input port to the Function-Call Subsystem to supply the time information. But this way, the time resolution is limited by the fundamental sampling time (1 ms in my case), which is why I want to avoid this.
My question is: How can I access the current time that has elapsed since the Nucleo board was started (with high accuracy) within a Function-Call Subsystem, so NOT synchronous to the regular model update every <Ts> seconds, but whenever an External Interrupt arrives?
Essentially, I am looking for an alternative to the "Digital Clock" block that works within Function-Call Subsystems and outputs the time even between fixed-step-size updates of the model.
Thank you!

Answers (0)


Find more on Schedule Model Components in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by