| Contents | Index |
hw_timer_obj = rtw.connectivity.Timer
| Constructor | Description |
|---|---|
| rtw.connectivity.Timer | Create timer object |
If your hardware target does not have built-in timer support, you must create a timer object that provides details of the hardware-specific timer and any associated source files.
To create this timer object, you must create an object of type rtw.connectivity.Timer. For example,
hw_timer_obj = rtw.connectivity.Timer
You may use the rtw.connectivity.Timer class directly or make a subclass of rtw.connectivity.Timer. Use the following methods to configure the hardware timer object.
| Method | Syntax and Description |
|---|---|
| setTimerDataType | hw_timer_obj.setTimerDataType(data_type); |
| Specify data type. Select 'uint8', 'uint16',
or 'uint32'. For example, TimerObj.setTimerDataType('uint32'); | |
| setTicksPerSecond | hw_timer_obj.setTicksPerSecond(no_ticks_ps) |
Specify number of timer ticks per second. For example, if timer
runs at 1 MHz, then number of ticks per second is 106. ticksPerSecond = 1e6; TimerObj.setTicksPerSecond(ticksPerSecond); Property is empty if you do not specify a rate. | |
| setCountDirection | hw_timer_obj.setCountDirection(direction) |
| The default value is 'up', which assumes
that the hardware timer increments with each clock cycle. If your
hardware timer decrements with each clock cycle, set the value to 'down'. For example, TimerObj.setCountDirection('down'); | |
| setReadTimerExpression | hw_timer_obj.setReadTimerExpression(valid_C_expression) |
Specify string to read timer. String must be a valid C expression,
for example, function call 'read_timer()', or name
of timer register that can be read directly. readTimerExpression = 'micros()'; TimerObj.setReadTimerExpression(readTimerExpression); | |
| setSourceFile | hw_timer_obj.setSourceFile(timer_source_file); |
| Specify name of source file that defines timer read function.
Name must include file path. Required if you are providing a custom source file that defines timer read function. For example, timerSourceFile = fullfile(matlabroot,...
'toolbox',...
'rtw',...
'targets',...
'pil',...
'c',...
'host_timer_x86.c');
TimerObj.setSourceFile(timerSourceFile);
| |
| setHeaderFile | hw_timer_obj.setHeaderFile(header_file) |
| Specify name of header file that has function prototype for
timer read function. Name must include file path. File may specify function prototype or define macro for accessing timer register directly. For example, headerFile = fullfile(matlabroot,...
'toolbox',...
'rtw',...
'targets',...
'pil',...
'c',...
'host_timer_x86.h');
TimerObj.setHeaderFile(headerFile); |
The following listing TimerX.m is an example of how you create a subclass of rtw.connectivity.Timer:
classdef TimerX < rtw.connectivity.Timer
methods
function this = TimerX
% Configure data type returned by timer reads
this.setTimerDataType('uint32');
% The micros() function returns microseconds
ticksPerSecond = 1e6;
this.setTicksPerSecond(ticksPerSecond);
% The timer counts upwards
this.setCountDirection('up');
% Configure source files required to access the timer
timerSourceFile = fullfile(matlabroot,...
'toolbox',...
'rtw',...
'targets',...
'pil',...
'c',...
'host_timer_x86.c');
headerFile = fullfile(matlabroot,...
'toolbox',...
'rtw',...
'targets',...
'pil',...
'c',...
'host_timer_x86.h');
this.setSourceFile(timerSourceFile);
this.setHeaderFile(headerFile);
% Configure the expression used to read the timer
readTimerExpression = 'micros()';
this.setReadTimerExpression(readTimerExpression);
end
end
end

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |