Pull to refresh

Working with digital infrared passive motion sensor PYD 1588

Programming microcontrollers *
  1. General information about PYD 1588 digital detector

In this article, there is the working with the PYD 1588 digital Infrared passive motion sensor introduced. The PYD 1588 is a serial opposed format, two element detector based on pyroceramic produced by the Excelitas Technologies. This sensor represents a low-power (3.0 uA with 1.8 V source voltage as in the documentation said) passive component with two sensible elements, which measure the thermal infrared radiation stream.

The signal is converted to a digital value using Sigma-Delta and DSP techniques. A configurable motion detection unit is implemented, which can generate an interrupt recognized by the external microcontroller (MCU) in case motion is detected. The motion detection unit contributes to significant device energy efficiency increasing via putting the MCU to a low-power sleep mode with no periodic raw data request and its analyzing necessity.

According to the declared technical characteristics the detector is capable of heated body motion registration within 115° field of view and with no auxiliary Fresnel lenses. It should be noticed that the digital detector PYD 1598 is a full analog to the described PYD 1588 except field of view only: the PYD 1598 structurally has a wider window (130°). PYD 1588 is implemented in TO-5 metal housing for high EMI immunity.

Figure 1 - PYD 1588, PYD 1598 pinout and dimensions
Figure 1 - PYD 1588, PYD 1598 pinout and dimensions

There are two 1-Wire serial interfaces with different technical and time characteristics implemented: the unidirectional “Serial In” interface (whose purpose is a configuration parameter loading) and the half-duplex “Direct Link” interface (whose purpose is a digital data reading). Whereas the “Serial In” interface is slower: in comparison with the “Direct Link” it has been allowed prolonged, up to 2 us, time slots. Therefore if one uses the preconfigured via “Serial In” interface embedded motion detection unit, the less productive (low clock frequency) microcontrollers could be used.

Figure 2 - PYD 1588, PYD 1598 block diagram
Figure 2 - PYD 1588, PYD 1598 block diagram

The pyroelectric sensing elements are connected to a built-in IC, whose functions are shown in the block diagram of the accompanied datasheet (figure 2).

The digital signal processing is provided by ASIC within the sensor package, which contains an oscillator, a voltage reference, and an analog to digital converter (ADC) with multiplexed inputs for the pyro-electric elements as well as for the internal temperature sensor. The ASIC also includes a motion detection unit and low and high pass filters. The “Serial In” serial interface is provided to configure the internal registers. The configuration memory is volatile which means that after powering up the register settings are undefined.

The serial “Direct Link” interface can be configured to:

  • send an interrupt once a motion event is detected;

  • read a continuous data stream from the detector.

Figure 3 illustrates the processing of the pyroelectric sensor signal analyzed after bandpass filtering (BPF) and when the internal motion detection unit is on.

Figure 3 - An example of the signal processing (after band pass filter) with the motion detection unit is on
Figure 3 - An example of the signal processing (after band pass filter) with the motion detection unit is on

In this mode, the “Direct Link” line pulls in a high state, when the motion criteria are met and cannot be automatically fallen back to a low state. To clear the interrupt, the “Direct Link” line has to be pulled to a low state by the MCU for at least 160 us. When the alarm event is cleared by resetting the interrupt, any further motion detection is stopped for the programmed blind time.

  1. Configuration register

Table 1 - The configuration register content
Table 1 - The configuration register content

[24:17] - threshold.

The voltage threshold value, achievement of which is interpreted as the motion alarm event that depends on pulse counter settings.

[16:13] - blind time.

The purpose of blind time is to avoid immediate retriggering after a motion event was detected and

an interrupt was signalized. The blind time starts counting after pulling the “Direct Link” line from high to low state by the host system. The time can be selected between 0.5 sec and 8.0 sec in steps of 0.5 sec.

[12:11] - pulse counter.

The amount of pulses above the threshold is counted in a specified window time. It can be

configured from 1 up to 4 pulses, which depends on the device application-specific (whether it is a volumetric or radial motion sensor).

[10:9] - window time.

The pulse counter is evaluated for pulses above the threshold within a given moving window time. The window time can be set from 2 sec up to 8 sec.

