我正在研究ADXL375,并使用I2C协议将其与Arduino UNO接口。我获得数据手册中提到的X、Y、Z轴值,即水平放置时,x = 0g、y = 0g、z = 1g(近似校准)。我已使能触发模式,并将中断Map到INT2。冲击阈值设置为0x28 = 31.2g。
当我在桌面上点击模块时,即使阈值为31.2g,也会触发中断,但我得到的值不变(大约x = 0,y = 0,z = 1)。如何在冲击过程中获得X,Y,Z的值?当我倾斜模块时,我可以看到值发生相应变化。但这些值几乎不超过3g。我做错了什么?
下面是寄存器的代码设置:
/*START Set Shock Threshold*/
Wire.beginTransmission(Device_Address);
Wire.write(0x1D); //Shock Duration Register Address
Wire.write(0x28); //Scale Factor is 780mg/LSB, hence 0x28 = 31.2g
Wire.endTransmission();
/*END Set Shock Threshold*/
/*START Set DUR Thresh_SHOCK*/
//Used for Double Shock Detection Only**
Wire.beginTransmission(Device_Address);
Wire.write(0x21); //Shock Duration Register Address
Wire.write(0x50); //Scale Factor is 625us/LSB, hence 0x50 = 50ms
Wire.endTransmission();
/*END Set DUR Thresh_SHOCK*/
/*START Set Latency*/
Wire.beginTransmission(Device_Address);
Wire.write(0x22); //Latent Register Address
Wire.write(0x20); //Scale Factor is 1.25ms/LSB, hence 0x20 = 400ms
Wire.endTransmission();
/*END Set Latency*/
/*START Set Shock Window to 300ms*/
Wire.beginTransmission(Device_Address);
Wire.write(0x23); //Window Register Address
Wire.write(0xF0); //Scale Factor is 1.25ms/LSB, hence 0xF0 = 300ms
Wire.endTransmission();
/*END Set Shock Window to 300ms*/
/*START Enable XYZ-Axis Shock Detection START*/
Wire.beginTransmission(Device_Address);
Wire.write(0x2A); //SHOCK_AXES Register
Wire.write(0x07); //Enable SHOCK_X, SHOCK_Y, SHOCK_Z
Wire.endTransmission();
/*END Enable XYZ-Axis Shock Detection END*/
/*START Set Out-Data-Rate(ODR) to 3200Hz*/
Wire.beginTransmission(Device_Address);
Wire.write(0x2C); //BW_RATE Register Address
Wire.write(0x0F); //3200 Hz Output Data Rate
Wire.endTransmission();
/*END Set Out-Data-Rate(ODR) to 3200Hz */
/*START Enable Single Shock Interrupt*/
Wire.beginTransmission(Device_Address);
Wire.write(0x2E); //INT_Enable Register Address
Wire.write(0x40); //Enable single Shock Int
Wire.endTransmission();
/*END Enable Single Shock Interrupt*/
/*START Assign Single Shock Interrupt*/
Wire.beginTransmission(Device_Address);
Wire.write(0x2F); //INT_Map Register Address
Wire.write(0x40); //Assign single Shock Int
Wire.endTransmission();
/*END Assign Single Shock Interrupt*/
/*START Data Format*/
Wire.beginTransmission(Device_Address);
Wire.write(0x31); //DATA_FORMAT Reg
Wire.write(0x0B);
Wire.endTransmission();
/*END Data Format*/
/*START Enable Trigger Mode*/
Wire.beginTransmission(Device_Address);
Wire.write(0x38); //FIFO_CTL Register Address
Wire.write(0xEA); //Enable Trigger Mode, set samples = 10
Wire.endTransmission();
/*END Enable Trigger Mode*/
/*START Offset Calibration*/
// Scale Factor = 0.196g/MSB
Wire.beginTransmission(Device_Address);
Wire.write(0x1E); //OFSX Address
Wire.write(0xFA); //OFSX offset
Wire.endTransmission();
Wire.beginTransmission(Device_Address);
Wire.write(0x1F); //OFSY Address
Wire.write(0xFB); //OFSY offset
Wire.endTransmission();
Wire.beginTransmission(Device_Address);
Wire.write(0x20); //OFSZ Address
Wire.write(0xFF); //OFSZ offset
Wire.endTransmission();
/*END Offset Calibration*/
/*Start Enable Measuring*/
Wire.beginTransmission(Device_Address);
Wire.write(0x2D); //POWER_CTL Register
Wire.write(0x08); //Enable Measuring
Wire.endTransmission();
/*END Enable Measuring*/
/*Attach Interrupt to Digital pin 2*/
attachInterrupt(digitalPinToInterrupt(2), ISR_Func, RISING);
下面是我接收这些值的方式:
int16_t data_x = 0, data_x_lsb = 0;
int16_t data_y = 0, data_y_lsb = 0;
int16_t data_z = 0, data_z_lsb = 0;
Wire.beginTransmission(Device_Address);
Wire.write(0x32); //read LSB
Wire.endTransmission();
Wire.requestFrom(Device_Address, 6);
while (Wire.available()) {
data_x_lsb = Wire.read();
data_x = Wire.read();
data_y_lsb = Wire.read();
data_y = Wire.read();
data_z_lsb = Wire.read();
data_z = Wire.read();
data_x = (data_x << 8) | (data_x_lsb);
data_y = (data_y << 8) | (data_y_lsb);
data_z = (data_z << 8) | (data_z_lsb);
}
data_x = (double)data_x*49/1000
data_y = (double)data_y*49/1000
data_z = (double)data_z*49/1000
样本输出:
14:36:51.120 -> -0.072 -0.067 0.977
14:36:51.221 -> -0.087 -0.096 0.949
14:36:51.325 -> 0.010 -0.191 0.988
14:36:51.427 -> -0.062 -0.162 1.071
14:36:51.536 -> -0.010 -0.088 1.071
14:36:51.614 -> -0.015 -0.037 1.052
14:36:51.725 -> -0.022 -0.047 1.044
14:36:51.837 -> 0.062 -0.043 1.012
14:36:52.025 -> FIFO STATUS REG: A0
14:36:52.025 -> Shock Occured
14:36:52.062 -> ACT STATUS SHOCK REG: 1
14:36:52.062 -> INT_SOURCE: C3
14:36:52.137 -> 0.055 -0.081 0.997
14:36:52.252 -> 0.024 0.031 1.033
14:36:52.354 -> 0.011 -0.072 1.079
14:36:52.455 -> 0.022 -0.031 0.973
14:36:52.547 -> 0.014 -0.042 1.041
14:36:52.654 -> -0.062 -0.036 1.018
14:36:52.770 -> -0.080 -0.003 1.003
14:36:52.880 -> -0.081 -0.118 1.084
14:36:52.972 -> -0.080 -0.039 1.046
14:36:53.079 -> -0.109 -0.016 0
根据数据表,它说我们需要在每个触发事件后重置触发模式。我试过这样做,但无济于事。
我正在使用I2C进行多字节读取,并实现了跨度为4的移动平均滤波器。
1条答案
按热度按时间tp5buhyn1#
更新:我能够得到输出值。我所要做的就是在初始设置中进入旁路模式来重置触发模式。并在每次冲击事件后再次重置。
这是我在设置中添加的代码部分,并在每次冲击事件后调用。
至于即使在冲击后仍保持恒定的值,我在仅阅读输出FIFO [0]后重置触发模式,此时有10个FIFO要收集数据,正如我在寄存器0x38中配置的那样(样本= 10)。因此,冲击值存储在FIFO的后级,而不是FIFO [0]。在冲击事件后阅读FIFO超过10次,然后重置触发模式解决了问题。
样品输出(X Y Z,单位g):