Zilog ZMOTION user manual

Application Note
ZMOTIONTM Detection Module Application Walkthrough
AN030701-0810
Abstract
This application note describes in detail the application code associated with the ZMOTION Detection Module and how it can be used for detection and cont rol applications. The ZMOTION Detection Module can be used either in Hardware Mode or Serial Mode. In the Hardware Mode, you use the hardware circuit selecti on for sensitivity adjustments, delay time settings, ambient light settings, and Sleep Mode. In the Serial Mode, you can use the UART interface to fine-tune the ZMOTION Detection Module with advanced configuration settings.
Note: The application code (AN0307-SC01) associated with this application note has been tested with
ZDS II—Z8 Encore! version 4.11.0.
ZMOTION Overview
Zilog’s ZMOTION Detection Module is a complete, compact, and easy to interface solution for motion detection and direction. It is designed using an Enhanced Passive Infrared (ePIR) technology and Zilog’s Z8FS04 Motion Detection MCU with a powerful embedded software engine that delivers high-performance motion detection. Figure 1 on page 2 shows the location of the pins on the ZMOTION Detection Module.
Table 1 on page 2 describes the pin functions.
Copyright ©2010 by Zilog®, Inc. All rights reserved.
www.zilog.com
ZMOTIONTM Detection Module Application Walkthrough
Figure 1. ZMOTION Detection Module Pin Diagram
Operation Modes
There are two operation modes: Hardware Interface Mod e and Serial Interface Mode. In the Hardware Interface Mode, you can make the following adjustments:
Use the hardware interface pins for basic configuration.
Adjust the motion sensitivity with the voltage on the SNS pin.
Adjust the time delay (Output Active Time) with the voltage on the DLY pin
Set the optional ambient light input.
Use the Sleep Mode to reduce power consumption.
In the Serial Interface Mode, you can use the serial interface (Rxd and Txd) for advanced configuration:
9600 baud rate
No parity
8 data bits
1 stop bit
No flow control
The /MD, LG, and SLP pins remain functional.
Table 1. ZMOTION Detection Module Pin Description
Pin No.
1 2 3
4
Signal
Name
GND Ground Ground VDD Supply Voltage Supply Voltage RXD/DLY DLY-Delay (analog
TXD/SNS SNS Sensitivity
Hardware Interface
Mode Serial Interface Mode Description
input) (analog input)
RXD Receive Data (digital input)
TXD Transmit Data (digital input)
— — —
Mode select during Reset
AN030701-0810 Page 2 of 30
ZMOTIONTM Detection Module Application Walkthrough
Pin No.
5
6 7 8
Signal
Name
/MD/RST Motion Detect (digital
LG Light Gate (analog /SLP/DBG /SLP Sleep (digital GND Ground Ground
Hardware Interface
Mode Serial Interface Mode Description
output)
input) input)
Configurable: /RST Reset (digital input) /MD Motion Detect (digital input)
Light Gate (analog input)
/SLP Sleep (digital input)
Default is /RST (Reset ) i n Serial Interface Mode
If unused, connect to V DBG is used for
programming and debug.
dd
.
Hardware Interface Mode Description
Figure 2 shows a typical example of how to connect the ZMOTION Detection Module using Hardware
Interface Mode. This mode of operation is selected when a voltage between 0 V and 1.8 V i s presented to the SNS pin during power ON (or after a reset caused by Vbo). When the Hardware Interface Mode has been established, this pin becomes the Sensitivity input and accepts a voltage between 0 V and 1.8 V as reference for motion detection sensitivity level.
0 V = Highest Sensitivity
1.8 V = Lowest Sensitivity
In Figure 2, R2 and R4 form a simple potenti ometer resistor divider to ensure that the Hardware Mode is entered upon reset and to control sensitivity levels.
Figure 2. Application Example of Hardware Interface Mode
AN030701-0810 Page 3 of 30
ZMOTIONTM Detection Module Application Walkthrough
After the application of power, the passive infrared sensor needs some time to stabilize. This typically takes about 20 seconds but varies depending on environmental conditions. The software dynamically monitors the pyroelectric sensor during power-up and begins detecting motion as soon as the sensor is stable.
The /MD (Motion Detect) pin is driven active (Low) when motion is detected. The voltage on the delay pin (DLY) is used to determine the active duration o f the /M D si gnal. This can be easily set using a resistor divider circuit shown in Figure 2 on page 3. With an 82-kA (R1) resistor tied to Vcc and values ranging from 0 A to 100 kA (R3) tied to ground, you can select d elay times from 2 seconds to 15 minutes. See Figure 2 on page 3 and Table 15 on page 20.
Table 2. Delay Times Using R1 = 82 K*
Delay Time R_DLY Voltage R_DLY Standard Resistor Value
2 sec 0 V 0 @ 5 sec 0.2 V 5.1 k@ 10 sec 0.4 V 11 k@ 30 sec 0.6 V 18 k@ 1 min 0.8 V 24 k@ 2 min 1.0 V 33.2 k@ 3 min 1.2 V 43 k@ 5 min 1.4 V 56 k@ 10 min 1.6 V 68 k@ 15 min 1.8 V 91 k@
The Light Gate (LG) signal acts as a disable (gate) f or the /MD output signal. In a typical application, this signal is a representation of the ambient light i n th e env i ronment. If there is light detected, the /MD signal does not activate even in the presence of motion.
Serial Interface Mode C ommands
The Serial Interface Mode operates as a host - cl ient relationship where the ZMOTION Detectio n Module is the client. Commands are sent from the host, and the module responds with the requested information or confirmation. The only exception is when the module is configured for “/MD Unsolicited” operation. Under this condition, it will send motion-detected information without first receiving a command from the host.
All the serial commands sent to the ZMOTION Detection Module are in ASCII character s f ormat, but the data sent to and from the module can be ASCII or decimal.
There are three types of commands accepted by the module:
Read commands
Write commands
Confirmation commands
Read Command Structure
Read commands are used to request information from the module. Read commands are sent from the h ost, and the module responds with the requested data. See Figure 3 on page 5.
All read commands are initiated by single lower-case letters.
When received, the device will return the applicable value as described in
AN030701-0810 Page 4 of 30
ZMOTIONTM Detection Module Application Walkthrough
Table 16 on page 21.
Figure 3. Read Command Structure
Write Command Structure
Write commands are used to update configuration of the module. The command is sent from the host, and the module responds with the current value as an acknowledgment. Then the host sends the new data, and the module responds with an 'ACK'. See Figure 4.
All write commands are initiated by single upper-case letters.
When a write command is received, the device returns the current value and expects an appropriate single-
byte data value.
When the data value is received, the device returns an 'ACK'. If no data is received after the inactivity
timeout of 2.5 seconds, the device returns a 'NACK'.
Figure 4. Write Command Structure
Confirmed Command Structure
Certain commands require a specific sequence of characters to be sent in order to help prevent accidental initiation. These commands require a 4-character confirmation sequence. When a command r equiring confirmation is received, the device returns an 'ACK' . See Figure 5.
If the sequence is correct, the device returns an 'ACK' and executes the command.
If the sequence is incorrect, or there is an inactivity delay of more than 2.5 seconds between any characters
of the sequence, the device immediately sends a 'NACK' and does not execute the command.
Figure 5. Confirmed Command Structure
Notes: 1. ACK = 0x06 (ASCII ACK character).
2. NACK = 0x15 (ASCII NACK character). The ZMOTION will respond with a 'NACK' on all
AN030701-0810 Page 5 of 30
ZMOTIONTM Detection Module Application Walkthrough
unrecognized commands or when a command requires data (that is, Write, Clear, and Confirmation types) but does not receive the required data within the inactivity timeout period.
Software Overview
The application code in the ZMOTION Detection Module first executes an initialization procedur e, which is discussed in the “Setting the Operational Mode” section on page 7. When the module is enabled, the ADC interrupt runs in the background (see Figure 6). Every ADC conversion generates an interrupt and the ZMOTION engine performs its functions during this time (see Figure 6). The user application code runs in the foreground and monitors the status through the API and performs any other functions required for the application, which is discussed in the “Main Application Loop” section on page 8.
Figure 6. ADC Interrrupt for ZMOTION Detection
One-Second Timer Tick
The ZMOTION engine requires a 1-second time base to perform various housekeeping operations (see Figure
7 on page 7). This is handled in the application by the timer interrupt. The Timer0 Interrupt is configured for
100 ms. The application code counts 10 of these interrupts and sets the Engine Timer Tick bit in ePIR_SC1.
AN030701-0810 Page 6 of 30
ZMOTIONTM Detection Module Application Walkthrough
1 Second
Timer Interrupt
Set bit 7 of ePIR_SC1
(Engine Timer Tick)
One
Second
Timer Tick
Return
Figure 7. One-Second Engine Timer Tick
Setting the Operation al Mode
The mode of operation (HW or Serial mode) can be selected using the TXD/SNS pin during the power ON or when exiting the Sleep Mode. The following explains the program in the operational mode (see Figure 8 on page 8):
1. The program starts by initializing all of the needed peripherals.
2. Check the Stop Mode Recovery SMR reset. If there is NO SMR reset, then the sensitivity level is
set to default and the ePIR status register is initialized.
3. The ePIR_ENABLE register is set to EPIR_ENABLE_PATTERN, so the engine can be enabled.
4. The EPIR_INIT macro is executed to initialize the ePIR engine.
5. Initialize Timer0 and set to 100-ms interrupt.
6. Check analog channel 0 (ANA0), which is connected to PIN4 or TXD/SNS if the analog level
exceeds the threshold or not. This is repeated 1 0 times to ensure a stable reading. If the TXD/SNS pin is above the threshold, then the cCmdState is set to 1; else, it is set to 0. This is done t o stabilize the ePIR engine.
7. Next, the mode of operation is determined with the value of the cCmdState. If the cCmdState is 1,
then the Mode of Operation is Serial Interface, and if the cCmdState is 0, then the Mode of Operation is Hardware Interface.
8. Finally, the mode of operation is set, and cCmdState is set to IDLE state; it then proceeds to the
main application loop.
AN030701-0810 Page 7 of 30
ZMOTIONTM Detection Module Application Walkthrough
Figure 8. Flow Diagram of Operational Mode
Main Application Loop
Figure 9 on page 9 describes the main application loop of the ZMOTION Detection Module.
AN030701-0810 Page 8 of 30
ZMOTIONTM Detection Module Application Walkthrough
Figure 9. Flow Diagram of Main Application Loop of Application Code
The following describes the operation of the main application loop:
1. The program checks the Sleep pin if it is low. If the Sleep pin is low, then the program enters to
the Sleep Mode.
2. Next the program checks the content of the cModule Status1 (cModuleStatus1) flag. See Table 20
on page 23.
If the Serial Mode Register (SER_MODE_ENABLED) is HIGH, several select cases are
available depending on the inputs of the select case. See
AN030701-0810 Page 9 of 30
Loading...
+ 21 hidden pages