[8:7] - operation mode.

There are three operation modes are available:

  • "Forced Readout" mode;

  • "Interrupt Readout" mode;

  • "Wake Up" operation mode;

In "Forced" and "Interrupt Readout" mode the “Direct Link” interface is used to read raw data and for configuration settings. In Wake up operation mode, the internal alarm event unit is used to generate a low to high transition on the “Direct Link” line once the criteria for the motion was met.

[6:5] - signal source.

There are three signal sources are available:

  • pyroelectric sensor signal after bandpass filtering (PIR BPF), a signed integer in the range of -8192 to 8192 counts [00];

  • pyroelectric sensor signal after low pass filtering (PIR LPF), an unsigned integer in the range of 0 to 16383 counts [01];

  • temperature sensor signal, an unsigned integer in the range of -8192 counts to 8192 counts [11].

The temperature sensor signal data can be used to ignore false triggers due to sudden temperature changes (1°C / min).

[2] - HPF cut-off.

The parameter value of the optimal high pass cut-off frequency in the bandpass filter depends on the motion pattern and the application-specific. The longer the necessary distance is the less the parameter value chosen [1]. The shorter the distance is, the more the parameter value is [0].

[0] - count mode.

If the mode is set to 0, pulses above the threshold are only counted when the sign of the signal changes after BPF. If set to 1, no zero crossing is required.

  1. “Serial In” Interface

The 1-Wire unidirectional serial “Serial In” interface is used for configuration data loading. The data loading process is depicted in figure 4.

Figure 4 - The data loading process to the PYD 1588, PYD 1598 detector configuration register via “Serial In” interface
Figure 4 - The data loading process to the PYD 1588, PYD 1598 detector configuration register via “Serial In” interface

While the data transmits, the “Direct Link” interface line must be pulled down by the external MCU. For the data transmitting initialization, the external MCU drives the “Serial In” interface line from the low state to the high state. And next, depending on the transmitted bit value (one or null), the MCU holds it on to the corresponding state (high or low). The clock pulse might be as short as the MCU clock pulse. The bit transmitting duration  (holding the line in the appropriate state) must exceed at least 80 us (t_shd). As soon as the detector gets all of 25 data bits and the transmitting process interrupts by pulling the “Serial In” interface line to a low state (t_slt) for a time of more than 650 us, the gotten parameters are loaded to the configuration register.

  1. Direct Link Interface

The “Direct Link” interface is the 1-Wire serial half-duplex Interface that serves to generate an alarm signal from the motion detection unit or for continuous relevant detector data reading.

Table 2 - The PYD 1588 data packet content transmitted via “Direct Link” interface
Table 2 - The PYD 1588 data packet content transmitted via “Direct Link” interface

[39] - Out of Range.

The internal ASIC has Out of Range detection feature: if the processed signal coming from the pyroelectric infrared sensor changes drastically in any direction on 511 ADC counts, the input circuit is shorted for 16 ms for sensor discharging. In this case, the 39th bit has a null value. That means that technical failures occurred, caused by pyroelectric element instability. During the regular detector mode, the 39th bit is set to one. For example, the data might be considered invalid when the strong temperature changes were (more than 1 K/s).

[38:25] - ADC counts.

The analog to digital processing can take place from three different sources: after the low pass filtering, after the bandpass filtering, and from the temperature sensor. The digitized data after the BPF is available every 20 ms after the previous data reading. The data reading more often than within the specified period can lead to irrelevant data getting.

[24:0] - configuration.

The motion detection unit parameters that loaded in the PYD 1588 configuration register.

Figure 5 - The data PYD 1588, PYD 1598 reading process via “Direct Link” interface
Figure 5 - The data PYD 1588, PYD 1598 reading process via “Direct Link” interface

Timing.

The “Direct Link” interface communication principle is depicted in figure 5. The whole process can be divided into the initialization phase (the start condition transmission) and the data stream. The reading initialization process is produced by driving the “Direct Link” interface line from a low to a high state for at least 120 us. The start condition depends on the chosen detector mode and can be initialized either by the external MCU (Forced Readout) or by the PYD 1588 detector itself (Interrupt Readout).

