基于3轴加速度计ADXL345的全功能计步器设计

合集下载

基于单片机的计步器设计

基于单片机的计步器设计

基于单片机的计步器设计随着人们生活水平的提高和科技的不断进步,智能硬件设备已经成为我们日常生活的一部分。

其中,计步器作为一种监测身体运动的工具,越来越受到人们的喜爱。

而基于单片机计步器的设计,不仅具有较高的精度和稳定性,还能够有效地降低成本。

本文将详细介绍基于单片机计步器的设计思路和实现方法。

计步器作为一种运动监测工具,可以帮助人们有效地监测自己的运动量,进而控制饮食和调整运动计划。

传统的计步器多为机械式或电子式,但其成本较高、体积较大,不利于随身携带。

因此,设计一种低成本、便携式的计步器成为了一项重要需求。

基于单片机的计步器应运而生,成为了满足这一需求的有效解决方案。

基于单片机计步器的核心部件为单片机、加速度传感器和显示屏。

其中,单片机作为控制中心,负责处理加速度传感器采集的数据并控制显示屏的显示;加速度传感器用于监测步行时的加速度变化;显示屏则用于显示步数、距离、时间等数据。

电路连接方面,单片机与加速度传感器、显示屏等部件通过线路连接。

其中,加速度传感器通过AD转换将模拟信号转化为数字信号,再传输给单片机;单片机将处理后的数据传输给显示屏进行显示。

软件设计方面,我们采用C语言编写程序。

程序主要包括数据采集、数据处理和数据显示三部分。

数据采集部分负责读取加速度传感器的数据;数据处理部分将这些数据进行分析和处理,计算出步数、距离、时间等参数;而数据显示部分则负责将处理后的数据显示在显示屏上。

在实现单片机计步器的过程中,首先需要进行实验验证,以确定设计的可行性和稳定性。

实验中,我们需要采集不同步行速度和距离下的加速度数据,并对这些数据进行处理和分析,以得出准确的步数、距离和时间等参数。

实验验证不仅能够帮助我们检验设计的正确性,还能够为后续的实际应用提供参考。

数据采集和处理是单片机计步器的核心环节之一。

在实际应用中,我们需要通过加速度传感器采集步行时的加速度变化数据。

这些数据经过AD转换后,传输给单片机进行处理。

ADXL345简介

ADXL345简介

ADXL345概述ADXL345是一款小而薄的超低功耗3轴加速度计,分辨率高(13位),测量范围达±16g。

数字输出数据为16位二进制补码格式,可通过SPI(3线或4线)或I2C数字接口访问。

ADXL345非常适合移动设备应用。

它可以在倾斜检测应用中测量静态重力加速度,还可以测量运动或冲击导致的动态加速度。

其高分辨率(3.9mg/LSB),能够测量不到1.0°的倾斜角度变化。

该器件提供多种特殊检测功能。

活动和非活动检测功能通过比较任意轴上的加速度与用户设置的阈值来检测有无运动发生。

敲击检测功能可以检测任意方向的单振和双振动作。

自由落体检测功能可以检测器件是否正在掉落。

这些功能可以独立映射到两个中断输出引脚中的一个。

正在申请专利的集成式存储器管理系统采用一个32级先进先出(FIFO)缓冲器,可用于存储数据,从而将主机处理器负荷降至最低,并降低整体系统功耗。

低功耗模式支持基于运动的智能电源管理,从而以极低的功耗进行阈值感测和运动加速度测量。

ADXL345采用3 mm × 5 mm × 1 mm,14引脚小型超薄塑料封装。

ADXL345特性超低功耗:VS= 2.5 V时(典型值),测量模式下低至23uA,待机模式下为0.1μA 功耗随带宽自动按比例变化用户可选的分辨率10位固定分辨率全分辨率,分辨率随g范围提高而提高,±16g时高达13位(在所有g范围内保持4 mg/LSB的比例系数)正在申请专利的嵌入式存储器管理系统采用FIFO技术,可将主机处理器负荷降至最低。

