6937 views|0 replies

124

Posts

1

Resources
The OP
 

[LSM6DSOX finite state machine routine learning three] -- vertical flip (Flip Down) [Copy link]

 

Last weekend, the two posts Introduction to Finite State Machines and Examples and Finite State Machine Programming and Usage have introduced the characteristics and basic usage of the LSM6DSOX finite state machine in detail. Starting this week, I will explain and share the FSM examples provided by ST , from understanding the examples to reproducing them, and further master the usage of the LSM6DSOX finite state machine.

You can first download the ST

链接已隐藏,如需查看请登录或者注册
from github . For convenience, I have packaged the LSM6DSOX routine and uploaded it to Baidu Cloud. The link and extraction code are as follows:

链接已隐藏,如需查看请登录或者注册

Extraction code: ufln

After downloading and decompressing, you can get the following seven folders:

Each file contains README.md , suffix .h , suffix .ucf files, where:

README.md briefly introduces the basic information of the example

The file with the suffix .h is a C code header file generated by Unico GUI based on the specific configuration parameters of FSM . It can be easily run independently in your own engineering program.

The file with the suffix .ucf is the standard configuration file of Unico GUI. Unico GUI can directly save the configuration information as a ucf file, or load and import it into the sensor.

This post mainly explains the implementation process of the flip recognition F lip-Down detection example.

The LSM6DSOX sensor is positioned in the IoT and low power consumption perspective, so it must be designed with the application perspective of various IoT devices in mind.

The flip recognition in the routine, as the name implies, is to identify whether the device is flipped to a certain angle. This application can be very simple on smart watches and mobile phones. For example, some mobile phones can be set to mute when the phone is flipped, and smart watches can display the time when the wrist is raised, etc.

So how is flip recognition achieved?

Anywhere on the earth, there is a gravitational acceleration pointing to the center of the earth, and the accelerometer in the sensor can sense this acceleration. The accelerometer has the ability to perceive in three directions, namely X\Y\Z. The vector sum of the gravitational acceleration in the directions of these three axes points to the center of the earth, so the direction of the sensor can be determined by the gravitational acceleration.

Now that we understand how to implement this function, let's take a look at the official Flip -Down detection example. Use the load function of Unico GUI to configure the ucf file to the sensor.

When Loaded is displayed on the left side of the load button, the parameters are loaded.

At this point, open the FSM control on the left and we can see the state machine code for flip recognition .

For an explanation of this programming interface, please refer to the previous article: Finite State Machine Programming Usage

Let's take a look at this routine, which has a total of 7 statements, combined with the instruction set description document at the end of the previous article,

Let’s analyze the meaning of each sentence one by one:

S0: RNC NOP GNTH2

A judgment statement, GNTH2: when the data of a certain axis is greater than Thresh2, it is established, NOP: otherwise it is reset.

You can see that Thresh2 = 0, Mask A = 08 in the variable area on the left, then according to the mask setting rules:

The positive direction of the Z axis is selected here, so the meaning of this statement is that when the positive acceleration value of the Z axis is greater than 0, it is established and can jump to S1, otherwise it returns to S0.

S1: RNC LNTH2 TI4

This is another judgment statement. The forward condition here is TI4: when the timer count is greater than the threshold set by Timer4, it is established. The reset condition is LNTH2: when the data of a certain axis is less than Thresh2. The time base of the timer counter here is counted according to the frequency set by FSM OCR. Timer = 0x0D, the total duration is 1/26*13 = 0.5s. So this statement means that if the acceleration value of the positive direction of the Z axis is greater than 0g for more than 0.5s, it will jump to S2, otherwise it will jump to S0.

S2: SRP

This is a command instruction, which means to set the reset pointer to the next address, that is, when the reset state of the judgment statement is encountered later, it will jump to S3 instead of S0.

S3: GNTH1 TI3

The forward condition of this judgment statement is TI3: that is, when the timer count is greater than the threshold set by Timer3, it is established. The reset condition is GNTH1: when the data of a certain axis is greater than Thresh1, it is reset. Thresh1 = -0.85, the acceleration value of the positive direction of the Z axis is greater than -0.85, that is, the positive acceleration of the Z axis is less than -0.85g for more than 1/26*10=0.38s, then jump to S4, otherwise jump to S3.

S4:CRP

This command resets the SRP function and sets the reset pointer back to S0.

S5:CONTREL

This instruction executes the loop to the reset point S0 and outputs the mask to the OUTSx register. At the same time, since INT1 is set in SM1 Status, the interrupt is routed to the external output interrupt pin. When the S5 instruction is executed, you can see that the external interrupt output INT1 generates a pulse.

S6:STOP

This instruction stops execution. Judging from the above code, it generally does not jump to this position.

In order to facilitate programming, ST also made a state machine diagram display interface. Open the Debug title bar, and you can see the following:

Then, combining the above instruction introduction and state machine diagram, it is not difficult to analyze its specific workflow:

1. First of all, the positive direction of the sensor is the positive direction of the Z axis. In general, it should be facing upward, so that S0 and S1 are established. This avoids the problem of interruption when the device is in a state where the panel is facing downward and then changes to the reverse direction and facing downward.

2. After eliminating the problem in 1 , the flip recognition effect can be achieved by simply judging whether the device has been in the forward direction for a certain period of time.

Here is a video of the test results:

Questions for consideration:

1. If the direction of the device sensor installation is not the positive direction of the Z axis towards the panel, but the positive direction of the X axis, how should we modify the configuration if we want to realize the action of identifying the flip device?

 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list