Wake Up mode.

As soon as motion is recognized by the motion detection unit the sensor pulls the line from a low to a high state. To reset the alarm motion detection state the external MCU has to pull the line from a high to a low state for a time not less than 160 us. New data is available after the alarm reset not earlier than in 120 us. For correct detector work in this mode, the external MCU pin connected to the “Direct Link” interface line must be configured as input and has a high impedance state (high Z).

Forced Readout and Interrupt Readout modes.

In these modes, the data reading process is the same. The main difference is the initialization phase: in the Forced Readout mode the start condition sending (120 us-pulse) is organized by the external MCU, while in the Interrupt Readout mode the PYD 1588 pulls the line high by itself every 16 ms, and the external MCU must drive the line to low not earlier than in 120 us. To recognize detector readiness for the next data reading session, the MCU pin connected to the “Direct Link” interface line also must be switched to a high impedance state (high Z) and be configured as an input.

The data reading process.

After driving the initialization pulse from a high to a low state the detector awaits the next rising edge pulse generated by the external MCU, whose pin has to be set as input. At the same time, the detector holds the line in a high state for one-bit value transmitting or drives the line to a low one for null bit value transmitting. The time taken for switching the line from one state to another depends on the line capacity. This means that the timeslots customization should be started with the maximum time declared in the datasheet (22 us) and gradually decrease to the maximum stable communication bitrate.

After the single bit reading the external MCU pulls the line to a low state again for the next transmission initialization of the packet bit. Further, the action consequence is repeated unless the last bit is transmitted. After the last bit receiving the external MCU must hold the “Direct Link” interface line in a low state of at least 160 us. It is recommended to realize the single communication session within 800 us time interval. It is possible to interrupt the data reading process at any moment by driving the “Direct Link” interface line to a low state for a time not less than 120 us.

  1. Example of working with the PYD 1588 detector.

Table 3 - The detector loaded parameters choosing:

parameter

value

note

threshold

0x1F

31 / 256 = 12% to maximum

blind time

0x06

0.5 + 0.5 * 6 = 3,5 sec

pulse counter

0x00

one crossing

window time

0x00

2 + 0 * 2 = 2 sec

operation mode

0x10

Wake up mode

signal source

0x00

PIR sensor, BPF

HPF cut-off

0x00

0.4 Hz

count mode

0x01

with no zero-crossing

The data bit sequence is introduced in table 4. The writing process of the chosen parameters via the “Serial In” interface, which is obtained with a logic analyzer, is described in figure 6.

Table 3 - Example of parameters writing to the configuration register of the detector

count

reserved

cut off

reserved

signal source

operation mode

window time

pulse counter

blind time

threshold

24

23

22

21

20

19

18

17

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

0

1

0

0

0

0

0

0

0

1

0

0

0

0

0

1

1

0

1

1

1

1

1

0

0

0

Figure 6 - The cyclogram of parameters writing to the configuration register of the detector
Figure 6 - The cyclogram of parameters writing to the configuration register of the detector

The cyclorama of the parameters writing and reading processes of the PYD 1588 detector is depicted in figure 7:

  1. the Forced Readout mode writing (“Serial In” interface);

  2. the detector data reading (“Direct Link” interface);

  3. switching to Wake up mode of the detector (“Serial In” interface).

Figure 7 - The cyclogram of the writing and reading processes of the PYD 1588 detector
Figure 7 - The cyclogram of the writing and reading processes of the PYD 1588 detector

The function of writing the necessary data in the PYD 1588 configuration register via the “Serial In” interface has been developed. Also, the function of getting the PYD 1588 data via the “Direct Link” interface has been developed. The library is available on Github.

The maximum voltage range measured by the detector ADC is 100 mV. ADC resolution is 14 bits (2^14 = ±8192 counts = 6.1 uV/count).

The code section with the parameters writing function is given below.

/*     Serial In interface realization     */

