Presentation is loading. Please wait.

Presentation is loading. Please wait.

Application Case Study Security Camera Controller

Similar presentations


Presentation on theme: "Application Case Study Security Camera Controller"— Presentation transcript:

1 Application Case Study Security Camera Controller
Embedded Systems Programming Application Case Study Security Camera Controller (with automatic pan to pre-set zones of interest triggered by movement sensors) Requirements analysis Selecting sensors, inputs and outputs I/O ports and interfacing Timing diagrams Configuration of internal modules (timer, ADC)

2 The automatic pan concept
Zone #1 Zone #3 Camera pivot and servo for rotation Camera Zone #2 Field of view The automatic pan concept (zones are equipped with localised movement sensors) Initial situation (camera facing zone #2) Movement detected in zone #1, camera is rotated to pre-set angle facing zone #1 Zone #2 Rotation Richard Anthony

3 Case study - Requirements analysis
Functional requirements of the Security Camera Controller: Detect movement in a number of specific zones. Sense light level and differentiate between day and night-time. Turn camera power on when movement detected. Turn camera servo power on when movement detected. Turn security light on when movement detected at night-time. Automatically pan camera to point at zone where movement detected. Turn camera servo power off when camera pan rotation completed. Turn camera power off when no movement detected for 5 minutes. Turn security light off when no movement detected for 5 minutes. Communicate with other components of a security system via a ZigBee network (this aspect only described in outline). Provide simple power and operational status indication via single LED. Non-functional requirements: Use low levels of power. Casing must be adequate for harsh environment (full weather exposure to some parts, large variation in temperatures and humidity). Mechanical robustness and smooth rotational movement of camera. 3 Richard Anthony

4 Case study - Selecting sensors, inputs and outputs
Sensors, and I/O devices for the Security Camera Controller : PIR sensors to detect movement in zones. Requires single digital input pin with interrupt capability per PIR sensor (up to 5 sensors to be supported). A light sensitive device such as a Photodiode or Light Dependent Resistor (LDR) is needed to sense the light level. Requires single analogue input pin (and the Analogue-to-Digital converter). The camera pan movement requires a servo, which is controlled by a single PWM output (and a programmable timer). The servo power, camera power and spotlight power require transistors driven each by a single digital IO pin (3 of). In addition, because the spotlight is mains-powered, it requires that the transistor drives a relay. The alarm sounder requires a single digital IO pin. A low-intensity LED is adequate for the signal LED. It requires a single digital output pin. The ZigBee network module requires a serial port USART (Rx and Tx pins). It also requires three handshaking signals; 2 digital outputs and 1 digital input. The camera is a separate component which sends signals via a separate wireless link (not part of the controller’s logic or function). 4 Richard Anthony

5 Case study - I/O ports and interfacing (1)
Interfacing sensors and I/O devices to specific ports (for ATmega328), ordered in terms of most specific requirements first. The ZigBee module’s serial interface is connected to Port D bits 0 and 1 which provide the USART Rx and Tx functions respectively. The Light Dependent Resistor must be connected to the Analogue-to-Digital converter, Port C bit 0 (ADC0) is used. The servo is connected to Port B bit 3 which provides the OC2A output from Timer2. The PIR sensors are connected to separate digital input bits on Port D bits 2-6 inclusive, sharing the PCINT2 pin-change interrupt. The servo power, camera power and spotlight power control outputs are connected to Port C digital output bits 1, 2, 3 respectively. The alarm sounder is connected to digital output Port D bit 7. The ZigBee module’s handshaking signals are connected to Port B digital IO bits 0, 1 and 2. The signal LED is connected to digital output Port B bit 7. The camera data stream has its own wireless link and is not interfaced to the microcontroller. 5 Richard Anthony

6 Case study - I/O ports and interfacing (2) – ATmega328p
ZigBee Comms Spotlight power PIR 1 Camera pwr PIR 2 Servo pwr PIR 3 Light sensor Signal LED PIR 4 PIR 5 Camera servo (PWM) Alarm sounder ZigBee module handshaking Richard Anthony

7 Case study - I/O ports and interfacing – ATmega1281 Equivalent
Richard Anthony ATmega1281 Case study - I/O ports and interfacing – ATmega1281 Equivalent Light sensor ZigBee Comms Camera servo (PWM) Alarm sounder Spotlight power PIR 1 PIR 2 PIR 3 Camera pwr PIR 4 PIR 5 Servo power Signal LED ZigBee module handshaking Richard Anthony

8 Case study - I/O ports and interfacing – ATmega2560 Equivalent
Light sensor ATmega2560 ZigBee comms Camera servo (PWM) Alarm sounder PIR 1 PIR 5 Spotlight power Camera power Servo power Signal LED ZigBee module handshaking Richard Anthony Richard Anthony

9 Flow chart (1) Main Start Wait Configure Timer1 (1 second clock)
Turn sounder Off Configure Timer2 (PWM for servo) Configure PCINT interrupt (movement sensors) Turn camera Off Turn servo power Off Turn spotlight Off Configure ADC (Sample light level) Stop SpotlightOn Off period completed ? Yes No LightLevel == Light Turn Spotlight on On period completed ? Yes No Turn Spotlight off SpotlightOff Stop ActivateSounder Set sounder On duration Turn sounder On Stop 9 Richard Anthony

