THE WAKE UP CHANNEL
Go to bottomPage: 12
TOPIC:
#896
direction of motion 1 Year, 6 Months ago Karma: 0
Hello,
looking for bit of guidance (after i got lost in zmotions product specs and refdesigns)
Unpacked my ZMOTION INTRUSION DETECTION devkit and got quickly thru the setup.
I just wonder how to get the detection of movement DIRECTION going.
Shall i work through Encore (with which i am not familiar with) or is there a faster way?
Looking forward to get a helping hand,
Jacob
jd (User)
Fresh Boarder
Posts: 6
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#897
Re:direction of motion 1 Year, 6 Months ago Karma: 4
Hello Jacob
To get the Motion Direction working, you need to set the Motion Direction Control bit (bit 3 of the EPIR_SC0) and read the Motion Direction (bit 2 of the EPIR_SC0) for the direction. If the bit is set (1) then is it positive (one direction), if the bit is cleared (0), then it is negative (opposite direction). The product spec PS0285, Page 23-25 gives the details.

So assuming you are using the sample application that comes with the ZMotion, you could change the following:

Code:


In the API_INIT_04.h file, change:
#define EPIR_SCO_DEF 0x40
// change (to turn on the motion direction control) to:
#define EPIR_SCO_DEF 0x048

In the main() function where it was:
if (ePIR_SC0 & SC0_MOTION_DETECTED)
{
     if(gTimeout == 0)  //transition!
     {
// You could add the following to handle direction:
           if (ePIR_SCO & SC0_MOTION_DIRECTION)
           {
               //direction one (such as left or top)
            }
            else
            {
               //direction opposite (such as right or bottom)
             }




Note:
The directional polarity of PIR sensors is arbitrary at the time of manufacturing. Therefore it is necessary for the user application to calibrate to each individual PIR sensor using a controlled target (i.e. moving in a known direction) and internally record the polarity to identify which polarity represents that direction
Tom Ormiston (Admin)
Admin
Posts: 168
graph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#901
Re:direction of motion 1 Year, 5 Months ago Karma: 0
Thanks, still some questions:
Should i see the motion bit status via hyperterminal (UART)?
Where to watch this bit?
Or is this a pin on the board that goes high/low?
I changed the code as you said, build says ok, but could not find where to check the bit.
Anyway: my API_INIT is not 04 but 09.h
And in the main function I could not find the code you refer to.
This is the copy
// ePIR_SC0 Default Configuration for Normal Scan Rate //////////////////////////////////////////////////////////////////////////
// Bit 6-7 - Extended Detction - Level 0 (00)
// Bit 5 - Engine Disabled - Engine Controlled (0)
// Bit 4 - MD Suspend - OFF (0)
// Bit 3 - Motion Direction Control - OFF (1)
// Bit 2 - Motion Direction - Engine Controlled (0)
// Bit 1 - Motion Detected - Engine Controlled (0)
// Bit 0 - PIR Stable - Engine Controlled (0)
#define EPIR_SC0_DEF 0x48

Looking forward to hear you,
Thanks again,
Jacob
jd (User)
Fresh Boarder
Posts: 6
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#902
Re:direction of motion 1 Year, 5 Months ago Karma: 4
Hi Jacob
Thank you for the information. It appears you are using the Intrusion sample apps.
Here are the modifications to show the direction on the console.

Modifications:

Under Application Variable Declarations
Add the following line:

Code:


unsigned char cDirection; //Motion detection direction




In main() function, Find the code (close to the end):

Code:


TxQueue(' ');
TxCharAsDecimal(TxMotionCount); // Send out the count of detections
TxString(" @ ");
TxIntAsDecimal(TxSecondCount); // Send out the time stamp




Insert the following:

Code:



TxString(" D: ");
TxCharAsDecimal(cDirection);




In the interrupt isrTimer0() function,
Find the code:

Code:


///////////////////////////////////////////////////////////
// Check for motion detected and update the output as needed
///////////////////////////////////////////////////////////
else if((ePIR_SC0 & SC0_MOTION_DETECTED) && !cMDCheck) // If the engine indicates a motion event
{
LED_ON; // Turn on the LED Output port (turned off in T0 int)




Add the following code:
Code:


    cDirection = ((ePIR_SCO & SC0_MOTION_DIRECTION) ? 1 : 0);




When the application runs, you should now see a direction indicator (D:)

Let me know how it goes.
Tom Ormiston (Admin)
Admin
Posts: 168
graph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#907
Re:direction of motion 1 Year, 5 Months ago Karma: 0
Dear Tom,
build says ok, but nothing visible happens in the terminal (only the usual M 00x @ xx)
Maybe i inserted the cDirection code on the wrong place, as i could not find the code you refer to as: (else if((ePIR_SC0 & SC0_MOTION_DETECTED) && !cMDCheck) // If the engine indicates a motion event{LED_ON; // Turn on the LED Output port (turned off in T0 int)
it is not in my file so i tried an insertion as follows:

///////////////////////////////////////////////////////////
//Interrupt routine for Timer 0 End of Count (50ms)
///////////////////////////////////////////////////////////
void interrupt isrTimer0(void)
{
if(cMDDelay > 0) // If the LED is still activated
{
cMDDelay--; // Decrement the LED activation time
if(cMDDelay == 0) // If the LED activation time has expired
{
LED_OFF; // Turn off the LED Output port
ePIR_SC0 &= ~SC0_MOTION_DETECTED; // Clear engine Motion detected flag
}
}
if(cMDCheck > 0) // When it hits 0, we check the MD bit in the main loop
{
cMDCheck--; // Decrement the MD check counter
cDirection = ((ePIR_SCO & SC0_MOTION_DIRECTION) ? 1 : 0);

#if (VERBOSE == 1)
ePIR_ASC0 &= ~ASC0_TRANSIENT_DETECTED;
ePIR_ASC0 &= ~ASC0_NOISE_DETECTED;
#endif
}
c50mSecond++;
jd (User)
Fresh Boarder
Posts: 6
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#908
Re:direction of motion 1 Year, 5 Months ago Karma: 4

Jacob
The line is in the wrong place.
Here is the entire ISR routine from the demo with the new line added:


Code:


///////////////////////////////////////////////////////////
//Interrupt routine for Timer 0 End of Count (50ms)
///////////////////////////////////////////////////////////
void interrupt isrTimer0(void)
{
if(cMDDelay > 0) // If the LED is still activated
{
cMDDelay--; // Decrement the LED activation time
if(cMDDelay == 0) // If the LED activation time has expired
{
LED_OFF; // Turn off the LED Output port
ePIR_SC0 &= ~SC0_MOTION_DETECTED; // Clear engine Motion detected flag
}
}
if(cMDCheck > 0) // When it hits 0, we check the MD bit in the main loop
{
cMDCheck--; // Decrement the MD check counter

#if (VERBOSE == 1)
ePIR_ASC0 &= ~ASC0_TRANSIENT_DETECTED;
ePIR_ASC0 &= ~ASC0_NOISE_DETECTED;
#endif
}
c50mSecond++; // Increment the 50 ms counter
//1 second tick area
if (c50mSecond >= DELAY_1SEC) // If we have reached one second...
{
c50mSecond = 0; // Reset the 50 ms counter
c1Second++; // Increment the one second counter
cSecondCount++; // Increment the continuous 1 second counter
ePIR_SC1 |= SC1_ENGINE_TIMER_TICK; // Pass the one second tick to the ePIR engine

#if (VERBOSE == 1)
if(SysStatus1 & PIR_STABLE)
{
if(ePIR_ASC0 & ASC0_WHITE_LIGHT_DETECTED)
{
ePIR_ASC0 &= ~ASC0_WHITE_LIGHT_DETECTED;
SysStatus1 |= WHITE_LIGHT_EVENT;
}
if(ePIR_ASC0 & ASC0_TRANSIENT_DETECTED)
{
ePIR_ASC0 &= ~ASC0_TRANSIENT_DETECTED;
SysStatus1 |= TRANSIENT_EVENT;
}
if(ePIR_ASC0 & ASC0_NOISE_DETECTED)
{
ePIR_ASC0 &= ~ASC0_NOISE_DETECTED;
SysStatus1 |= NOISE_EVENT;
}
}
#endif
// 1 minute tick area
if (c1Second >= 60) // If we have reached one minute...
{
c1Second = 0; // Clear the one second counter
}
}
///////////////////////////////////////////////////////////
// Check for PIR sensor stability after power up
///////////////////////////////////////////////////////////
if(!(SysStatus1 & PIR_STABLE))
{
if(!(SysStatus1 & PIR_PRE_STABLE)) // If we have not seen engine stability after power up...
{
if (ePIR_SC0 & SC0_PIR_STABLE) // If the PIR sensor has become stable...
{
SysStatus1 |= PIR_PRE_STABLE; // Indicate that the system has stabilized after powerup
cMDCheck = DELAY_5SEC; // Add some extra time to pyro stablization - just to be sure
}
}
else
{
if(cMDCheck == 0)
{
SysStatus1 |= PIR_STABLE; // Indicate that the system has stabilized after powerup
LED_OFF; // Turn off LED to show we are ready

// Set up the White Light detection registers and enable (Defines are in main.h)
ePIR_ASC0 |= WHITE_LIGHT_ANTI_JAM_DEF << 5; // Configure White Light Anti-Jam
ePIR_ASC1 = WHITE_LIGHT_SCAN_RATE_DEF + (WHITE_LIGHT_DEBOUNCE_DEF << 4);
ePIR_SC2 += (WHITE_LIGHT_THRESH_DEF << 3); // Set up the white light detection threshold and enable

#if (VERBOSE == 1)
// Clear out any status from before the pyro was stable
ePIR_ASC0 &= ~ASC0_WHITE_LIGHT_DETECTED;
ePIR_ASC0 &= ~ASC0_TRANSIENT_DETECTED;
ePIR_ASC0 &= ~ASC0_NOISE_DETECTED;
SysStatus1 &= ~(TRANSIENT_EVENT + NOISE_EVENT + WHITE_LIGHT_EVENT);
#endif
SysStatus1 |= SEND_STABLE; // Send the "Stable" message from main
}
}
}

///////////////////////////////////////////////////////////
// Check for motion detected and update the output as needed
///////////////////////////////////////////////////////////
else if((ePIR_SC0 & SC0_MOTION_DETECTED) && !cMDCheck) // If the engine indicates a motion event
{
LED_ON; // Turn on the LED Output port (turned off in T0 int)
cMDDelay = cMDDelayTime; // Initiate LED ON time
cMDCheck = DELAY_1SEC; // Wait 1 second before checking for motion again (allows Engine to re-stablize)

cDirection = ((ePIR_SCO & SC0_MOTION_DIRECTION) ? 1 : 0); //New line to get direction of movement

if(ePIR_ASC0 & ASC0_MD_ORIGIN) // Which Engine reported the motion event?
{
SysStatus1 |= TX_EXTENDED; // Set Extended flag if motion was sensed by Extended Detector
cEDCount++; // Increment the Extended Detection counts
TxMotionCount = cEDCount; // Set the Extended Detection Counts to be transmitted in main()
}
else
{
SysStatus1 |= TX_NORMAL; // Set Normal flag if motion was sensed by Extended Detector
cMDCount++; // Increment the Normal Detection counts
TxMotionCount = cMDCount; // Set the Normal Detection Counts to be transmitted in main()
}
TxSecondCount = cSecondCount; // Save the time stamp - transmitted in main()
}
}





Just in case, here is the entire main() application loop with the new line added:


Code:


///////////////////////////////////////////////////////////
// This is the main application loop - we never exit
///////////////////////////////////////////////////////////
while(1)
{
Z8_WDT; // Kick the watchdog
Z8_HALT; // Halt to conserve power. ADC and T0 Interrupt pull CPU out of Halt
// Is there anything to do?
if(SysStatus1 & (WHITE_LIGHT_EVENT | TRANSIENT_EVENT | NOISE_EVENT | SEND_STABLE | TX_EXTENDED | TX_NORMAL))
{
#if (VERBOSE == 1)
if(SysStatus1 & WHITE_LIGHT_EVENT)
{
TxQueue('W');
SysStatus1 &= ~WHITE_LIGHT_EVENT;
}
if(SysStatus1 & TRANSIENT_EVENT)
{
TxQueue('T');
SysStatus1 &= ~TRANSIENT_EVENT;
}
if(SysStatus1 & NOISE_EVENT)
{
TxQueue('N');
SysStatus1 &= ~NOISE_EVENT;
}
#endif
if(SysStatus1 & SEND_STABLE)
{
TxQueue('S'); // Send out 'S' to indicate we are stable
TxCRLF();
SysStatus1 &= ~SEND_STABLE;
}
// The T0 interrupt sets TX_EXTENDED or TX_NORMAL when a motion event is detected
// We send out a message with a count of events and a time stamp
if(SysStatus1 & (TX_EXTENDED | TX_NORMAL))
{
if(SysStatus1 & TX_EXTENDED)
{
SysStatus1 &= ~TX_EXTENDED;
TxQueue('E'); // Send an 'E' if motion was sensed by Extended Detector
}
else
{
SysStatus1 &= ~TX_NORMAL;
TxQueue('M'); // Send an 'M' if motion was sensed by Normal Detector
}
TxQueue(' ');
TxCharAsDecimal(TxMotionCount); // Send out the count of detections
TxString(" @ ");
TxIntAsDecimal(TxSecondCount); // Send out the time stamp
TxString(" D: ");
TxCharAsDecimal(cDirection); 
TxCRLF();
}
}
} // End of main application loop





It looks like your modification of your headfile is correct:

EPIR_SC0_DEF 0x48

Let me know if this helps.
Tom Ormiston
Tom Ormiston (Admin)
Admin
Posts: 168
graph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
Go to topPage: 12