单振/双振检测,活动/非活动监控,自由落体检测电源电压范围:2.0 V至3.6 VI / O电压范围:1.7 V至VSSPI(3线和4线)和I2C数字接口灵活的中断模式,可映射到任一中断引脚通过串行命令可选测量范围通过串行命令可选带宽宽温度范围(-40°C至+85℃)抗冲击能力:10,000 g无铅/符合RoHS标准小而薄:3 mm× 5 mm× 1 mm,LGA封装。

ADXL345 三轴加速度计快速入门指南说明书

ADXL345 三轴加速度计快速入门指南说明书

Skill Level: Beginner ADXL345 Quickstart Guideby zagGrad | January 10, 2011 | Description:The ADXL345 is a small, thin, low power, 3-axis accelerometer with high resolution (13-bit) measurement at up to ±16 g. Digital output data is formatted as 16-bit twos complement and is accessible through either a SPI (3- or 4-wire) or I2C digital interface. The ADXL345 is well suited to measure the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion or shock. Its high resolution (4 mg/LSB) enables measurement of inclination changes less than 1.0°. Several special sensing functions are provided. Activity and inactivity sensing detect the presence or lack of motion and if the acceleration on any axis exceeds a user-set level. Tap sensing detects single and double taps. Free-fall sensing detects if the device is falling. These functions can be mapped to one of two interrupt output pins. An integrated, patent pending 32-level first in, first out (FIFO) buffer can be used to store data to minimize host processor intervention. Low power modes enable intelligent motion-based power management with threshold sensing and active acceleration measurement at extremely low power dissipation.Features:•2.0-3.6VDC Supply Voltage •UltraLowPower:40uAinmeasurementmode,*******************•Tap/Double Tap Detection •Free-Fall Detection • SPI and I2C interfacesDownloads:•ADXL345 Basic Arduino Code•ADXL345 Advanced Arduino Code•ADXL345 Advanced Processing CodeHooking it Up:This section of the guide illustrates how to connect an Arduino to the ADXL345 breakout board. The following is a table describing which pins on the Arduino should be connected to the pins on the accelerometer:Arduino Pin ADXL345 Pin10CS11SDA12SDO13SCL3V3VCCGnd GNDHere is a diagram in case you like pictures!Beginner Sample Code:Let's look at a sketch to get the ADXL345 up and running with an Arduino. You can download the sketch in its entirety here. Below we'll examine what the different sections of this code does.This is the initialization section of the sketch. It's pretty basic really. Here's what's happening.1.The SPI.h library is added to the sketch. SPI is a communication protocol usedby Arduino to communicate to the ADLX345.2. A variable named CS is created to store the pin number of the Chip Selectsignal.3.Variables are created for several of the ADXL345 registers. These variablesstore the address of the indicated registers and are used to set and retrievevalues from the accelerometer. The datasheet shows all of the registersavailable on the ADXL345 and their addresses.4.Variables are created that will hold information that has been retrieved from theaccelerometer.The main section of the sketch is split into two parts: the setup and the loop. The setup section is used to configure different aspects of the Arduino to communicate with the ADXL345. At the end of the setup section two functions are used to put the accelerometer into the mode we want to use (+/-4g detection, and enable measurement mode). The functions will be discussed in the next section of the sketch.The loop does most of the work in the sketch. Here's what's going on in the loop:1.Arduino reads 6 register values from the ADXL345 using the readRegisterfunction. This command reads the x, y and z acceleration values from theaccelerometer and stores them in the buffer named "values" that was created in the initialization section of the sketch.2.When values are read from the accelerometer they are returned in bytes. Abyte is only 8 bits, but the accelerometer reports acceleration with up to 10 bits!In order to see the correct acceleration value we have to concatenate two bytes together. The x, y and z acceleration values are determined by concatenating the bytes from the values buffer.3.The acceleration values are printed to the serial terminal4.The sketch waits for 10ms before executing the loop again. This will allow theloop to run at roughly 100 hz.The readRegister command is used to read values from the ADXL345. When using the readRegister function three variables must be given to the function: the registerAddress where reading should start from, the number of registers that should be read in sequence, and the buffer where the values should be stored. When reading a register from the ADXL345 the address must be modified so that the 8th bit is set high. If more than 1 register is to be read the 7th bit must also be set high. The function accomplishes this task in the first two lines. After that the function is very similar to the writeRegister function. The CS pin is set low to start an SPI sequence, then the address is transferred. After that a loop is used to read the specified number of registers from the accelerometer and the values are stored in the specified buffer. Finally the CS pin is set high to end the SPI sequence and the function is complete.Once you've hooked the ADXL345 up to an Arduino as specified in the Hook Up section of the guide, download the sketch. After opening the sketch in the Arduino IDE just load it to your board and open the terminal from Arduino. You'll see the X,Y and Z acceleration values start scrolling in the terminal window.Advanced Sample Code:Once you understand how to read and write from registers to the ADXL345 there are some really cool functions that you might want to experiment with. In this section we'll look at a sketch that can detect single and double taps, and will convert the x,y and z acceleration values to Gs (a unit of measurement corresponding to 1g). This project will use both an Arduino sketch to interface with the ADXL345 and a Processing sketch so that we can interpret the data. You can download the Arduino sketch hereand the Processing sketch here.In order for the sketch to work properly you'll need to add a wire from the INT1 pin on the ADXL345 to pin D2 on the Arduino.Let's look at some of the special parts of this sketch.//Create an interrupt that will trigger when a tap is detected.attachInterrupt(0, tap, RISING);//Put the ADXL345 into +/­4G range by writing the value 0x01to the DATA_FORMAT register.writeRegister(DATA_FORMAT, 0x01);//Send the Tap and Double Tap Interrupts to INT1 pinwriteRegister(INT_MAP, 0x9F);//Look for taps on the Z axis only.writeRegister(TAP_AXES, 0x01);//Set the Tap Threshold to 3gwriteRegister(THRESH_TAP, 0x38);//Set the Tap Duration that must be reachedit R i t (DURATION 010)This code has been added to the setup() section of the sketch. It's a bit different from the setup() section of the ADXL345_Basic example because we're setting the ADXL345 up to detect a single and double tap event. When the accelerometerdetects a tap or a double tap we want the INT1 pin to go high, then when the event is handled the INT1 pin will go back low.When the INT1 pin goes high on the ADXL345 we want to the Arduino to generate an interrupt. In order to do this we use the attachInterrupt() function; we tell the function that we want an interrupt to occur on the Arduino Interrupt 0 (pin D2) when the pin goes from low to high, and we want the Arduino to execute the tap function when this occurs. We'll look at the tap() function later on.After the interrupt is created we need to configure the ADXL345 to recognize single and double tap events. In order to make this configuration we must change the values in the following registers: INT_MAP, TAP_AXES, THRESH_TAP, DURATION, LATENT and WINDOW. You can read the 'TAP DETECTION' section of thedatasheet to see why these values were assigned to their registers. Basically, though, the ADXL345 has been configured so that if a single or double tap is detected the INT1 pin will go from low to high; once the interrupt is handled the INT1 pin will go back low.In the final project we'll want two types of outputs. If a single tap is detected the Arduino will output the raw accelerometer values for x,y and z; just like in theADXL345_Basic example. However if the ADXL345 detects a double tap we want the Arduino to output the actual G values of the x,y and z axis. In order to find the G values from the raw accelerometer data we must scale the original values. To find the scale we need to know two things: the number of bits used to represent the original values and the range of acceleration values that can be represented. The ADXL345 is set up to measure the values with 10 bits. We've set the range to +/- 4 g, or an 8g range. The scale is found by dividing the total range by the number that can be represented in 10 bits.Once we know the scale all we have to do is multiply the raw accelerometer data by the scale to find the number of gs. The variables xg, yg and zg are float variables so that they can hold decimal numbers.When the tap() interrupt function runs (we'll cover this next) it assigns a value to the tagType variable. The variable is assigned '1' if a single tap was detected and '2' if a double tap was detected. If a single tap was detected the Arduino will write the word "SINGLE" to the terminal followed by the x,y and z accelerometer values. If a double tap was detected Arduino will write the word "DOUBLE" to the terminal followed by the g values for the x,y and z axis. After printing the values to the terminal we disable the interrupt for a little while; this prevents the Arduino from detecting any 'echoed' interrupts that may occur while the ADXL345 is still vibrating from the tap event.void tap(void){//Clear the interrupts on the ADXL345readRegister(INT_SOURCE, 1, values);if(values[0] & (1<<5))tapType=2;else tapType=1;;}Because of the way the attachInterrupt() function was called the tap() function will beused whenever Arduino sees an interrupt occur on pin D2. This function is fairlystraightforward: Arduino reads the INT_SOURCE register on the ADXL345 and storesthe value in the 'values' buffer. The INT_SOURCE register tells us if the interruptcame from a single tap or a double tap event. Depending on which kind of tap set ofthe interrupt we assign the tapType variable with a 1 or a 2.Download the Arduino sketch and the Processing sketch. After you've connected theADXL345 to the Arduino as specified in the Hooking It Up section, and added a wirefrom the INT1 pin on the ADXL345 to pin D2 on the Arduino, open Arduino anddownload the sketch to your board. Then open processing and run theADXL345_Advanced processing sketch. You may have to change the serial port inthe sketch to reflect which port your Arduino is plugged into. If everything has beendone correctly the Processing window will output the words "Single Tap" to the screenalong with the raw accelerometer values when you tap the ADXL345; likewise"Double Tap" and the G values will be displayed when you double tap the ADXL345.https:///tutorials/2402/12/2015。

