Presentation is loading. Please wait.

Presentation is loading. Please wait.

Application Case Study Christmas Lights Controller

Similar presentations


Presentation on theme: "Application Case Study Christmas Lights Controller"— Presentation transcript:

1 Application Case Study Christmas Lights Controller
Embedded Systems Programming Application Case Study Christmas Lights Controller (with RC5 Infrared remote control) Requirements analysis Selecting sensors, inputs and outputs I/O ports and interfacing Configuration of internal modules (H/W interrupt, Timers, Power management) 1

2 Richard Anthony December 2010

3 Case study - Requirements analysis
Functional requirements of the Christmas lights control system: Turn on / off LED decorative lights by remote control (TV remote); Adjust brightness of lights by remote control; A signal LED should blink briefly to indicate the remote control command was recognised (the controller may not be compatible, the user may press the wrong button, the batteries may be flat, controller may not be pointed directly at the unit, etc.). Non-functional requirements: Use very low levels of power. 3 Richard Anthony December 2010

4 Case study - Selecting sensors, inputs and outputs
Sensors, and I/O devices for the Christmas lights control system: An RC5 decoder (receiver) is needed to detect the Infrared signal transmitted by a TV remote control. This will need a single digital input pin. (In addition, if the Power-Down low power mode is to be used to conserve battery power, the input must also be able to generate a hardware interrupt to wake the microcontroller). A low-intensity LED is adequate for the signal LED. Requires a single digital output pin Several high-intensity LEDs will form the actual tree lights. Requires a single digital output pin (this will need to be switched via a power transistor because the microcontroller output pin cannot provide enough current. (In addition, to enable adjusting the brightness of the lights, the output pin will have to be one of the timer PWM outputs). 4 Richard Anthony December 2010

5 Case study - I/O ports and interfacing (1)
Interfacing sensors and I/O devices to specific ports (for ATtiny45) Allocate devices that need specific ports or functionality first: 1. The RC5 decoder (receiver) must be able to generate a hardware interrupt to wake the microcontroller. There is only one external interrupt pin that can do this, so this pin must be used: INT0, Port B bit 2 2. The high-intensity LEDs must be connected to a PWM output so that their brightness can be changed. The ATtiny45 has two timers (0 and 1) and each has two independent PWM outputs. Timer 1 will be used to control the brightness so the PWM output OC1A will be used: OC1A, Port B bit 1 3. The signal LED can be connected to any digital output pin. Uses: Port B bit 0 5 Richard Anthony December 2010

6 Case study - I/O ports and interfacing – ATtiny45 version
This is the actual microcontroller used in the built system. The ATtiny45 is an 8-pin device, has only one port (port B) with only 6 I/O pins: 6 digital input / outputs, 4 ADC inputs, 2-input analogue comparator, external interrupt pin, serial communications, 2 programmable timers (each can produce PWM outputs), and power-management. Port-pin assignment ATtiny45 RC5 IR receiver, INT0 port B bit 2 LED Lighting Timer1 PWM port B bit 1 Signal LED port B bit 0 6 Richard Anthony December 2010

7 Case study - I/O ports and interfacing - ATmega8535 Equivalent
Signal LED RC5 decoder LED Lights (PWM) 7 Richard Anthony December 2010

8 Richard Anthony ATmega1281 ATmega1281 Port mapping

9 Case study - I/O ports and interfacing – ATmega1281 Equivalent
Richard Anthony ATmega1281 Case study - I/O ports and interfacing – ATmega1281 Equivalent Signal LED RC5 decoder LED Lights (PWM)

10 ATmega2560 Port mapping ATmega2560 Richard Anthony

11 Case study - I/O ports and interfacing – ATmega2560 Equivalent
Signal LED LED Lights (PWM) RC5 decoder Richard Anthony

12 RC5 IR Receiver (TSOP4838) – technical documentation from datasheet
Picture of device showing pin connections Pin 1 is demodulated data output and can be connected directly to a microcontroller port pin. Pin 2 is Gnd Pin 3 is +Ve supply (rated +4.5 to +5.5 volts, tested working Ok down to 3.4V) 1 2 3 Block diagram showing main functional components: - Automatic gain controlled amplifier - Band pass filter to cut out noise - Demodulator to remover the 38KHz modulation carrier wave - Output driver transistor which enables direct driving of a microcontroller port pin (data rate of 4K b/S) Generic circuit diagram for connection to a microcontroller. Richard Anthony December 2010

13 The RC5 receiver photodiode
Christmas lights control system: Full Circuit Diagram +4.5V 0V The RC5 receiver photodiode IR transmitter (e.g. TV remote control) PB2 INT0 Pin7 +Vcc Green SIGNAL LED 330 Ω PB0 Pin5 PB1 PWM Pin6 1.5KΩ lights + 2200µF Cap (because of combination of specific Colour-cycle LEDs and the use of PWM. Capacitor converts the pulse to a smoothed voltage) 22µF Cap (Smooths short-term voltage drops across ATMEL, e.g. when LEDs initially turned on full brightness) 1A fuse Richard Anthony December 2010

14 Flow chart – Christmas lights control system
Main Timer0 ISR (RC5 bit clocking) Bit received Stop Start (bit-time expired) enables (detect Pulse) Start Timer 0 Configure H/W INT2 Process code bit Entire code received ? Yes Configure Timer1 (PWM) Next code bit ready No Apply RC5 command (on / off / change brightness, via PWM) updates Configure Timer0 Decode and interpret received RC5 code INT2 ISR (detect RC5 code pulses) 14 Richard Anthony

15 Case study - Timing diagram - Representing related timing aspects
Timer0 Interrupt handler Data pattern (detected) Light Signal present Case study - Timing diagram - Representing related timing aspects Interrupt 2 detect signal Receive_RC5 function active Code repeats automatically while Tx button pressed Timer runs continuously Command code interpreted at application level (Turn lights on/off, or adjust Timer1PWM) Time Relationship Key: Cause Effect Not to Scale When all bits (14) received Richard Anthony

16 Case study - Configuration of internal modules (outline details)
Hardware Interrupt – used to wake-up the microcontroller from sleep. Configured to detect low-level initially because clocks are disabled in the Power-Down sleep mode (need clock running to detect a rising or falling edge). After device has woken up, reconfigure the hardware interrupt to rising-edge sensitive to be able to recognise the start of an RC5 data code. Timers – one needed to clock-in the RC5 code, the other used for PWM. Timer 0 (8bit) used in the RC5 data receiver protocol (to determine the start and end of each data bit that makes up the RC5 code). Timer 1 (8bit on Attiny45) used to generate the Pulse-Width-Modulation signal which controls the brightness of the LED lights. Power Management – needed because the system is battery powered and may be ‘off’ for long periods of time. The system must use the least possible amount of power – Power-Down Mode. The system is woken by a hardware interrupt (INT0) Not-needed parts (ADC, Analogue comparator, USI – Universal Serial Interface) are turned off to further minimise power use. Richard Anthony December 2010

17 Case study – RC5 command map RC5 command Application Command mapping
# Turn on PWM output to LEDs (initially 1% duty cycle ) 1 LED brightness = 1% duty cycle (lowest brightness) 2 LED brightness = 2% duty cycle 3 LED brightness = 4% duty cycle 4 LED brightness = 8% duty cycle 5 LED brightness = 15% duty cycle 6 LED brightness = 30% duty cycle 7 LED brightness = 50% duty cycle 8 LED brightness = 70% duty cycle 9 LED brightness = 90% duty cycle (highest brightness) CHAN_DOWN Turn off PWM output to LEDs (LEDS off, Unit enters power-down sleep mode) VOL_DOWN Turn off PWM output to LEDs Richard Anthony December 2010

18 Output to decorative lights
Christmas lights control system: External view RC5 decoder Signal LED Output to decorative lights Richard Anthony December 2010

19 Christmas lights control system: Internal View
Richard Anthony December 2010

20


Download ppt "Application Case Study Christmas Lights Controller"

Similar presentations


Ads by Google