1
\$\begingroup\$

I found a lot of algorithms for pedometers that assume a fast CPU with a decent ALU and high sampling rates, which I don't have. (Z80) However, the LIS3DH has various options for generating interrupts when some condition occurs.

How can I configure it such that it generates interrupts when I'm walking? High accuracy is not needed, I just need to know if the user is moving or not.

I looked through the datasheet, but there are more options than I can wrap my head around. Click detection looked promising, but gave useless, semi-random results, maybe because it only detects fast clicks and not walking speeds. There are also options for free-fall interrupt, inertial interrupt, orientation detection, high-pass filter, FIFO, and more.

I'll sleep on it and toil along tomorrow, but any wise words are hugely appreciated.

Datasheet
Application note

\$\endgroup\$
  • \$\begingroup\$ It is unclear why you need the LIS3DH to generate interrupts. A Z80 isn't super fast, but still quite a lot of instructions/second. I would normally expect to monitor the sensor at a regular rate, say 1kHz. By sampling at a regular rate it should be easier to estimate speed and direction than from interrupts. \$\endgroup\$ – gbulmer Aug 28 '16 at 21:35
  • \$\begingroup\$ Well, with an SPI bus at 8000hHz, that's unsustainable. Think 7 bytes per sample and a slow chip select and you're looking at 100Hz max. Then you have to do math on 16 bit numbers with an ALU that only does 8-bit add/subtract on a CPU that's busy running a game. \$\endgroup\$ – Pepijn Aug 29 '16 at 6:23
  • \$\begingroup\$ Well, I live and learn. Interesting. Thank you. I had assumed because SPI is so common, and straightforward, that it would be 1MHz. Apologies for wasting your time. \$\endgroup\$ – gbulmer Aug 29 '16 at 16:06
1
\$\begingroup\$

Section 6.3.2 and 6.3.3 of the application note explains how to raise an interrupt when an axis exceeds a certain value. Combined with a high-pass interrupt to get rid of the gravity vector, allowed me to set a really low threshold that triggers at 64mg.

  call DelayFrame ; raise CS

  ld a, LIS3DH_REG_WHOAMI
  ld b, a
  call ReadRegister
  ld a, c
  ldh [hWhoAmI], a

  call DelayFrame ; raise CS

; based on application note section 6.3.2-3
  ld a, LIS3DH_REG_CTRL1
  ld b, a
  ld a, $77 ; CTRL1: enable all axes, 400HZ
  ld c, a
  call WriteRegister
  ld a, $0F ; CTRL2: high-pass filter on everything
  call SPITransfer
  ld a, $00 ; CTRL3: not used
  call SPITransfer
  ld a, $88 ; CTRL4: BDU, high resolution, 2g
  call SPITransfer
  ld a, $08 ; CTRL5: latch interrupt on INT1_SRC 
  call SPITransfer

  call DelayFrame ; raise CS

  ld a, LIS3DH_REG_INT1CFG
  ld b, a
  ld a, %00101010 ; int1 config: enable high int on all axes
  ld c, a
  call WriteRegister
  ld a, 0 ; src
  call SPITransfer
  ld a, 4 ; threshold
  call SPITransfer
  ld a, 0 ; minimum duration
  call SPITransfer
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.