三轴加速度计ADXL345数据手册

三轴加速度计ADXL345数据手册

ADXL345数据手册基本描述:ADXL345是一款小而薄的低功耗3轴加速度计,分辨率高(13位),测量范围达±16g。

数字输出数据为16位二进制补码格式,可通过SPI(3线或4线)或I2C数字接口访问。

ADXL345非常适合移动设备应用。

它可以在倾斜检测应用中测量静态重力加速度,还可以测量运动或冲击导致的动态加速度。

其高分辨率(4 mg/LSB),能够测量不到1.0°的倾斜角度变化。

该器件提供多种特殊检测功能。

活动和非活动检测功能检测有无运动发生,以及任意轴上的加速度是否超过用户设置的限值。

敲击检测功能可以检测单击和双击动作。

自由落体检测功能可以检测器件是否正在掉落。

这些功能可以映射到两个中断输出引脚中的一个。

正在申请专利的32级先进先出(FIFO)缓冲器可用于存储数据,最大程度地减少主机处理器的干预。

低功耗模式支持基于运动的智能电源管理,从而以极低的功耗进行阈值感测和运动加速度测量。

ADXL345采用3 mm × 5 mm × 1 mm、14引脚小型超薄塑料封装。

功能特性:超低功耗:VS = 2.5 V时(典型值),测量模式下低至40 μA,待机模式下为0.1 μA功耗随带宽自动按比例变化用户可选的分辨率10位固定分辨率全分辨率,分辨率随g范围提高而提高,±16 g时达到最高分辨率13位(在所有g范围内保持4 mg/LSB的比例系数)正在申请专利的嵌入式FIFO技术可最大程度地减少主机处理器的负荷单击/双击检测活动/非活动监控应用程序:手机医疗仪器游戏,指的设备工业仪表个人导航设备硬盘驱动器(硬盘)保护芯扬国际(香港)有限公司。

