Download TIIC2015- Motion Controlled Lamp - TI E2E Community

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Josiah Jackson
Final Project Report
Embedded Systems
5/5/15
Introduction
This project served as the final project for the embedded systems course and was required
to contain multiple aspects of the topics covered in class as well as other courses. The project
also included aspects of design, implementation of that design, and presentation or reporting. In
short, the designed project functioned as a motion-controlled light switch. Using different
components such as a PIR sensor and the MSP430G2553 a 3-stage system was designed to
control a simple circuit that powered a light.
Methods
To start, an initial design was decided upon for a motion-controlled light. While some
aspects of the initial design were changed, the basic design remained intact. The initial design
was for a system that was controlled by the MSP430, detected motion with a PIR sensor, and
powered a light via an N-channel MOSFET. The final parts list is shown below, the sources and
specifications of the parts are included in Appendix 1:
1.
2.
3.
4.
5.
6.
7.
System Control: MSP430G2553
Software: Code Composer Studio v5.5.0
Motion Detection: Pyroelectric/Passive Infrared (PIR) Sensor
Switch: N-Channel MOSFET
Light: 12V Car Utility Lamp
Power: AC/DC 12V 1.5A Adapter
Miscellaneous: Breadboard, wires, alligator clips, 2kΩ resistor
Additionally, the CCS code used to program the MSP430 is included in Appendix 2. The basic
system diagram is shown below in Figure 1.
Figure 1: Overall System Diagram
As seen in the Figure, the hardware setup for the system was rather simple. The power for
the whole system excluding the MSP430 was supplied by a 12V DC adapter that was connected
to a 120V AC wall outlet. The PIR sensor as well as the 12V lamp were both powered by this
single source. Practically, whenever the PIR sensor detected motion it sent a 3V signal to the
MSP430. Based on what state the system was currently in, the MSP430 would send a signal to
the MOSFET which allowed power to flow to the light. The 2kΩ resistor served as a drain for a
possible floating output PIN from the MSP430.
For the software, as shown in Appendix 2, the system used a 3-state program. Using the
input from the PIR sensor as well as the pushbutton on the MSP430, the light was controlled by
an output signal to the MOSFET. The state transition diagram is shown in Figure 2.
Figure 2: Software State Transition Diagram
Initially, the signal from the PIR sensor was LOW at 0V. Once motion was detected the
signal went HIGH to 3V and using the ADC module the MSP430 would then detect this HIGH
signal. The system started in State 1, and once motion was detected the lamp was turned ON and
the system moved to State 2. While in State 2, the lamp would remain ON regardless of whether
motion was detected or not. Once the pushbutton of the MSP430 was pressed then the light
would turn OFF and remain so regardless of motion. If the button was again pressed, the system
would delay for a certain amount of time and then return to State 1, where the entire process
would begin again with the system waiting to detect motion.
Results
As a whole, the final design worked very well with virtually no problems. Table 1 shows
the aspects included in the project and the result of implementing each one.
Table 1: Results of Different Project Aspects
Planned Aspect
Completed?
Difficulties
MSP430 System Control
Yes
None
PIR Sensor
Yes
Only semi-reliable
Light
Revised, Yes
None
Power Switching via
MOSFET
Power
Yes
None
Partially, Yes
Powering MSP430
As shown in the Table, the MSP430 control and MOSFET switch all worked correctly
with no problems. The PIR sensor on the other hand, seemed to work with a varying degree of
reliability. Whether this is due to a software error or a hardware error is unknown, but overall the
PIR sensor works as intended. The implementation of a light went through a revision after more
research was done about powering the entire system. The original project proposal included the
use of a lamp that ran off of 120V AC power. However, after some research it was found that it
would be much easier to convert the power of the entire system to DC including the light. This
removed the process of controlling the AC power with a DC control system. Additionally, it was
proposed that the MSP430 would also run off of the power from the 12V DC supply, but this
was not implemented due to time constraints and requiring a decent amount of light to be given
off by the lamp.
Because of the simplicity of the design it would also be rather simple to use it in a real
world application. For instance, as the person entered a room the light would turn on. The light
would stay on until the user turned it off, at which point it wouldn’t be set off by random
movement inside the room. If the user wanted to reset the system and leave the room, the delay
would allow them to leave the room and the light would stay off until they reentered the room.
There is also the possibility of extending this design to other application, such as a speaker
playing a greeting to a person entering a room or designing an alarm system.
Appendix 3 includes two figures of the design, the components together as a whole and a
picture of the circuit.
Conclusion
This project, while seemingly simple, allowed for a broad experience in building a
system from the ground up. The use of a specific plan and process, implementation of that plan,
revising where needed, and final product made this project as a whole very educational. The
integration of embedded systems with physical circuit design was also interesting and enjoyable.
In the end, some things that were learned from the project were as such:





