Generate ramp output
Embedded Coder^{®} Support Package for Texas Instruments™ C2000™ Processors/ Optimization/ C28x DMC
Embedded Coder Support Package for Texas Instruments C2000 F28M3x Concerto™ Processors Processors/ Optimization/ C28x DMC
This block generates ramp output (out
) from the slope of the
ramp signal (gain
), DC offset in the ramp signal
(offset
), and frequency of the ramp signal (freq
)
inputs. All of the inputs and output are 32bit fixedpoint
numbers with Q values between 1 and 29.
The block's output (out
) at the sampling instant
k is governed by the following algorithm:
out
(k) = angle(k)
* gain
(k) +
offset
(k)
For out
(k) > 1,
out
(k) =
out
(k)  1. For
out
(k) < 1,
out
(k) =
out
(k) + 1.
Angle(k) is defined as follows:
angle(k) = angle(k1) +
freq
(k) * Maximum step
angle
for angle(k) > 1, angle(k) = angle(k)  1
for angle(k) < 1, angle(k) = angle(k) + 1
The frequency of the ramp output is controlled by a precision frequency generation algorithm that relies on the modulo nature of the finite length variables. The frequency of the output ramp signal is equal to
f = (Maximum step angle * sampling rate) / 2^{m }
where m represents the fractional length of the data type of the inputs.
All math operations are carried out in fixedpoint arithmetic, where the fixedpoint fractional length is determined by the block's inputs.
Note
To generate optimized code from this block, enable the TI
C28x
or TI C28x (ISO)
Code Replacement
Library.
The maximum step size, which determines the rate of change of the output (i.e., the minimum period of the ramp signal).
When you enter doubleprecision floatingpoint values for parameters in the IQ Math blocks, the software converts them to singleprecision values that are compatible with the behavior on c28x processor.
The following model demonstrates the Ramp Generator block. The Constant and Scope blocks are available in Simulink^{®} Commonly Used Blocks.
In your model, select Simulation > Model Configuration
Parameters. On the
Solver pane, set Type to
Fixedstep
and Solver to
Discrete (no continuous states)
.
Set the parameter values for the blocks as shown in the following table.
Block  Connects to  Parameter  Value 

Constant (Simulink)  Ramp Generator  


Constant (Simulink)  Ramp Generator  


Constant (Simulink)  Ramp Generator  


Scope (Simulink) and Floating Scope (Simulink) (Simulink block) 


When you run the model, the Scope block generates the following output (drag a zoom box around a portion of the output to change the display).
With fixed point calculations in IQMath, for a given frequency input on the block, f_input, the equation is:
f = (Maximum step angle * f_input * sampling rate) / 2^{m}
For example, if f_input = 0.001, the real value, 1, counts as fixed point with a fractional length of 9:
f = (1 * 1 * (1/0.001) ) / 2^{9} = 1.9531 Hz
Where 0.001 is the block sample time.
If we use normal math, and f_input is a nonfixed point real value, then:
f = (Maximum step angle * f_input * sampling rate) / 1
For example, if we are using floating point calculation:
f = (1 * 0.001 * (1/0.001) ) / 1 = 1 Hz
When using fixed point with fractional length 9, the expected period becomes:
T = 1/f = 1/1.9531 Hz = 0.5120 s
This result is what the above Scope output shows.
Note
If you use different fractional lengths for the fixed point calculations, the output frequency varies depending on the precision.