ADXL345中文PDF

ADXL345中文PDF

32 LEVEL FIFO
SDA/SDI/SDIO SERIAL I/O SDO/ALT ADDRESS
07925-001
SCL/SCLK GNDຫໍສະໝຸດ CS图1.Rev. A
Information furnished by Analog Devices is believed to be accurate and reliable. However, no responsibility is assumed by Analog Devices for its use, nor for any infringements of patents or other rights of third parties that may result from its use. Speci cations subject to change without notice. No license is granted by implication or otherwise under any patent or patent rights of Analog Devices. Trademarks and registered trademarks are the property of their respective owners. See the last page for disclaimers.
3轴,± 2g/ ± 4g/ ± 8g/ ± 16g 数字加速度计 ADXL345
超低功耗:VS = 2.5 V时(典型值),测量模式下低至23ìA, 待机模式下为0.1μA 功耗随带宽自动按比例变化 用户可选的分辨率 10位固定分辨率 全分辨率,分辨率随g范围提高而提高,±16g时高达13位 (在所有g范围内保持4 mg/LSB的比例系数) 正在申请专利的嵌入式存储器管理系统采用FIFO技术,可将 主机处理器负荷降至最低 单振/双振检测 活动/非活动监控 自由落体检测 电源电压范围:2.0 V至3.6 V I / O电压范围:1.7 V至VS SPI(3线和4线)和I2C数字接口 灵活的中断模式,可映射到任一中断引脚 通过串行命令可选测量范围 通过串行命令可选带宽 宽温度范围(-40°C至+85℃) 抗冲击能力:10,000 g 无铅/符合RoHS标准 小而薄:3 mm× 5 mm× 1 mm,LGA封装 应用 手机 医疗仪器 游戏和定点设备 工业仪器仪表 个人导航设备 硬盘驱动器(HDD)保护

