[LSM6DSOX FSM finite state machine understanding]--Programming module introduction
[Copy link]
This post was last edited by justd0 on 2020-4-22 09:52
At the beginning of this chapter, I will share in detail my understanding of the programming module in the FSM of LSM6DSOX . If you don’t know what the FSM state machine is, please read LSM6DSOX’s FSM finite state machine understanding--state machine introduction first.
In this chapter, I will introduce the meaning of each module, area, and variable from the FSM programming module to the Unico FSM programming interface, laying the foundation for writing your own FSM state machine program. Let's get started.
In the previous post , it was introduced that there are 16 completely independent state machine blocks with the same resources in the FSM of LSM6DSOX . So what does each block look like?
A state machine program block contains two parts: input selector and state machine code block .
The input selector can select the input signal source from the sensor signal or the internal calculated data signal. The supported signals are as follows:
- LSM6DSOX accelerometer data, magnitude of acceleration and vector.
- LSM6DSOX gyroscope angular rate data, angular velocity and vector modulus.
- External sensor ( such as magnetometer ) data, magnetic force and vector magnitude.
- Internally calculated angles, angles and vector magnitudes ( what is this ... )
- Output of a properly configured machine learning module.
Among them, the module calculation method of the above-mentioned spatial physical quantities and vectors is as follows:
How to select the input FSM signal source ? This involves a command " SINMUX ". This command can be used to configure different data to the data source of the FSM . I will explain the specific usage in the command introduction ~
The state machine code block is the functional module for realizing our own state machine. As shown in the figure below, the state machine code block consists of fixed variables, variable variables, and instruction programs :
The fixed variable area is located at the front end of the program block, with a fixed length of 6 bytes, a total of 6 variables, which are automatically updated according to the configuration system and do not need to be changed by yourself.
The variable variable area is located after the fixed variable area. Its length changes with usage. It is up to 36 bytes long . There are 24 variables in total, which can be set as needed.
The instruction program area is located after the variable area and consists of conditions and commands. The command " SINMUX " that controls the input selector is set in this area.
The total length of the above three areas in the state machine code block is up to 256 bytes. Each time the power is turned on, the FSM code block content needs to be reconfigured .
Each state machine code block can generate an interrupt signal and modify the corresponding FSM_OUTS register state according to the input signal sampling set data.
Next, we will introduce the relevant contents of the above state machine program blocks in combination with the FSM interface of the UnicoGUI software .
If you have any questions about how to connect the development board and start the UnicoGUI software , you can refer to LSM6DSOX Unboxing and Experience "Port not open & not supported" problem solution .
It is assumed here that everyone can open the UnicoGUI software normally.
On the left side of the main interface of Unico , click on the FSM module, and you can see that there are three tabs in the interface: Configuration , Interrupt , and Debug .
The default interface is the state machine setting and programming interface, as shown in the figure below.
In this interface, we can see that there are many buttons and input boxes. Referring to the FSM usage .pdf file on Unico , I marked 8 red box areas. Let's take a look at them one by one :
1. StateMachine Selection , state machine selection . There are 16 options in this drop-down menu , corresponding to the 16 independent state machine program blocks mentioned earlier .
2. FSM_ODR , FSM frequency (Output Data Rate) . This value limits the maximum frequency of acceleration / angular velocity data transmitted to the code block. It is recommended to set the output frequency of acceleration / angular velocity higher than this value, that is, the Accelerator output data rate and Gyrocope Output data rate values in Options of the Unico main interface should be higher than the FSM ODR value to avoid undersampling problems.
3. Long_Counter , 16 -bit counter , a global counter that can count up to 65535, that is, it is common to all state machine blocks. Max Value is used to set the maximum overflow value of the counter, 16 -bit data format flag (for example, fill in FFFF for 65525 ) , and the two check boxes below can set whether to generate INT1/INT2 external interrupts when the counter overflows. The value of the counter can be increased from the program using " INCR ".
4. Converter , format conversion . Since half-precision floating point numbers HFP are used in FSM , we are provided with a small tool for converting 32 -bit floating point numbers to 16 -bit floating point numbers and 16- bit to 32- bit numbers.
5. SM x status, state machine x status setting . This area has three options. Enabled is used to start state machine x . Only when Enabled is checked , the state machine program block will work. INT1 INT2 routes the interrupt of the state machine to INT1 and INT2 external interrupts respectively . The 16 state machines can be independently set to start or not and bind external interrupts.
6. SM x Fixed Data Section, State Machine x Fixed Data Section , displays 6 variables and 2 switches:
- ConfigA and configB store the amount of resources used by the program .
- Size shows the total number of bytes of the state machine. In the figure, since no resources are configured, the 6 bytes displayed are the fixed variable area size.
- Setting saves the current program state, selected mask, selected threshold, input signal, etc.
- Reset Pointer (RP) is the reset point that stores the address to which the conditional instruction jumps when the return judgment (RESET) is true.
- Program Pointer (PP) is the current program point, which stores the address of the instruction being executed during the current sampling time.
- Hysteresis , hysteresis variable switch. After starting this option, the Hysteresis variable below can be set .
- D ecimation , frequency reduction variable switch. After starting this option, the dest frequency reduction variable below can be set.
The above fixed variables are automatically changed with programming operations when using UnicoGUI, and there is no need to change them by yourself.
When we want to use LSM6DSOX directly in our own project, we need to consider setting the values.
7. SM x Variable Data Section, state machine x variable data area , which displays 24 variables, totaling 36 bytes. When we do not use certain variables, Unico will not configure the variable into the state machine program block, and it will not occupy memory.
The variables in black font are the variables that can be set.
- T hresh1-3 , threshold , in conditional instructions, is used to compare whether the data of the axis corresponding to the input signal reaches the threshold.
- Hysteresis parameter. When the hysteresis parameter is set, when comparing the threshold of an axis, the comparison value will be increased by the hysteresis parameter to become a comparison interval, as shown in the figure below.
- M asksA-C , axis selection mask , is used to specify which axis of the input data is to be used for threshold condition or zero-crossing condition judgment.
- Timer1-3 , timer value , in the conditional instruction, the time value set for the timer comparison.
- D est is a frequency reduction factor, which is used to reduce the frequency of the state machine processing sensor data, and reduces the frequency of the state machine processing data to FSM ODR/Dest .
- Decision Tree, machine learning decision tree interface, checks the decision tree results inside the machine learning core through the " CHKDT " command. This parameter is needed when FSM and machine learning are combined.
Variables in grey font are variables that cannot be set directly
- Temporary MaskA-C , temporary mask , used to saveMasksA-C.
- DX, DY, DZ, DV , three-axis angle, angle and vector modulus , display the angle value obtained by integrating the current sensor angular velocity.
- DeltaT is the integral parameter of angular velocity . The angular velocity will be multiplied by this value and then integrated to obtain the angle value .
- PAS, Previous axis sign , stores the axis number of the previous sample, used under zero crossing conditions .
- DESC , internal counter , used during frequency reduction, managed automatically by the device.
- TC , Timer Counter , internal temporary timing counter , used to detect whether the timer has expired.
8. SM x Instructions Section, program instruction area. In the above picture , this area has only four buttons, namely
- Add State adds state instructions
- Import State Machine command
- Export State Machine command
- Reset State Machine reset state machine instruction
When you click the Add State button, you can add a state instruction, as shown in the following figure
The contents of the red boxes in the picture are from left to right:
- S0 state number , as the state instruction increases, the state number increases successively
- The state address of 0x06 also increases with the increase of state instructions. The data in the Reset Pointer (RP) and the Program Pointer (PP) currently running program point refers to this address. The first state address depends on the total length of the previous fixed variables and variable variables. In the figure, since there are only 6 fixed lengths, the state S0 address is 0x06 .
- RNC , Reset /Next conditions , select this status as a conditional instruction
- CMD , Commands, select the status as command instruction
- Instruction selection box , select the required instruction
- Hexadecimal instruction code, the hexadecimal form of the selected instruction
- Add , add a state button, add a state before this state
- Remove , delete status button, delete this status.
In the Interrupt interface of the FSM module , it is divided into two areas, as shown in the figure.
The left side shows the waveforms of input acceleration, angular velocity, and output external interrupt INT1/INT2.
On the right is the data of the output register OUT_Sx of the 16 state machines. By clicking read, you can read the current value.
The Development interface of the FSM module is also divided into two areas, as shown in the following figure .
The left side is the state machine diagram we wrote. By analyzing it, we can clearly see how the state of our state machine changes.
The right side is the debugging area. By importing the collected input data set, the state machine on the left can be simulated and debugged. I will not go into details here.
The above is the basic understanding of each module and parameter of the FSM programming module in LSM6DSOX . After having a preliminary understanding of these, we can start to look at the sample state machine program and analyze its workflow and writing process .
The next chapter will analyze and explain the FSM programming process of LSM6DSOX based on the example program .
|