Real-Time Workshop | ![]() ![]() |
Sample Rate Limits
Program timing is controlled by installing an interrupt service routine that executes the model code. The target PC's CPU is then interrupted at the specified rate (this rate is determined from the step size).
The rate at which interrupts occur is controlled by application code supplied with Real-Time Workshop. This code uses the PC-AT's 8254 Counter/Timer to determine when to generate interrupts.
The code that sets up the 8254 Timer is in drt_time.c
, which is in the matlabroot
\rtw\c\dos\rti
directory. It is automatically linked in when you build the program using the DOS real-time template makefile.
The 8254 Timer is a 16-bit counter that operates at a frequency of 1.193 MHz. However, the timing module drt_time.c
in the DOS run-time interface can extend the range by an additional 16 bits in software, effectively yielding a 32-bit counter. This means that the slowest base sample rate your model can have is
This corresponds to a maximum base step size of approximately one hour.
The fastest sample rate you can define is determined by the minimum value from which the counter can count down. This value is 3, hence the fastest sample rate that the 8254 is capable of achieving is
This corresponds to a minimum base step size of
However, note that the above number corresponds to the fastest rate at which the timer can generate interrupts. It does not account for execution time for the model code, which would substantially reduce the fastest sample rate possible for the model to execute in real time. Execution speed is machine dependent and varies with the type of processor and the clock rate of the processor on the target PC.
The slowest and fastest rates computed above refer to the base sample times in the model. In a model with more than one sample time, you can define blocks that execute at slower rates as long as the sample times are an integer multiple of the base sample time.
Modifying Program Timing
If you have access to an alternate timer (e.g., some I/O boards include their own clock devices), you can replace the file drt_time.c
with an equivalent file that makes use of the separate clock source. See the comments in drt_time.c
to understand how the code works.
You can use your version of the timer module by redefining the TIMER_OBJS
macros with the build command. For example, in the Real-Time Workshop pane of the Simulation parameters dialog box, changing the build command to
replaces the file drt_time.c
with my_timer.c
in the list of source files used to build the program.
![]() | System Configuration | Device Driver Blocks | ![]() |