adxl345实用电路中文版

adxl345实用电路中文版

Rev.0“Circuits from the Lab” from Analog Devices have been designed and built by Analog Devices engineers. Standard engineering practices have been employed in the design and construction of each circuit, and their function and performance have been tested and verified in a lab environment at room temperature. However, you are solely responsible for testing the circuit and determining its suitability and applicability for your use and application. Accordingly, in no event shall Analog Devices be liable for direct, indirect, special, incidental, consequential or One Technology Way, P.O. Box 9106, Norwood, MA 02062-9106, U.S.A. Tel: 781.329.4700 电路笔记CN-0133连接/参考器件 利用ADI 公司产品进行电路设计3轴、±2 g /±4 g /±8 g /±16 g 数字加速度计ADXL345放心运用这些配套产品迅速完成设计。

欲获得更多信息和技术支持,请拨打4006-100-006或访问精密模拟微控制器,12位模拟I/O ,ARM7TDMI /zh/circuits 。

ADXL345中文资料

ADXL345中文资料
3轴,± 2g/ ± 4g/ ± 8g/ ± 16g 数字加速度计
ADXL345
特性
超低功耗:VS = 2.5 V时(典型值),测量模式下低至23ìA, 待机模式下为0.1μA
功耗随带宽自动按比例变化 用户可选的分辨率
10位固定分辨率 全分辨率,分辨率随g范围提高而提高,±16g时高达13位 (在所有g范围内保持4 mg/LSB的比例系数) 正在申请专利的嵌入式存储器管理系统采用FIFO技术,可将 主机处理器负荷降至最低 单振/双振检测 活动/非活动监控 自由落体检测 电源电压范围:2.0 V至3.6 V I / O电压范围:1.7 V至VS SPI(3线和4线)和I2C数字接口 灵活的中断模式,可映射到任一中断引脚 通过串行命令可选测量范围 通过串行命令可选带宽 宽温度范围(-40°C至+85℃) 抗冲击能力:10,000 g 无铅/符合RoHS标准 小而薄:3 mm× 5 mm× 1 mm,LGA封装 应用 手机 医疗仪器 游戏和定点设备 工业仪器仪表 个人导航设备 硬盘驱动器(HDD)保护
概述
ADXL345是一款小而薄的超低功耗3轴加速度计,分辨率 高(13位),测量范围达± 16g。数字输出数据为16位二进制 补码格式,可通过SPI(3线或4线)或I2C数字接口访问。 ADXL345非常适合移动设备应用。它可以在倾斜检测应用 中测量静态重力加速度,还可以测量运动或冲击导致的动 态加速度。其高分辨率(3.9mg/LSB),能够测量不到1.0°的 倾斜角度变化。 该器件提供多种特殊检测功能。活动和非活动检测功能通 过比较任意轴上的加速度与用户设置的阈值来检测有无运 动发生。敲击检测功能可以检测任意方向的单振和双振动 作。自由落体检测功能可以检测器件是否正在掉落。这些 功能可以独立映射到两个中断输出引脚中的一个。正在申 请专利的集成式存储器管理系统采用一个32级先进先出 (FIFO)缓冲器,可用于存储数据,从而将主机处理器负荷 降至最低,并降低整体系统功耗。 低功耗模式支持基于运动的智能电源管理,从而以极低的 功耗进行阈值感测和运动加速度测量。 ADXL345采用3 mm × 5 mm × 1 mm,14引脚小型超薄塑料 封装。

