sparkfun / SparkFun_AK975x_Arduino_Library

An Arduino library for the AK975x digital quad PIR human presence sensors
https://www.sparkfun.com/
Other
10 stars 10 forks source link

Interrupt functions upgrade : INT pin has bad behaviour and INTST register values are incorrect #3

Open thedub2001 opened 6 years ago

thedub2001 commented 6 years ago

Hello! I'am using the SparkFun_AK975x_Arduino_Library with a non-Sparkfun AK9750 module. Every function of the library works fine.

I tried to implement interrupt management but I'am having bad results :

Only IR13L / IR24L interrupts are triggering

One interrupt only is triggering on the couple HIGH/LOW threshold: This is IR13L / IR24L. It triggers when the differential signals of two IR sensors (IR1 - IR3 / IR2 - IR4) are equal to or below the lower threshold levels. (datasheet page 32) Physicaly this correspond in sensor 4 excited for IR24L and sensor 3 excited for IR13L.

The other interrupt is not triggering normally : This is IR13H / IR24H. It should trigger when the differential signals of two IR sensors (IR1 - IR3 / IR2 - IR4) are equal to or above the upper threshold levels. (datasheet page 32)

Bad INTST register value :

Lets take an example with setting IR24L for triggering (EINTEN = 11000010) here is the INTST values when INT output triggers :

Sensor 4 excited, sensor 2 idle : INTST = 11100010      OK
when exiting the sensor 4 aera : INTST = 11100000       NOT OK
Sensor 4 idle, sensor 2 excited : INT pin doesn't trigger   OK

INT pin should not trigger when exiting from sensors aera with a null INTST register value (11100000)

Next we set IR24H for triggering (EINTEN = 11000100) here is the INTST values when INT output triggers :

Sensor 4 excited, sensor 2 idle : INTST = 11100000      NOT OK
when exiting the sensor 4 aera : INTST = 11100100       NOT OK
Sensor 4 idle, sensor 2 excited : INT pin doesn't trigger   NOT OK

INT pin should trigger when sensor 2 is excited and sensor 4 is not (idle) INT pin should not trigger when sensor 4 is excited and sensor 2 is not excited with a null INTST register value (11100000) INT pin should not trigger when exiting from sensors aera with a INTST value corresponding to IR24H (11100100)

Threshold has no effect on interrupts

Setting threshold has no effect on interrupts. INT pin is flickering on small "ir2-ir4" values while threshold si set on maximum value Here is the Serial output of a basic sketch : IR24L is set for triggering (EINTEN = 11000010). Each time the interrupt is triggered, a message is printed with

the INTST register value
the result of ir2-ir4
the time since the last interrupt
AK9750_INTST : 11100010
ir2-ir4 : -8
time : 1022

AK9750_INTST : 11100000
ir2-ir4 : 32
time : 35

AK9750_INTST : 11100010
ir2-ir4 : -16
time : 88

AK9750_INTST : 11100000
ir2-ir4 : 16
time : 35

AK9750_INTST : 11100010
ir2-ir4 : -8
time : 123

AK9750_INTST : 11100000
ir2-ir4 : 64
time : 17

AK9750_INTST : 11100010
ir2-ir4 : -16
time : 618

AK9750_INTST : 11100000
ir2-ir4 : 16
time : 17

I really want to use the interrupt pin to reduce power consumption and read sensor values only when the interrupt pin is triggered. I hope you could help but I think this problems are coming from the product itself.

Attachments :

The modificated SparkFun_AK975x_Arduino_Library (I worked on a previous version of the library) Schematic used AK9750 datasheet

thedub2001 commented 6 years ago

The "BasicReadings" sketch shows normal behaviour when not using interrupt pin.

Serial plotter outputs showing ir2 (blue) and ir4 (red) values : ak9750_from2to4 image 1 : hot body passing form sensor 2 to sensor 4

ak9750_from4to2 image 2 : hot body passing form sensor 4 to sensor 2

joepelderman commented 6 years ago

Hi,

I'm having the same problem, unfortunately.

Have you since been able to verify that it is an hardware problem with the AK9750? Will the threshold values for example correctly effect the interrupt triggering on the AK9753? It would be really cool for low power performance if this issue is resolved!

nseidle commented 6 years ago

Excellent issue write up - one of the best I've seen.

Your interrupt code in your forked lib looks solid. There is one spot here where you are doing an int that should probably be a uint8_t but it shouldn't cause any problems.

What's going on here? You are clearing the hysteresis bits then setting them again. That doesn't look right.

I think the hysteresis needs to be set before interrupts can function properly.

thedub2001 commented 6 years ago

I managed to make interrupts work perfectly. I updated the forked SparkFun_AK9750_Arduino library. As it has been a long time since I haven't worked on it, I forgot a lot. I remember that WRITING IN EEPROM HAS NO EFFECT that's why you must set threshold, hysteresis and interrupts on each reboot.

Here is my boot sequence :

  if (movementSensor.begin()) {
    movementSensor.setThresholdIr2Ir4(HIGH,ThresholdHighValue);
    movementSensor.setThresholdIr2Ir4(LOW,ThresholdLowValue);
    movementSensor.setHysteresisIr2Ir4(HysteresisValue);
    movementSensor.setInterrupts(0,0,1,1,0);
    diagPirRunning=1;
    DEBUG_PRINTLN(F("PIR running"));
  } else {
    DEBUG_PRINTLN(F("PIR sensor failed to connect"));
    diagPirRunning=0;
  }
joepelderman commented 6 years ago

Awesome! That fixed it for me as well, Thank you.

AndyEngland521 commented 5 years ago

Hey @thedub2001 I just got approached by Mark over in tech support, do you still have your fork of the library? Any chance we could do a pull request to get this updated interrupt functionality into ours?

SebastienPitt commented 5 years ago

Hi, I am no expert. Just trying to make something work for art purposes. So starting from the the provided sketch Exemple4-ThresholdsTests from the SparkFun hookup guide, I am attempting to test thresholds thought a esp8266 Thing Dev by sending OSC message with a «switch» function and some string parsing (replacing serial commands). The messaging part works fine (using MicroLed to monitor incoming messages). Sending interrupts seems to work when sending 4,0-4,31. I get good readings (stops) from differentials with ir1-ir3 and ir2-ir4, still a little bit jittery. But thresholds and Hysteresis are not doing anything. Am I right to assume that the solution put forth by @thedub2001 is making «on the fly» thresholds tests obsolete?