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.
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
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
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
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
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.
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
Table 17 on page 22. The contents of the cModuleStatus1 flag are evaluated and updated.
•If the Sleep Mode Request (MOD_SLEEP_REQ) is HIGH, then the MCU Sleep Flag will be
on, and the MCU will go to sleep. This is to reduce the power consumption of the MCU
especially for battery-powered devices.
3. The program checks the state of the cModule Status2 (cModuleStatus2) flag. See Table 21 on page
23.
•If the ADC current channel scan (SCAN_SE NS_POT) is HIGH and the conversion for Sense
potentiometer is complete, then the program gets the latest Sense value from the
potentiometer.
•If the Scan delay pot (SCAN_DELAY_POT) i s HI GH and the conversion for Delay
potentiometer is complete, then the program gets the latest Delay setting from the
potentiometer
•If the Scan Light Gate (SCAN_LIGHT_GATE) is HIGH and the conversion for the Light
Gate is complete, then the program gets the latest ambient light level for light comparison.
•If the Scan Request (SCAN_REQUEST_NEW) new is high, then the program will request
new ADC channel conversion.
4. Finally, the program checks again the status of the cModule Status1 (cModuleStatus1) flag. See
Table 20 on page 23.
•If the Mode Pir Stable (MOD_PIR_STABLE) is LOW, then the program checks the PIR
sensor stability after power up.
•If the Mode Pir Stable (MOD_PIR_STABLE) is HIGH, the engine will indicate an alarm and
checks for motion detected and updates the output.
Sleep Mode in Hardware Interface Mode
Sleep signal can be used to put the device into a low-power mode. Using this feature will allow a sh orter PIR
stabilization time.
If the Sleep (/SLP) input signal is driven LOW, the device enters into a low-power Sleep Mode. It can be
awakened by either deactivating the /SLP sig nal (driving the signal HIGH) or sending a charact er over the
serial interface; the received character is r ecei ved and processed.
Serial Interface Mode (Software Interface Mode)
The Serial Interface Mode is responsible for handling serial command input and processing. See Table 3.
Table 3. Command State (cCmdState)
Command State (cCmdState) Description
Idle State This state puts the ZMOTION into standby mode
Real Time State This state puts the program in real-time mode. This s tate is enabled if the
received command is “Y” and disabled if the received comm and is “N”.
Suspend Status State This state temporarily ena bles or disables the motion detection of the program.
This state is enabled if the received command is “Y” an d di sabled when the
receive command is “N”.
Serial Interface Mode State This state let the user change the mode of sending the data f ormat of the
ZMOTION to either ASCII or Decimal. The ASCII mode is enabl ed if the
command received is “A” and Decimal Mode if the command received is “D”.
Sensitivity Change State This state changes the sensitivity of the ePIR engine to t h e t arget m ot i on.
Sensitivity is higher with a lower number value. 0x00 being t he m ost sensitive
and 0xFF being the least sensitive.
Sleep Duration State This state changes the time duration of Sleep Mode.
Delay Change State This state changes the time delay of changing the state from one state to
another.
Light Threshold Change
State
MD Output Change State This state indicates how the ePIR engine detected the last mot io n-detected
Configuration Change This state is used to configure the motion detection. If the received command
Direction Change State This state is used to configure the direction of the motion to positive, negative,
Dual Direction Change State This state determines if the engine should accept signals from one or two ePIR
Hyper-sense Change State This state changes the sensitivity of the ZMOTION. If this state is enabled, the
Ping Write Request State This state is used to clear and temporarily save the receive d command.
Frequency Response State This state determines the frequency response of t he mot i on det ection system.
Range Control State This state determines the relative range of motion detection. Larger values
Reset Mode State This state uses the watch-dog timer to have system reset.
Sleep Mode State This state puts the program in Sleep Mode. This state uses the watch-dog
This state is used to control and monitor the signal a ss ociated with the Light
Gate pin.
event. When the ZMOTION sets the Motion Dete ct ed bit in ePIRStatus0, it
also sets this bit according to which detection engi ne registered the event.
is ‘R’, then it is requesting for a Reset. If the receive command is ‘M’, then it is
requesting for make motion detection.
or disabled. Positive movement is requested when a “+” i s re ceiv ed, negative
movement is requested when a “-” is received, and disabled mot i on detection
is requested when “A” is received.
sensor. If configured as single operation then only one sensor is used which is
connected to ANA2. If it is configured as dual operation then Z MOTION will
scan two sensors simultaneously with the second sensor connected to ANA3.
engine considers smaller signal changes as valid motion ev ent s. This
significantly increases sensitivity at the cost of more potential false motion
detections.
Higher values allow lower frequencies to be acce pted by the ePIR engine.
Lower values cause the engine to ignore targets that generate lower
frequencies.
decrease the range of detection.
timer to have system reset that wakes up MCU.
Sleep Mode Request in Serial and Hardware Interface Mode
The program enters Sleep Mode request if MOD_SLEEP_REQ in cModuleStatus1 register is enabled and
sleeps for the given time duration depending on the value of the set sleep duration.
Sensitivity Setting from Potentiometer (Hardware Interface Mode)
Get the latest Sense setting from the Pot. The p rogram gets the latest sense from the poten t iometer if the
SCAN_SENS_POT is enabled in cModuleStatus2 register and the SC3_ANA0_SCAN_REQUEST is disabled.
Then the ePIR_sensitivity is updated.
Delay Setting from Potentiometer (Hardware Interface Mode)
Get the latest Delay setting from the Pot. The p r ogram checks if the SCAN_DELAY_POT is enabled in
cModuleStatus2 register and then updates th e cDelayTime.
Ambient Light Level for Gate comparison (Hardware Interface Mode)
Get the latest Ambient light level for Light Gat e comparison. The program checks if the
SCAN_LIGHT_GATE is enabled in cModuleStatus2 register and the updates the value of cLGAmbient.
ADC Conversion and Request Next Channel Conversion (Hardware Interface Mode)
Request new ADC channel conversion. Th e program checks if the SCAN_REQUEST_NEW is enabled in
cModuleStatus2 register and then the cModuleStatus2 register is updated.
Sensor Stability
Check for PIR sensor stability. The p rogram checks the stability of the system by verifying if the
MOD_PIR_STABLE is enabled in cModuleStatus1 register after power up.
Motion Detection
Check for motion detected and update the output on time as needed. The program checks if motion is detected
by checking if the SCO_MOTION_DETECTE D is enabled in ePIR_SCO register then send it once it is
needed.
References
The following documents are associated with ZMOTIONTM Detection Module and are available on
www.zilog.com:
•ePIR Motion Detection Zdots Single Board Computer Product Brief (PB0223)
This appendix lists the settings and resources you need for your build.
Use the following Compiler and Linker settings to prepare for your build:
ZDS Version
CPU Family
CPU
Limit Optimizations for Easier Debugging
Memory Model
Frames
Parameter Passing
Use Register Variables
Generate printf Inline
Bit-Field Packing
Place CONST Variables in ROM
Disable ANSI Promotions
Address Space
ePIR_Enable ePIR API Enable Register
ePIR_Sensitivity ePIR API Sensitivity Register
ePIR_SC0 ePIR API Status and Control Reg. 0
ePIR_SC1 ePIR API Status and Control Reg. 1
ePIR_SC2 ePIR API Status and Control Reg. 2
ePIR_SC1 ePIR API Status and Control Reg. 3
ePIR_Reserved_106 Reserve Standard API Register
ePIR_Reserved_107 Reserve Standard API Register
ePIR_Reserved_108 Reserve Standard API Register
ePIR_Reserved_109 Reserve Standard API Register
ePIR_ADC_Result ePIR ADC result Register
ePIR_Version ePIR Engine S/W Version Register
ePIR_Reserved_10D Reserve Standard API Register
ePIR_Reserved_10E Reserve Standard API Register
ePIR_Reserved_10F Reserve Standard API Register
Table 8. Register Address of Advanced API Interface (0xF0 to 0xFF)
UART 0 BRG high setting for 9600 Baud with IPO
UART 0 BRG low setting for 9600 Baud with IPO
UART 0 Control Register 0 value
UART 0 Control Register 1 value
Timer 0 reload value high when set for 5.5MHz standard clock
Timer 0 reload value low when set for 5.5MHz standard cloc k
Timer 0 Control 0 Register value
Timer 0 Control 1 Register value
WDT Upper byte, ~1000 ms
WDT High byte, ~1000 ms
WDT Lower byte, ~1000 ms
Oscillator control
Power control 0 register value
Table 11. Predefined Application Definitions with Initial Default Values
Light Gate threshold POR Default value
Default Frequency Response value
High Frequency Response value
Serial Interface Mode Inactivity timeout (x 100ms)
Table 12. Serial Interface Macro Definitions
Define Function Description
SER_ACK TxDirect(0x06) Serial Acknowledge
SER_NACK TxDirect(0x15) Serial Not Acknowledge
SER_AWAKE TxDirect(0x16) Serial Awake
Delay the program by 2 sec
Delay the program by 5 sec
Delay the program by 10 sec
Delay the program by 30 sec
Delay the program by 60 sec
Delay the program by 2 minutes
Delay the program by 3 minutes
Delay the program by 5 minutes
Delay the program by 10 minutes
Delay the program by 15 minutes
Idle State
Handle the Sensitivity Change state
Handle the Delay Change state
UNUSED
Handle the Freq. Response Change state
Handle the Sleep Mode state
Handle the Light Gate Threshold Change state
Handle the /MD Output State Change state
Handle the Direction Change state
Handle the Reset Request state
Handle the Real-Time MD Status Change state
Handle the /MD Config Change state
Handle the Hypersense Change state
Handle the MD Suspend Status Change state
UNUSED
Handle the Sleep Duration Change state
Handle the Ping write request
Handle the Range Control Change state
Handle the Dual Direction Change state
Handle the Serial Interface Mode state
Z8_NOP asm("NOP") Do nothing
Z8_WDT asm("WDT") Refresh the watch-dog timer
Z8_HALT asm("HALT") Enter "Halt" mode
Z8_STOP asm("STOP")Enter "Stop" mode
Z8_ATM asm("ATM") DI for the next 3 assembly instructions
This appendix describes the contents of API_INIT_06.h.
Table 23. Serial Command States
Define ValueDescription
EPIR_SENSITIVITY_DEF 16 ePIR Sensitivity Register Default Configuration for Normal Scan
Rate. The lower the value, the greater sensitivity.
EPIR_SC0_DEF 00h ePIR Serial Command Register 0 Default Configur at i on for
Normal Scan Rate
Bit 6-7 - Extended Detection - Level 0 (00)
Bit 5 - Engine Disabled - Engine Controlled (0)
Bit 4 - MD Suspend - OFF (0)
Bit 3 - Motion Direction Control – OFF (0)
Bit 2 - Motion Direction - Engine Controlled (0)
Bit 1 - Motion Detected - Engine Controlled (0)
Bit 0 - PIR Stable - Engine Controlled (0)
EPIR_SC1_DEF 28h ePIR Serial Command Register 1 Default Configur at i on for
Normal Scan Rate
Bit 7 - Engine Timer Tick
Bits 6-3 - Frequency Response (0101)
Bit 2 - PIR Scan Rate - Normal Mode (0)
Bit 1 - Reserved (0)
Bit 0 - Dual Pyro Enable – OFF (0)
EPIR_SC2_DEF 02h ePIR Serial Command Register 2 Default Configur at i on for
Normal Scan Rate. Lower values provide greater range.
Bits 7-3 - Reserved (00000)
Bits 2-0 – Range (010)
EPIR_SC3_DEF 00h ePIR Serial Command Register 3 Default Configur at i on for
Normal Scan Rate
Bits 7-0 - ANAx Scan Request – None (00000000)
No ADC Scan requests made during Init
EPIR_ASC0_DEF 00h ePIR Analog Serial Comm and R egister 0 Default Configuration
for Normal Scan Rate
Bits 7-5 - Reserved (000)
Bit 4 - Buffer Refresh - OFF 0)
Bit 3 - New Sample - Engine Controlled (0)
Bit 2 - MD Origin - Engine Controlled (0)
Bit 1 - EM Noise - Engine Controlled (0)
Bit 0 - EM Transient - Engine Controlled (0)
EPIR_ASC2_DEF 5Ah ePIR Analog Serial Command Register 2 Def aul t C onfiguration
Disables all primary engine functions, including motion
detection. Used to temporarily or permanently shut down
the engine.
Enables the ePIR engine. All primary engine fun ct i ons as
configured in Engine Status/Control Registers ar e enabled.
Confirmation of enabled status is provided through Engine
Disabled bit in Status/Control Register 0.
(R/W) Register used to adjust the sensitivity of the ePIR
Table 26. ePIR API Status/Control Register 0 ( ePIR_SC0)
ZILOG'S PRODUCTS ARE NOT AUTHORIZED FOR USE AS CRITICAL COMPONENTS IN LIFE
SUPPORT DEVICES OR SYSTEMS WITHOUT THE EXPRESS PRIOR WRITTEN APPROVAL OF THE
PRESIDENT AND GENERAL COUNSEL OF ZILOG CORPORATION.
As used herein
Life support devices or systems are devices which (a) are intended for surgical implant into the body, or (b)
support or sustain life and whose failure to perfo rm when proper ly used in accordan ce with instru ction s for us e
provided in the labeling can be reasonably expected to result in a significant injury to the user. A critical
component is any component in a life support device or system whose failure to perform can be reasonably
expected to cause the failure of the life support dev i ce o r sy st em or to affect its safety or effectiveness.