adxl345技术参数

adxl345技术参数

adxl345技术参数ADXL345技术参数ADXL345是一种小型、低功耗的加速度传感器,广泛应用于移动设备、工业自动化和运动控制等领域。

本文将介绍ADXL345的技术参数,包括传感器的工作范围、分辨率、灵敏度、数据输出等方面。

1. 工作范围ADXL345的工作范围指的是传感器能够测量的加速度范围。

该传感器的工作范围为±2g、±4g、±8g和±16g。

其中,g代表重力加速度,约为9.8m/s²。

用户可以根据具体应用需求选择合适的工作范围。

2. 分辨率ADXL345的分辨率指的是传感器可以测量的最小加速度变化值。

该传感器的分辨率为4mg/LSB,即每个最低有效位(LSB)代表4mg的加速度变化。

分辨率越高,传感器能够捕捉到更小的加速度变化。

3. 灵敏度ADXL345的灵敏度指的是传感器对加速度变化的敏感程度。

传感器的灵敏度与工作范围和分辨率相关。

在±2g工作范围下,灵敏度为1LSB=3.9mg;在±4g工作范围下,灵敏度为1LSB=7.8mg;在±8g工作范围下,灵敏度为1LSB=15.6mg;在±16g工作范围下,灵敏度为1LSB=31.2mg。

用户可以根据具体应用需求选择合适的工作范围和灵敏度。

4. 数据输出ADXL345通过数字接口(如I2C或SPI)输出加速度数据。

传感器可以以全分辨率模式输出数据,也可以以10位或8位分辨率模式输出数据。

在全分辨率模式下,传感器的输出数据为13位,可以表示±16g工作范围内的加速度变化。

用户可以根据处理器的要求选择合适的输出分辨率。

5. 数据格式ADXL345以16位二进制补码表示加速度数据。

对于3轴加速度数据,每个轴的数据占据16位,其中高8位和低8位分别表示数据的整数部分和小数部分。

用户可以通过简单的移位和组合操作将这些数据转换为实际的加速度值。

6. 内部采样率ADXL345具有可调节的内部采样率,可以根据应用需求选择合适的采样率。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

基于3轴加速度计ADXL345的全功能计步器设计 时间:2010-11-01 21:57:19 来源: 作者: 简介 计步器是一种颇受欢迎的日常锻炼进度监控器,可以激励人们挑战自己,增强体质,帮助瘦身。早期设计利用加重的机械开关检测步伐,并带有一个简单的计数器。晃动这些装置时,可以听到有一个金属球来回滑动,或者一个摆锤左右摆动敲击挡块。 如今,先进的计步器利用MEMS(微机电系统)惯性传感器和复杂的软件来精确检测真实的步伐。MEMS惯性传感器可以更准确地检测步伐,误检率更低。MEMS惯性传感器具有低成本、小尺寸和低功耗的特点,因此越来越多的便携式消费电子设备开始集成计步器功能,如音乐播放器和手机等。ADI公司的3轴加速度计ADXL335, ADXL345和 ADXL346小巧纤薄,功耗极低,非常适合这种应用。

本文以对步伐特征的研究为基础,描述一个采用3轴 图1. 各轴的定义 让我们考虑步行的特性。图2描绘了一个步伐,我们将其定义为单位步行周期,图中显示了步行周期各阶段与竖向和前向加速度变化之间的关系。

图2. 步行阶段与加速度模式 图3显示了与一名跑步者的竖向、前向和侧向加速度相对应的x、y和z轴测量结果的典型图样。无论如何穿戴计步器,总有至少一个轴具有相对较大的周期性加速度变化,因此峰值检测和针对所有三个轴上的加速度的动态阈值决策算法对于检测单位步行或跑步周期至关重要。 图3. 从一名跑步者测得的x、y和z轴加速度的典型图样

算法 步伐参数 数字滤波器:首先,为使图3所示的信号波形变得平滑,需要一个数字滤波器。可以使用四个寄存器和一个求和单元,如图4所示。当然,可以使用更多寄存器以使加速度数据更加平滑,但响应时间会变慢。

