View source for Matlab/Simulink files
You do not have permission to edit this page, for the following reason:
You can view and copy the source of this page.
Return to Matlab/Simulink files.
You do not have permission to edit this page, for the following reason:
The action you have requested is limited to users in one of the groups: Administrators, Bureaucrats.
You can view and copy the source of this page.
Return to Matlab/Simulink files.
Creating a custom S-function block requires the addition of four files to the MatLAB/Simulink project.
File location: ./blockset/toolbox/STM32/blocks/sfcn_signal_tower.m
Each layer of the signal tower requires three input ports: one for each RGB color.
As there are four layers, a total of twelve input ports are created in the setup function.
Notice that the DataTtypeID of each port is set to 3, which means that the ports requires data of type uint8_T.
The range of a uint8_T variable is 0-255.
The S-function requires two dialog parameters:
This number of parameters is set by the following line of code:
block.NumDialogPrms = 2;
File location: .\blockset\toolbox\STM32\blocks\sfcn_signal_tower_chk.m
The Olimexino STM32 features two SPI channels. This function checks if there more than two signal tower blocks in the model and will generate an error message.
File location: .\blockset\toolbox\STM32\blocks\sfcn_signal_tower_mcb.m
The function sfcn_signal_tower_mcb takes two parameters:
The function returns a human readable string with information about the each channel.
Information about the hardware_ID is omitted, because this is always the same for this example project.
The value of the variable channelStr is what will be used in the C-code. The value of channelStr depends on channel, which is selected by the user in the block's dialog.
File location: .\blockset\toolbox\STM32\blocks\tlc_csfcn_signal_tower.tlc
This file is the target language compiler (TLC) file that contains the code generation specifics.
The file starts by including the header file ws2812b.h
This file contains two functions:
This function is called once when the model starts. In this function the ws2812b_init() function is called for initializing the target hardware.
The channel parameter is read from the block by using the MatLAB macro %<block.RTWdata.channel>.
This function is called whenever the block must be updated.
The function reads the value of each of the twelve input ports by using a MatLAB macro, such as %<LibBlockInputSignal(0, "", "", 0)>.
The rest of the function is implemented in plain C-code. The port values are shifted to the correct positions and finally the ws2812b_write() function is called for assigning the new values to the LEDs.