Documentation Home Page RT-LAB Home Page
Pour la documentation en FRANÇAIS, utilisez l'outil de traduction de votre navigateur Chrome, Edge ou Safari. Voir un exemple.

OpFcn Knock Generator

Block

Mask

Description

The functionality block OpFcnKnockGenerator is used to generate a knock signal on the Opal-RT OP6222 Reference Pulse Generation (RPG)board. This feature generates an analog signal using various signal sources determined by the engine positions. This feature is typically used to simulate the soundwave detected by a knock sensor connected to an ECU.

The block may control from 1 to 15 knock windows of configurable position and duration and assign an analog signal to each one of them. Another signal, called the noise signal, is produced when no knock windows are active. The source analog signals may be provided as sampled patterns stored in a MAT-file, by the BNC connectors the front of the RPG board or by an internally simulated oscillator.

The pattern MAT-file must contain two variables. The first one is a one-dimensional cell array where each cell defines one pattern. Each cell contains a one-dimensional array specifying the sequential pattern samples in volts. Any number of patterns may be defined and patterns may be of any lengths. The second variable is a single cell containing a one-dimensional array containing the sample rate in samples per second for each pattern. The length of this array must be equal to the number of patterns.

Here is an example of Matlab commands used to create a pattern MAT-file:

myPatternArray{1} = [0 0.5 1 0.5 0 -0.5 -1 -0.5] % first pattern,1 volts triangular wave
myPatternArray{2} = [0 1 2 1 0 -1 -2 -1] % second pattern, 2 voltstriangular wave
mySampleRates{1} = [100000, 500000] % the sample rates of each pattern
save MyFile.Mat mySampleRates myPatternArray -V6



Note: It is required that the MAT-File is saved in the V6 format. For MATLAB R13.X, V6 is the default format and the -V6 option does not exist.




Note: RPG Module bitstreams prior to revision 0x159 requires that the pattern MAT-File contents do not exceed a total of 8192 samples for all patterns combined. Later versions support MAT-files of any size but streaming is performed at each calculation step to provide the samples to the hardware during run-time, which may impact significantly on the model computation time. For those bitstream revisions, streaming is performed only when the total number of samples exceeds 12288 minus the number of samples reserved for the oscillator.




Note: The knock functionality did not become officially available until bitstream revision 0x152.


Parameters

ControllerNameEach functionality block such as the OpFcnKnockGenerator block must refer to an OpCtrl RPG Module block that will manage the link to the RPG card. The binding between OpFcn and OpCtrl blocks is performed via the use of the Controller name that each OpCtrl block uniquely defines. This binding is checked during the initialization phase of the model. If no OpCtrl block is found that defines the same controller Name as this OpFcnKnockGenerator block, the OpFcnKnockGenerator block is simply disabled.
Channel SelectionSpecifies which knock channel to use. Nodevice supports more than one channel, so 0 is the only possible channel.
Number of CylindersSpecifies how many cylinders events occur during one rotation cycle (usually defined as 0-720° cycles). Maximum possible value is 15.
Use Pattern FileSpecifies if a pattern MAT-file is to be used. If this option is selected, the knock and noise signals may either come from selected patterns or the BNC connectors. If this option is not used, the only signal sources available are the BNC connectors or ground signal.
The next five parameters are available only if the Use PatternFile option is checked.
Change Pattern File at Run-TimeThis option allows to either reload the pattern MAT-file or load a new one at run-time. When this option is selected, the content of the Pattern File Name, Pattern Variable, Sample Rates Variable can be updated through the RT-LAB Parameters panel. A block input is also created which the model can use to trigger the file read once the listed parameters have been updated and the file is available on the target. Note that using this option forces the knock application to operate in streaming mode and that files containing fewer than [12288 - Number of Samples per Period ] samples will not be stored in the firmware memory. This may impact significantly on the model computation time.
Pattern File NameName of the MAT-file with the pattern definitions. See the Description section for more details on the file format.
Pattern VariableName of the MAT-file variable that contains the pattern samples.
Sample Rates VariableName of the MAT-file variable that contains the pattern sample rates.
Use Sample Rate Factor InputsWhen selected, two new inputs will be created, allowing to apply factors to the knock and noise sample rates.
Use Oscillator SourceWhen selected, six new block inputs are created, allowing to control the internal oscillator.
The following parameter is available only if the Use OscillatorSource option is checked.
Number of Samples per PeriodThe internal oscillator uses a digital to analog converter to generate sinusoids. This parameter determines the number of samples used per sinusoid period. Increasing this value reduces harmonic distortion but requires more onboard memory and limits the maximum possible sinusoid frequency. The maximum possible value is 4096.
Sample Time (s)This parameter allows the user to specify the block sample time in seconds. The default value is 0, which specifies a continuous sample time (note that the sample time is borrowed from the separated subsystem) while -1 specifies an inherited sample time. A functionality block and its associated controller block must execute at the same sample time.

 Inputs