图4. 数字滤波器 图5显示了来自一名步行者所戴计步器的最活跃轴的滤波数据。对于跑步者,峰峰值会更高。 图5. 最活跃轴的滤波数据 动态阈值和动态精度:系统持续更新3轴加速度的最大值和最小值,每采样50次更新一次。平均值(Max + Min)/2称为“动态阈值”。接下来的50次采样利用此阈值判断个体是否迈出步伐。由于此阈值每50次采样更新一次,因此它是动态的。这种选择具有自适应性,并且足够快。除动态阈值外,还利用动态精度来执行进一步滤波,如图6所示。

图6. 动态阈值和动态精度 利用一个线性移位寄存器和动态阈值判断个体是否有效地迈出一步。该线性移位寄存器含有2个寄存器:sample_new寄存器和sample_old寄存器。这些寄存器中的数据分别称为sample_new和sample_old。当新采样数据到来时,sample_new无条件移入sample_old寄存器。然而,sample_result是否移入sample_new寄存器取决于下述条件:如果加速度变化大于预定义精度,则最新的采样结果sample_result移入sample_new寄存器,否则sample_new寄存器保持不变。因此,移位寄存器组可以消除高频噪声,从而保证结果更加精确。 步伐迈出的条件定义为:当加速度曲线跨过动态阈值下方时,加速度曲线的斜率为负值(sample_new < sample_old)。 . 峰值检测:步伐计数器根据x、y、z三轴中加速度变化最大的一个轴计算步数。如果加速度变化太小,步伐计数器将忽略。 步伐计数器利用此算法可以很好地工作,但有时显得太敏感。当计步器因为步行或跑步之外的原因而非常迅速或非常缓慢地振动时,步伐计数器也会认为它是步伐。为了找到真正的有节奏的步伐,必须排除这种无效振动。利用“时间窗口”和“计数规则”可以解决这个问题。 “时间窗口”用于排除无效振动。假设人们最快的跑步速度为每秒5步,最慢的步行速度为每2秒1步。这样,两个有效步伐的时间间隔在时间窗口[0.2 s - 2.0 s]之内,时间间隔超出该时间窗口的所有步伐都应被排除。 ADXL345的用户可选输出数据速率特性有助于实现时间窗口。表1列出了TA = 25°C, VS = 2.5 V, and VDD I/O = 1.8 V时的可配置数据速率(以及功耗)。 表1. 数据速率和功耗 输出数据 速率 (Hz) 带宽 (Hz) 速率 代码 IDD (µA)

3200 1600 1111 146 1600 800 1110 100 800 400 1101 145 400 200 1100 145 200 100 1011 145 100 50 1010 145 50 25 1001 100 25 12.5 1000 65 12.5 6.25 0111 55 6.25 3.125 0110 40

此算法使用50 Hz数据速率(20 ms)。采用interval的寄存器记录两步之间的数据更新次数。如果间隔值在10与100之间,则说明两步之间的时间在有效窗口之内;否则,时间间隔在时间窗口之外,步伐无效。 “计数规则” 用于确定步伐是否是一个节奏模式的一部分。步伐计数器有两个工作状态:搜索规则和确认规则。步伐计数器以搜索规则模式开始工作。假设经过四个连续有效步伐之后,发现存在某种规则(in regulation),那么步伐计数器就会刷新和显示结果,并进入“确认规则”工作模式。在这种模式下工作时,每经过一个有效步伐,步伐计数器就会更新一次。但是,如果发现哪怕一个无效步伐,步伐计数器就会返回搜索规则模式,重新搜索四个连续有效步伐。 图7显示了步伐参数的算法流程图。 图7. 步伐参数算法流程图 距离参数 根据上述算法计算步伐参数之后,我们可以使用公式1获得距离参数。 距离 = 步数 × 每步距离 (1) 每步距离取决于用户的速度和身高。如果用户身材较高或以较快速度跑步,步长就会较长。参考设计每2秒更新一次距离、速度和卡路里参数。因此,我们使用每2秒计数到的步数判断当前跨步长度。表2显示了用于判断当前跨步长度的实验数据。 表2. 跨步长度与速度(每2秒步数)和身高的关系 每2秒步数 跨步(m/s) 0~2 身高/5 2~3 身高/4 3~4 身高/3 4~5 身高/2 5~6 身高/1.2 6~8 身高 >=8 1.2 ×身高