void load_parameters(uint8_t counting_mode,                                          //  pulse counting method with the signal sign accounting
                     uint8_t cut_off_frequency,                                      //  the high pass cut-off frequency in the band pass 1lter
                     uint8_t signal_source,                                          //  a choice of three data sources is available (PIR BPF, PIR LPF, temperature sensor)
                     uint8_t operation_mode,                                         //  three sensor operation modes are available
                     uint8_t window_time,                                            //  the pulse counter increment is performed during the selected time
                     uint8_t pulse_counter,                                          //  the amount of pulses above the threshold
                     uint8_t blind_time,                                             //  for avoid immediate re-triggering after a motion event detection
                     uint8_t threschold,                                             //  threshold voltage
                     uint16_t t_shd,                                                 //  data bit time (not less than 80 us)
                     uint16_t t_slt)                                                 //  hold time for detector data latching
{

    DL_LINE_HIGH_TO_LOW;

    SI_LINE_HIGH_TO_LOW;                                                            //      initialization impulse
    SI_LINE_LOW_TO_HIGH;
    SI_LINE_HIGH_TO_LOW;

    /*	parameters setting	*/

    uint8_t p_counting_mode     = counting_mode;
    uint8_t p_cut_off_frequency = cut_off_frequency;
    uint8_t p_signal_source     = signal_source;
    uint8_t p_operation_mode    = operation_mode;
    uint8_t p_window_time       = window_time;
    uint8_t p_pulse_counter     = pulse_counte;
    uint8_t p_blind_time        = blind_time;
    uint8_t p_threschold        = threschold;

    uint16_t loaded_data[0x02] = {0x00};
    uint8_t *bit_field[0x04] = {0x00};

    bit_field[0x00] = &p_pulse_counter;
    bit_field[0x01] = &p_window_time;
    bit_field[0x02] = &p_operation_mode;
    bit_field[0x03] = &p_signal_source;


    #ifdef MSP430                                                                   //  lsb (msp430) to msb (pyd1588) data format converting

    p_blind_time = ((p_blind_time & 0x0A) >> 0x01) | ((p_blind_time & 0x05) << 0x01);
    p_blind_time = ((p_blind_time & 0x0C) >> 0x02) | ((p_blind_time & 0x03) << 0x02);
    
    for(uint16_t i = 0x00; i < 0x04; i ++)    {
      *bit_field[i] = ((*bit_field[i] & 0xAA) >> 0x01) | ((*bit_field[i] & 0x55) << 0x01);
    }
    
    lsb_to_msb(&p_threschold);

    #endif
        
    loaded_data[0] |= p_threschold;
    loaded_data[0] |= (p_blind_time        << 0x08);
    loaded_data[0] |= (p_pulse_counter     << 0x0C);
    loaded_data[0] |= (p_window_time       << 0x0E);
    loaded_data[1] |= p_operation_mode;
    loaded_data[1] |= (p_signal_source     << 0x02);
    loaded_data[1] |= (p_cut_off_frequency << 0x06);
    loaded_data[1] |= (p_counting_mode     << 0x08);
                 
    for(uint8_t i = 0x00; i < 0x02; i ++)     {
          
      for(uint8_t k = 0x00; k < 0x10; k ++)     {

        if((k == 0x09) & (i == 0x01))     {
         
          SI_LINE_HIGH_TO_LOW;
          break;
        }
        
        if((loaded_data[i] & (0x01 << k)) == 0x00) {
          
          SI_LINE_HIGH_TO_LOW;
          SI_LINE_LOW_TO_HIGH
          SI_LINE_HIGH_TO_LOW;
        }

        else {
          
          SI_LINE_HIGH_TO_LOW;
          SI_LINE_LOW_TO_HIGH;
        }
                    
        bit_time(t_shd);
      }
    }
    SI_LINE_HIGH_TO_LOW;
    bit_time(t_slt);
    DL_LINE_INPUT_MODE;
}

The source code is located on Github. The Interrupt Readout mode isn`t realized. The data experiments when the device is powered by a battery by the moment of the article composing are not available. The whole information about the PID 1588 detector was taken from the according to documentation located on the manufacturer's site.

Tags:
Hubs:
Total votes 3: ↑3 and ↓0 +3
Views 743
Comments Leave a comment