Main Content

Generate Variant Coding Section in ASAP2 File

This example shows how to generate a variant coding section in an ASAP2 (A2L) file. A variant coding section in an ASAP2 file contains the variant criterion and variant selection characteristics.

With variant parameters, you can represent different variants of a system. You can incorporate variant parameters in any Simulink® block. The code that you generate for variant parameters represent the possible values of a system. For more information, see Use Variant Parameters to Reuse Block Parameters with Different Values.

To export variant coding section to an A2L file, a Simulink model must contain:

Open and Configure the Model

This example uses the VariantCodingDemo.slx model. This model takes a battery voltage as input, verifies if the voltage is with in the minimum and maximum voltage levels. The minimum and maximum voltage levels vary based on the type of engine and they are configured using the variant parameters. The model then outputs a signal indicating whether the input battery voltage signal is valid or not.

In this example, variant parameters are created for the minimum and maximum battery voltages.

  1. Open the example model.

open_system("VariantCodingDemo");

  1. Define an enumeration type for Energy to specify different variants.

Simulink.defineIntEnumType('Energy', ...
    {'Diesel','Petrol','Electric'}, ...
    [0 1 2], ...
    'DefaultValue', 'Diesel', ...
    'StorageType', 'int16', ...
    'Description', 'Energy EnumClass definition', ...
    'AddClassNameToEnumNames', false);

2. Create the variant control variable and assign the enumerated values defined in step 1.

EnergySelector = Simulink.VariantControl(Value = Energy.Electric, ActivationTime = 'startup');

3. Create a variant bank and define the variant conditions.

EnergyVariantCriterionInfo = Simulink.VariantBank(Name='VariantConditionsForEnergy',... 
	Description='Possible Variant Conditions for Energy', VariantConditions={... 
	'EnergySelector == Energy.Electric',... 
    'EnergySelector == Energy.Diesel',... 
	'EnergySelector == Energy.Petrol'});

4. Create variant variables for minimum and maximum battery voltage values.

% Minimum battery voltage threshold for different variants
BattVoltMin = Simulink.VariantVariable(Choices={...
    'EnergySelector == Energy.Electric', 47.5,...
    'EnergySelector == Energy.Diesel', 11.8,...
    'EnergySelector == Energy.Petrol', 12.2});

% Maximum battery voltage threshold for different variants
BattVoltMax = Simulink.VariantVariable(Choices={...
    'EnergySelector == Energy.Electric', 48.5,...
    'EnergySelector == Energy.Diesel', 12.2,...
    'EnergySelector == Energy.Petrol', 12.8});

5. Associate the variant bank with the variant variable.

BattVoltMin.Bank='EnergyVariantCriterionInfo';
BattVoltMax.Bank='EnergyVariantCriterionInfo';

6. Optionally, you can create a Simulink.Parameter and associate it with specification it with the variant variables to define its properties.

VoltageParam = Simulink.Parameter;
VoltageParam.Value = 12;
VoltageParam.Complexity = 'real';
VoltageParam.CoderInfo.StorageClass = 'Auto';
VoltageParam.Description = 'Reference parameter for Battery Voltage';
VoltageParam.DataType = 'fixdt(1,16,0.01,0)';
VoltageParam.Min = -100;
VoltageParam.Max = 100;
VoltageParam.DocUnits = 'V';
BattVoltMin.Specification='VoltageParam';
BattVoltMax.Specification='VoltageParam';

7. Save the model.

Build and Generate A2L File

Build the model and generate the A2L file.

slbuild('VariantCodingDemo');
coder.asap2.export('VariantCodingDemo');

Verify that the A2L file contains a variant coding section.

Limitations

  • Generating a variant selection characteristic is not supported for ASAP2 versions before 1.61, per ASAM specifications.

See Also

| | |

Topics