All the input widths are equal to the number of cylinders, except for the inputs related to the noise signal, which are single values. The first signal of each vectored input corresponds to the first cylinder knock signal.

KnockEnablesThis vector enables each cylinder individually. A value of 1 means the knock window shall be generated for the associated cylinder.
KnockStartsThis vector defines the start position of each knock signal in degrees.
KnockDurationsThis vector defines the duration of each knock signal in degrees.
KnockSources

This vector selects the signal source for each cylinder.

The following values are possible:


ValueDescription
-2Use the internal simulated oscillator.
-1Leave the output floating.
0Use the BNC KNOCK IN connector on the front of the RPG.
1 and aboveUse a sampled pattern. Corresponds to the index in the pattern cell array from the MAT-file.

Noise Source: This signal selects the signal source for the noise. The following values are possible:

ValueDescription
-2Use the internal simulated oscillator.
-1Leave the output floating.
0Use the BNC NOISE IN connector of the RPG.
1 and aboveUse a sampled pattern. Corresponds to the index in the pattern cell array from the MAT-file.

The following inputs are available only if a MAT-file is used.

KnockPattern OffsetsThis vector specifies, for each knock window, the sample (starting with 0) at which the pattern generation will start. For instance, if 4 is specified, pattern generation will start with the 5th sample for the related cylinder.
NoisePattern OffsetThis value specifies, for the noise signal, the sample (starting with 0)at which the pattern generation will start. For instance, if 4 is specified, the noise generation will start with the 5th sample.
KnockLoop EnablesThis vector specifies, for each cylinder, if the generated pattern is to be repeated until completion of the knock window (should the window last longer than the pattern). Provide 1to repeat the pattern or 0 for a single generation.
NoiseLoop EnableThis input specifies if the noise pattern is to be repeated until the next knock window or played only once. Provide 1 to repeat the pattern or 0 for a single generation.
KnockSample Rate FactorsThis vector defines the multipliers to be applied to the pattern sample rates associated with each cylinder. The effective rates are the rates defined in the MAT-file, multiplied by these factors. For instance, considering a rate value of 1000 S/sand an input value of 0.5, the sample rate of the pattern will be1000 * 0.5 = 500 S/s.
NoiseSample Rate FactorThis signal defines the factor to be applied to the noise pattern sample rate. The effective rate is the rate defined in the MAT-file, multiplied by this factor.
For instance, considering a rate value of 1000 S/s and an input valueof 0.5, the sample rate will be 1000 * 0.5 = 500 S/s.
Reload Pattern FileThe application reloads the pattern MAT-file when this input is 1. Available only if Change Pattern File at Run-Time is selected.
The following inputs are available only if the oscillator is used.
Knock Oscillator AmplitudesThis vector specifies the oscillator amplitudes (in volts) associated with each cylinder. The maximum value is 2.5 volts.
Noise Oscillator AmplitudeThis input specifies the oscillator amplitude (in volts) associated with the noise signal. The maximum value is 2.5 volts.
Knock Oscillator FrequenciesThis vector specifies the oscillator frequency in hertz associated with each cylinder. See the characteristics and limitations section for details.
Noise Oscillator FrequencyThis input specifies the oscillator frequency associated with the noise signal. See the characteristics and limitations section for details.
Knock Oscillator PhasesThis vector specifies the oscillator phase in degrees associated with each cylinder. May be any positive or negative value.
Noise Oscillator PhaseThis input specifies the oscillator phase in degrees associated with the noise signal. May be any positive or negative value.