10 Signal LED pulse interval reached
Flow chart (2) Timer1 ISR Start (1-second clock interval) Yes No Pulse signal LED Signal LED pulse interval reached ? LED_FlashIntervalRemaining -- Sounder OffTime > 0 OnTime > 0 SounderOffTime -- SounderOnTime -- Turn sounder Off Camera CameraOnTime -- Turn camera Off Call SpotlightOff Spotlight SpotlightOffTime -- SpotlightOnTime -- Start ADC conversion Stop 10 Richard Anthony

11 Flow chart (3) PCINT ISR Sensor #1 pin high ? Yes No
(Motion sensors) Sensor #1 pin high ? Yes No Set PWM value to point camera to zone #1 Start (an input pin changed value) Set PWM value to point camera to zone #2 Sensor #3 Set PWM value to point camera to zone #3 Stop Turn camera On Sensor #2 Call SpotlightOn Call ActivateSounder Turn servo power On LightLevel = Dark Start (conversion complete) ADC ISR LightLevel > threshold ? Yes No = Light Stop 11 Richard Anthony

12 Timing diagram 1 1-second clock and light-level sampling
ADC conversion complete (momentary state) Ambient light level (as detected) ADC interrupt handler Timer1 (1-second clock) Start ADC conversion ADC conversion time Light Dark 1 second 12 Richard Anthony

13 Timing diagram 2 Movement sensors and camera positioning
PCINT ISR Zone #1 Zone #2 Zone #3 Camera target position Richard Anthony

14 Timing diagram 3 Actuator control logic
Camera Rotating (worst case) Timing diagram Actuator control logic Camera power Sounder Servo power Zone #1 Zone #2 Zone #3 Camera target position Ambient light level Light Dark Spotlight Richard Anthony

15 Case study - Configuration of internal module – Timer1
Timer1 is used to provide a 1-second clock pulse which is used to count-down a number of application-level time-periods (i.e. one hardware clock is used to govern multiple separate software-managed time intervals). The application-level time periods include the Signal LED pulse interval and the timing periods for {camera on-time, spotlight on-time, spotlight off-time, sounder on-time}. Mode of operation – to achieve a timeout after 1 second, channel A is used in CTC mode. Timer1 is ideal for the 1-second clock because it is a 16-bit timer. The largest prescaler is used, i.e This allows the timer to measure an interval of up to 67 seconds approximately with a 1MHz clock. The timer is configured to use interrupts (Compare Match interrupt). 15 Richard Anthony

16 Case study - Configuration of internal module – Timer2
Timer2 generates a PWM pulse to control the rotational position of the camera. Interrupts are not needed for Timer2; the PWM pulse is generated directly on the OC2A pin (Port B bit 3 of the ATmega328). The pulse width is from 500 to 2500 microseconds (the equivalent servo rotational angle is approximately 180 degrees). A 500µS pulse width indicates fully anticlockwise, 1500µS indicates the centre position, and 2500µS indicates fully clockwise. The pulse is repeated at a typical rate of 18mS, as shown in the PWM timing diagram: Interval (I) = 18 mS typical 500µS 2500µS Pulse (P) Equivalent servo position However, Timer2 is an 8-bit timer (16-bit Timer1 is used for the 1-second clock), so the precision of the actual timing signal produced is limited: For a clock speed of 1MHz, and by using the 64 prescaler, the pulse interval (given by the counter overflow) is actually mS (works correctly with the servos tested). The specific prescaler and clock speed combination limits the PWM pulse granularity to 64µS increments (where 2500µS – 500µS = 2000µS pulse width range for 180° movement range, ≡ 11µS per degree). Therefore 64µS ≡ 5.76° movement granularity (which is adequate in this application). Richard Anthony

17 Case study - Configuration of internal module - ADC
Only a single analogue sensor is used; the light-level sensor. Therefore only a single channel of the ADC is used; channel 0. The application design requires that the light level is sampled frequently; once a second is ideal, therefore the ADC conversion is started from within the Timer1 ISR. The ADC unit has a 10-bit precision, but in this application it is only necessary to detect the light-level difference between night-time and daytime, and thus an 8-bit result is adequate. The configuration registers are programmed to provide the most-significant 8-bits in a single data register. The ADC is configured to use interrupts (Conversion Complete interrupt). Richard Anthony

18 Case study - Configuration of internal module – PCINT2 Interrupt
Up to five movement sensors are supported, and it is necessary to detect signals from these via an interrupt mechanism. The ATmega328 only has two dedicated interrupt pins (INT0 and INT1), but pin-change interrupts are supported for every I/O pin, managed separately for each of the three ports (B, C, D). PCINT2 can be used to detect any pin-change on any of the input pins of Port D. The movement sensors are each connected to one of the Port D bits (bits 2-6 inclusive). The PCINT2 interrupt is enabled. When triggered, the PCINT2 ISR code must first determine which sensor has detected movement, by examining all the input bits. The sensors work in active-high mode (and external pull-down resistors are used in the circuit), meaning that all bits are low when no movement is detected. Determining which sensor was activated requires finding which pin has gone high. The ISR must then set the camera servo PWM value appropriately so that the camera rotates to point at the zone where movement was detected. 18 Richard Anthony


Download ppt "Application Case Study Security Camera Controller"

Similar presentations


Ads by Google