The earlier that the project is started the better. Not only does this allow time to debug
certain problems or add new optional features, it also greatly decreases the amount of
stress.
Thorough research is rarely a waste. Understanding the aspects of the project, the
components, and the best way to accomplish goals is important.
Start the implementation of the design in small parts. Working with smaller, simple,
systems allows for easier debugging and makes the transition from multiple parts to final
product much smoother.
There are many places to find components, online, in stores, and otherwise. However,
make sure that the parts will actually function with the design before making large
purchases.
Being flexible is important. Sometimes it is better to switch to a simpler design rather
than continue to work on a design that is more complicated for a very long amount of
time.
Appendix 1: Parts List with Sources
1. MSP430G2553 Launchpad, from Texas Instruments:
http://www.ti.com/ww/en/launchpad/launchpads-msp430-msp-exp430g2.html
2. Code Composer Studio, from Texas Instruments: http://www.ti.com/tool/CcStudio
3. PIR Sensor, from Adafruit: http://www.adafruit.com/products/189?gclid=CK3tt_yqcUCFZJffgodHAIA3Q
4. CSD18502KCS N-Channel Power MOSFET, from Texas Instruments:
http://www.ti.com/product/csd18502kcs
5. 12V DC Car Utility Lamp, Produced by Blazer International: Purchased at Walmart
6. 12V 1.5A AC/DC Adapter, from Sunfone: Purchased with a HITACHI external HDD,
but available for purchase online, http://poweradapter.co/sunfone-acw018a312u-acadapter-12v-15a-class-2-transformer-p-2481.html
7. Breadboard, wires, alligator clips, resistors, and all miscellaneous parts provided by Dr.
Timothy Gilmour or John Brown University.
Project was completed at John Brown University using Texas Instruments parts.
Appendix 2
#include <msp430.h>
#define LED BIT0
#define INPUT BIT1
#define OUTPUT BIT2
#define BUTTON BIT3
#define G_LED BIT6
//Red LED used to indicate when PIR signal is HIGH
//Input from PIR Sensor
//Output to MOSFET
//Pushbutton used to change states
//Green LED indicates when the delay is cycling
volatile int state = 1, count = 0;
//state: 1 = waiting for movement
//2 = OFF
//3 = Delay, then change state to 1
void delay_function(int half_seconds);
int main(void)
{
WDTCTL = WDTPW + WDTHOLD;
// Stop WDT
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;
__enable_interrupt();
// Enable interrupts.
TA0CCR0 = 30;
// Delay to allow Ref to settle
TA0CCTL0 |= CCIE;
// Compare-mode interrupt.
TA0CTL = TASSEL_2 | MC_1;
// TACLK = SMCLK, Up mode.
LPM0;
// Wait for delay.
TACCTL0 &= ~CCIE;
// Disable timer Interrupt
__disable_interrupt();
ADC10CTL1 = INCH_1;
// input A1
ADC10AE0 |= INPUT;
// PA.1 ADC option select
P1DIR |= LED + G_LED + OUTPUT;
P1REN = BUTTON;
P1OUT = BUTTON;
P1IE = BUTTON;
P1IES = BUTTON;
P1IFG &= ~BUTTON;
__enable_interrupt();
while(1)
{
ADC10CTL0 |= ENC + ADC10SC;
// Sampling and conversion start
__bis_SR_register(CPUOFF + GIE);
// LPM0, ADC10_ISR will force exit
if (ADC10MEM < 0x100)
// if PIR signal is LOW...
{
P1OUT &= ~LED;
}
else
{
P1OUT |= LED;
if(state == 1)
// if State = 1
{
P1OUT |= OUTPUT; // turn lamp ON
state = 2;
// move to State 2
}
}
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF);
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer0_A0(void)
{
TA0CTL = 0;
LPM0_EXIT;
}
// Clear CPUOFF bit from 0(SR)
// Exit LPM0 on return
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
__delay_cycles(10000);
// Debounce
//if State = 3, delay and change to State
if (((P1IN & BUTTON) == 0x00) && state ==
{
state = 1;
P1OUT |= G_LED;
delay_function(10);
P1OUT &= ~G_LED;
}
//if State = 2, turn Lamp OFF and move to
if (((P1IN & BUTTON) == 0x00) && state ==
{
state = 3;
P1OUT &= ~OUTPUT;
}
P1IFG = 0x00;
}
delay
= 1
3)
State = 3
2)
// delay for State = 3
void delay_function(int half_seconds)
{
unsigned int index;
for(index=0; index < 10*half_seconds; index++)
__delay_cycles(50000);
}
Appendix 3
Figure 3: Design with All Components
Figure 4: Top View of Circuit Layout