2秒的时间间隔可以利用采样数精确算出。以50 Hz数据速率为例,处理器可以每100次采样发送一次相应的指令。处理器利用一个名为m_nLastPedometer的变量记录每个2秒间隔开始时的步数,并利用一个名为m_nPedometerValue的变量记录每个2秒间隔结束时的步数。这样,每2秒步数等于m_nPedometerValue与m_nLastPedometer之差。 虽然数据速率为50 Hz,但ADXL345的片内FIFO使得处理器无需每20 ms读取一次数据,极大地减轻了主处理器的负担。该缓冲器支持四种工作模式:旁路、FIFO、流和触发。在FIFO模式下,x、y、z轴的测量数据存储在FIFO中。当FIFO中的采样数与FIFO_CTL寄存器采样数位规定的数量相等时,水印中断置1。如前所述,人们的跑步速度最快可达每秒5步,因此每0.2秒刷新一次结果即可保证实时显示,从而处理器只需每0.2秒通过水印中断唤醒一次并从ADXL345读取数据。FIFO的其它功能也都非常有用。利用触发模式,FIFO可以告诉我们中断之前发生了什么。由于所述解决方案没有使用FIFO的其它功能,因此笔者将不展开讨论。 本文来自电子发烧友网

(http://www.elecfans.com) 速度参数 速度 = 距离/时间,而每2秒步数和跨步长度均可根据上述算法计算,因此可以使用公式2获得速度参数。

速度 = 每2秒步数 × 跨步/2 s (2) 卡路里参数 我们无法精确计算卡路里的消耗速率。决定其消耗速率的一些因素包括体重、健身强度、运动水平和新陈代谢。不过,我们可以使用常规近似法进行估计。表3显示了卡路里消耗与跑步速度的典型关系。 表3. 卡路里消耗与跑步速度的关系

跑步速度 (km/h) 卡路里消耗(C/kg/h) 8 10 12 15 16 20 20 25

由表3可以得到公式(3)。 卡路里(C/kg/h) = 1.25 × 跑步速度(km/h) (3) 以上所用的速度参数单位为m/s,将km/h转换为m/s可得公式4。 卡路里(C/kg/h) = 1.25 × 速度(m/s) × 3600/1000 (4) 卡路里参数随同距离和速度参数每2秒更新一次。为了考虑运动者的体重,我们可以将公式4转换为公式5。体重(kg)为用户输入量,一个小时等于1800个2秒间隔。 卡路里(C/2 s) = 4.5 × 速度 × 体重/1800 (5) 如果用户在步行或跑步之后休息,则步数和距离将不变化,速度应为0,此时的卡路里消耗可以利用公式6计算(休息时的卡路里消耗约为1 C/kg/h)。 卡路里(C/2 s) = 1 × 体重/1800 (6) 最后,我们可以将所有2秒间隔的卡路里相加,获得总卡路里消耗量。 硬件连接 ADXL345易于连接到任何使用I2C®或SPI数字通信协议的处理器。图8给出了演示设备的原理示意图,它采用3V电池供电。ADXL345的/CS引脚连接到板上的VS,以选择I2C模式。利用一个低成本精密模拟微控制器ADuC7024从ADXL345读取数据,执行算法,并通过UART将结果发送至PC。SDA和SCL分别为I2C总线的数据和时钟引脚,从ADXL345连接到ADuC7024的对应引脚。ADXL345的两个中断引脚连接到ADuC7024的IRQ输入,以产生各种中断信号并唤醒处理器。

图8. 硬件系统的原理示意图 用户界面 用户界面显示测试数据,并对操作员的指令做出响应。用户界面(UI)运行之后,串行端口应打开,通信链路应启动,随后演示程序将持续运行。图9显示了用户佩戴计步器步行或跑步时的测试情况。用户可以输入其体重和身高数据,距离、速度和卡路里参数将根据这些数据进行计算。

相关文档
最新文档