Outputs

Error: This output will report errors should any occur. The output width is equal to the number of cylinders plus one. A signal is dedicated for each cylinder and the last signal is for the noise generation. The possible values are:

ValueDescription
1The application is currently loading a pattern MAT-File. Activity on the Reload Pattern File is ignored while this status is reported. This value must not be interpreted as an error. 
0No errors
-1Invalid signal source. The value on the Noise Source or Knock Sources inputs is invalid. Beware of values higher than 0 when no MAT-file is used or values exceeding the number of patterns are submitted. The last valid source is used when an error is detected.
-2The sample rate exceeds the range possible by the current hardware and was saturated to the highest or lowest possible value. This may also indicate an oscillator frequency set too high.
-3At least one voltage value in the pattern file exceeded the range possible by the current hardware and was saturated to the highest or lowest possible value. Possible range is [-2.5 2.5] volts.
-4The offset specified on the Knock Offsets or Noise Offset input is invalid. It is either negative or exceeds the pattern length. The last valid offset is used.
-5The Knock Start and Duration inputs describe an invalid knock windows pattern. The rules are:
- The windows must be in the correct order
- No windows may overlap
- Only one window may pass over 0°
The last valid start/stop sequence is used.
-6The Engine Synchronous Pulse Generation functionality of the RPG is essential for the operation of the Knock feature. This error code indicates that no OpFcn Engine Sync Pattern Gen block is associated with the selected controller.
-7The oscillator amplitude exceeds the [-2.5 2.5] volts range. The amplitude was saturated to that interval.
-8The specified sample rate factor is invalid (smaller or equal to 0). A unit factor was used instead.
-9The Number of Sample per Period oscillator exceeds 4096 and 4096 was used instead of the specified value.
-10One of the sample rates specified in the MAT-file exceeded 15,626,000 S/s and was saturated to this value.
-11The pattern MAT-File could not be loaded at run-time. The means that the MAT-File is either invalid or could not be found. 

Characteristics and Limitations



NOTE: The voltage range specified in the MAT-file must be in the range [-2.5 2.5] volts. Due to the hardware design of the RPG.




NOTE: The maximum possible oscillator frequency may be calculated using:

Frequency Max (Hz) = 15,626,000 / Number of Samples per Period




NOTE: When using MAT-file patterns, the maximum possible sample rate is 15,626,000 samples per second when the MAT-file is small enough to be stored in the onboard RAM. When the MAT-file is larger, the maximum possible sample rate is determined by:

Sample Rate Max = (12,288 - Number of Samples perPeriod) / (2 * Model Sample Time).



IMPORTANT: The circuit design filters any DC component from the generated output, no matter which signal sources (MAT-file, BNC connectors)are used for the noise or knock windows. These same filters may also eliminate signal components or introduce propagation delays, resulting in signals that may differ from those provided as sources.



NOTE: Starting from bitstream revision 0x15D, the generation of a knock window is interrupted if the engine speed is set to 0 RPM and noise is produced instead. In such a situation, previous knock revisions would have continued generating the current knock window as long the speed would have remained at 0.


Direct FeedthroughNo
Discrete sample timeNo
XHP supportNo
Work offlineNo

OPAL-RT TECHNOLOGIES, Inc. | 1751, rue Richardson, bureau 1060 | Montréal, Québec Canada H3K 1G6 | opal-rt.com | +1 514-935-2323