Difference between revisions of "S18: M.E.O.W"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Power management functionality in LPC 176x CPU)
(Testing & Technical Challenges)
 
(79 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=== Grading Criteria ===
+
[[File:IMG 3326.jpg|right|720px]]
<font color="green">
 
*  How well is Software & Hardware Design described?
 
*  How well can this report be used to reproduce this project?
 
*  Code Quality
 
*  Overall Report Quality:
 
**  Software Block Diagrams
 
**  Hardware Block Diagrams
 
**:  Schematic Quality
 
**  Quality of technical challenges and solutions adopted.
 
</font>
 
  
 
 
== Microcontroller Energy Observation Widget (M.E.O.W) ==
 
== Microcontroller Energy Observation Widget (M.E.O.W) ==
  
 
== Abstract ==
 
== Abstract ==
This section should be a couple lines to describe what your project does.
+
Our project aims to provide a theft detection service by recording a video when any movement is detected in an immediate vicinity. A video feed is stored on the device to collect later on. The video feed can be used as evidence to provide authority to find the culprit. This report details the system and technology used to implement this project.
  
 
== Objectives & Introduction ==
 
== Objectives & Introduction ==
 
Show list of your objectives.  This section includes the high level details of your project.  You can write about the various sensors or peripherals you used to get your project completed.
 
Show list of your objectives.  This section includes the high level details of your project.  You can write about the various sensors or peripherals you used to get your project completed.
 +
 +
Our primary goal for this project was to learn about the sleep modes that the LPC Microcontoller is capable of. In order to help us understand the functionality of the technology, we wanted to implement the sleep modes on a real life practical example.
 +
 +
Living in the Bay Area, a highly technological society, most tech employees travel with expensive equipment in their cars. Knowing this thieves consider this a prime area to conduct car robberies. Recently there has been an increase in these car robberies, where it can be hard to catch the criminals who have committed the theft. Often times the robbers work so quickly and discretely that a normal bystander might not consider the act suspicious. Additionally if your car is parked in remote area, far away from city cameras, it can be hard gather any evidence to catch the thief. Video surveillance evidence is highly valuable to an investigator assigned on the case.
 +
 +
Our video surveillance device, records footage if a crime is committed in a customers' car. Sensors in our device activate a camera to start recording when movement is detected. In its idle state, the device is in sleep mode where minimal tasks are being run on the device, which means it saves on a lot of power consumption. Alternatively if the device is constantly polling, this would use up an enormous amount of battery power. Since this device is meant to be running in a car that is not running, it is pertinent to use minimal power unless absolutely necessary to maximize the battery life.
 +
 +
This application can be scaled for any environment; your home, backyard, or even for city use. We can connect it every street lamp with some IOT capabilities resulting in lower crime rate across the city.
 +
 +
Objectives:
 +
* Research Power consumption capabilities of micro-controllers.
 +
* Build and implement a video surveillance device to feature the low power methods.
  
 
=== Team Members & Responsibilities ===
 
=== Team Members & Responsibilities ===
 
*  R "Meow Meow" Nikfar
 
*  R "Meow Meow" Nikfar
 
**Team Lead, PCB Design, Sensor Design and Implementation, Hardware Testing, Power Analysis, Sleep-Mode Firmware  
 
**Team Lead, PCB Design, Sensor Design and Implementation, Hardware Testing, Power Analysis, Sleep-Mode Firmware  
*  Ahsan "Whiskers" Uddin
+
[https://www.linkedin.com/in/ahsanu/ Ahsan "Whiskers" Uddin]
 
**BeagleBone Testing, Video Capture Implementation, Storage, Sleep-Mode Research   
 
**BeagleBone Testing, Video Capture Implementation, Storage, Sleep-Mode Research   
*  Nelson "fluffy" Wong
+
*  Nelson "Fluffy" Wong
 
**Deep Power Modes, Power Analysis, Communications   
 
**Deep Power Modes, Power Analysis, Communications   
 
*  Britto "Kitty Kat" Thomas
 
*  Britto "Kitty Kat" Thomas
**CAN BUS Low Power Research, Power Analysis   
+
**CAN BUS Low Power Research, Power Analysis, System Design    
 
*  Sai Kiran "Mittens" Rachamadugu
 
*  Sai Kiran "Mittens" Rachamadugu
 
**Testing, Board Communications, User Interface
 
**Testing, Board Communications, User Interface
  
 
== Schedule ==
 
== Schedule ==
Show a simple table or figures that show your scheduled as planned before you started working on the project.  Then in another table column, write down the actual schedule so that readers can see the planned vs. actual goals.  The point of the schedule is for readers to assess how to pace themselves if they are doing a similar project.
 
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 109: Line 109:
 
|  
 
|  
 
* Prototype of the shell of the project.
 
* Prototype of the shell of the project.
* write and further test implementation of low power modes.
+
* Write and further test implementation of low power modes.
 
|
 
|
* 3d rendering of the prototype done. yet to be printed.
+
* 3D rendering of the prototype done. yet to be printed.
* further research and implementation of power modes done. More research needed.
+
* Further research and implementation of power modes done. More research needed.
 
|-
 
|-
 
! scope="row"| 9
 
! scope="row"| 9
 
| 04/29
 
| 04/29
 
|  
 
|  
 +
* Integrate code with PIR and Low Power functionalities
 
* Rob Went to Napa Valley.
 
* Rob Went to Napa Valley.
  
 
|
 
|
 +
* PIR Integration Complete
 
* Rob drank wine.
 
* Rob drank wine.
 +
 
|-
 
|-
 
! scope="row"| 10
 
! scope="row"| 10
Line 129: Line 132:
 
* Test the power consumption of each  
 
* Test the power consumption of each  
 
|
 
|
 
+
* Camera Successfully records on interrupt.
 +
* Bitcoin has only hit 8000
 +
* Testing Power modes complete
 
|-
 
|-
 
! scope="row"| 11
 
! scope="row"| 11
Line 135: Line 140:
 
|  
 
|  
 
* MEOW @ PREET
 
* MEOW @ PREET
 +
* Finalize Prototyping and print the housing
 +
* Collect Images and Video for documentation
 
|
 
|
 
+
* MEOWing Successful.
 +
* Housing completed.
 +
* Recorded Video and presentation images.
 
|-
 
|-
 
|}
 
|}
  
 
== Parts List & Cost ==
 
== Parts List & Cost ==
Give a simple list of the cost of your project broken down by components.  Do not write long stories here.
+
 
 +
* BeagleBone Black Wireless $55
 +
* Logitech HD PRO WEBCAM C920 $70
 +
* 3 PIR sensors $45
 +
* 1 SJ One board $80
  
 
== Design & Implementation ==
 
== Design & Implementation ==
The design section can go over your hardware and software design.  Organize this section using sub-sections that go over your design and implementation.
 
  
 
=== Hardware Design ===
 
=== Hardware Design ===
Discuss your hardware design here. Show detailed schematics, and the interface here.
+
 
 +
===== GPIO Pins =====
 +
 
 +
M.E.O.W uses three PIR sensors , each of these sensors are connected to GPIO pins on port 2.3 , 2.4 and 2.5. Any motion detected asserts these pins creating a WIC to wake up the system from sleep.
 +
 
 +
GPIO pin 1.28 is asserted to signal beagle bone to start recording.  
  
 
===== Low-Level Hardware =====
 
===== Low-Level Hardware =====
 +
 +
  
 
The low-level design starts from the PIR Motion Sensors and ends with the storage of the video data. The LPC1758 plays a big role in the communication of the overall system. The PIR sensors are each connected to the LPC1758 using a GPIO protocol and send signals if an object or and person is within their range. Once the signal is sent from the Sensors, the LPC wakes up and consumes power from the PCB which either uses the power from a plugged source or the backup LIPO battery. LPC then sends the right information to the BeagleBone board using UART protocol.
 
The low-level design starts from the PIR Motion Sensors and ends with the storage of the video data. The LPC1758 plays a big role in the communication of the overall system. The PIR sensors are each connected to the LPC1758 using a GPIO protocol and send signals if an object or and person is within their range. Once the signal is sent from the Sensors, the LPC wakes up and consumes power from the PCB which either uses the power from a plugged source or the backup LIPO battery. LPC then sends the right information to the BeagleBone board using UART protocol.
 +
[[File:Meow hardware schematic.JPG|bottom]]
 +
 +
=== Software Design ===
 +
 +
==== freeRTOS Tasks ====
 +
 +
For this project, we use two RTOS tasks, one for asserting GPIO pin needed for beagle bone and the other to put the LPC board to sleep. The PIR task which asserts GPIO pin is given a higher priority compared to the task which puts the LPC board to sleep.
 +
 +
===== Psuedo-code =====
 +
 +
Void PIRTask (void* pvParams){
 +
              while(1){
 +
                  if(xSemaphoreTake(xGetSemfromISR,portMAX_DELAY){
 +
                 
 +
                        // assert GPIO pin to signal beagle bone for recording video
 +
                        LPC_GPIO1->FIOSET = 1 << “pin number”;
 +
                }
 +
        }
 +
  }
 +
 +
Above code allows PIRTask to assert a GPIO pin to signal beagle bone to start recording.
 +
To put the LPC board to sleep a second task with lower priority is run. This task in-turn calls appropriate sleep mode.
 +
Void PutToSleep(void* pvParams){
 +
While(1){
 +
              if(xSemaphoreTake(xGetSemforSleep,portMax_DELAY){
 +
                      //call appropriate sleep function
 +
                        enter_powerdown();
 +
 
 +
              }
 +
        }
 +
  }
 +
Interrupt request handler is created for above tasks which uses xSemaphoreGiveFromISR on interrupt to give a semaphore to the tasks. The code given below shows a pseudo-code for the Interrupt handler.
 +
 +
  void Simple_IRQHandler(){
 +
         
 +
        long yieldRequired = 0;
 +
        xSemaphoreGiveFromISR(xGetSemfromISR, &yieldRequired);
 +
        portYIELD_FROM_ISR(yieldRequired);
 +
 
 +
    }
 +
 +
=== Printed Circuit Board Design ===
 +
 +
 +
In order to stabilize and provide a noise free power supply to all the components of the system, a printed circuit board(PCB) was created. This piece of hardware brings all the power consumption of the unit together. The design and the creation of the board was done in Eagle Schematics Software where the gerber files were created. Once the gerber files were ready, the files were sent to be printed. There were 2 iteratins of this board. The first lacked the necessary connections for the additional components and had several noise reduction flaws. The second board solved all these issues. Note that the final board had to be 1 layer due to the noise reduction characteristics of the material and the ability for placement of the LIPO battery on the bottom of the board.
 +
<BR/>
 +
[[File:Meow Eagle schematic.JPG|bottom]]
 +
 +
[[File:MEOW PCB schematic.JPG|bottom]]
 +
 +
== NXP LPC1700 Series Power Modes ==
  
 
=== Power management functionality in LPC 176x CPU ===
 
=== Power management functionality in LPC 176x CPU ===
  
* There are mainly 4 modes of runtime power savings mode that are available in LPC 176x CPU. They are described in details as follows
+
There are mainly 4 modes of runtime power savings mode that are available in LPC 176x CPU. They are described in details as follows. Measurements were made using an Agilent Infiniium MSO9254A, a N2870A passive probe, and a 1147B current probe. It should be noted that our SJ One board generally runs at 96MHz with 5V input voltage and consumes about 177mA of current which corresponds to '''885mW''' of power.
**Normal sleep
+
 
**Deep sleep
+
====Deep sleep====
**Power Down mode
+
 
**Deep Power mode
+
Upon entering the Deep sleep mode, the main oscillator is powered down and the DSFLAG in PCON is turned on. We observed that the current consumed at this state was 167mA which corresponds to '''835mW''' of power. To wake up from Deep Sleep, an EINT0 was used to resume the CPU. Note that as PLLs are shut off during this sleep, the PLLs are configured once the CPU is resumed from deep sleep.
* How to put to sleep
+
 
**WFE/WFI
+
[[File:Cmpe244_S18_MEOW_Deep_Sleep_Entry02.jpg|bottom|Deep Sleep power saving scopeshot]]
* How to wake up system?
+
 
**Wake up interrupt controller (WIC)
+
====Power Down mode====
**General interrupts
+
 
 +
Upon entering the Power Down mode, like deep sleep the main oscillator is powered down but additionally the flash is also turned off. We observed that the current consumed at this state was '''80mA''' which corresponds to 400mW of power. To wake up from Deep Sleep, an EINT0 was used to resume the CPU. Note that as PLLs are shut off during this sleep, the PLLs are configured once the CPU is resumed from deep sleep.
 +
 
 +
[[File:Cmpe244_S18_MEOW_Power_Down_Entry.jpg|bottom|Power Down power saving scopeshot]]
 +
 
 +
As we learnt in this semester that frequency plays a role in power consumption, and as we know that the default frequency of the LPC board is 96MHz, we tried the same power down sequence wit 8MHz. This time we saw that the current consumption went down to 24mA which corresponds to only '''120mA'''!!! By far, this was the most stable power saving feature we have tested and we implemented this setting in our project.
 +
 
 +
[[File:Cmpe244_S18_MEOW_Power_Down_Entry_with_8MHz clock.jpg|bottom|Power Down @ 8MHz power saving scopeshot]]
 +
 
 +
====Deep Power mode====
 +
 
 +
Upon entering the deep power down mode, the entire chip is powered down except the RTC and the DPDFLAG in PCON is turned on. We observed that the current consumed at this state was 60mA which corresponds to '''300mW''' of power. To wake up from Deep Sleep, there is only one way i.e to set the RESET pin, which replicates very closely to the cold boot process.
 +
 
 +
[[File:Cmpe244_S18_MEOW_Deep_Power_Down_Entry.jpg|bottom|Deep Power Down power saving scopeshot]]
 +
 
 +
====Summary of Power modes====
 +
 
 +
Below is a chart for all the power savings comparisons side by side.
 +
 
 +
[[File:CMPE244_S18_MEOW_PowerComp.JPG|bottom|Power savings comparison chart]]
 +
 
 +
One things that needs to be noted is that although we are manipulating the power states we are still seeing a significant amount of current being drawn constantly. For example we are claiming that in deep power down, the ASIC is switched off but yet we see 60mA of current being drawn. The answer is that is even though the ASIC is switched off, there are other peripherals that are still ON. For example the 7 segment LED. So ideally it would be interesting to see what happens when each and every single peripheral is turned off dynamically in each state and to see the absolute power savings consumption.
 +
 
 +
=== Entering ===
 +
 
 +
Power mode entry is based on tables 44 (Power Mode Control register) and 662 (SCR bit assignments) of UM10360 [1].
 +
 
 +
Please note the following, regarding the interaction between power modes and debugging status. If P2.10/EINT0/NMI is asserted voltage-low, the LPC will boot in debug mode. In debug mode, the LPC will not wake in the same manner. Since we do not program the LPC via JTAG/SWD, this is not a problem for us.
 +
 
 +
void enter_sleep()
 +
{
 +
    LPC_SC->PCON = 0x0; // Table 44
 +
    SCB->SCR    = 0x0; // Table 662
 +
    __WFI();
 +
}
 +
 +
void enter_deep_sleep()
 +
{
 +
    LPC_SC->PCON  = 0x8; // Table 44
 +
    SCB->SCR    |= 0x4; // Table 662
 +
    __WFI();
 +
}
 +
 +
void enter_powerdown()
 +
{
 +
    LPC_SC->PCON  = 0x1; // Table 44
 +
    SCB->SCR    |= 0x4; // Table 662
 +
    __WFI();
 +
}
 +
 +
void enter_deep_powerdown()
 +
{
 +
    LPC_SC->PCON  = 0x3; // Table 44
 +
    SCB->SCR    |= 0x4; // Table 662
 +
    __WFI();
 +
}
 +
 
 +
Note the use of of __WFI(), which the compiler resolves as the assembly directive
 +
__ASM ("wfi");
 +
 
 +
=== Exiting ===
  
=== Hardware Interface ===
+
On exiting a power mode, the associated bit on the Power Mode Control register must be cleared. As noted in the datasheet, bits 8, 9, 10, and 11 are associated to the particular power modes, and these flags are cleared in software by writing "one" to the associated bit.  
In this section, you can describe how your hardware communicates, such as which BUSes used.  You can discuss your driver implementation here, such that the '''Software Design''' section is isolated to talk about high level workings rather than inner working of your project.
 
  
=== Software Design ===
+
void clear_sleep()          { LPC_SC->PCON |= 1 <<  8; };
Show your software design.  For example, if you are designing an MP3 Player, show the tasks that you are using, and what they are doing at a high level. Do not show the details of the code.  For example, do not show exact code, but you may show psuedocode and fragments of code. Keep in mind that you are showing DESIGN of your software, not the inner workings of it.
+
void clear_deep_sleep()    { LPC_SC->PCON |= 1 <<  9; };
 +
void clear_powerdown()      { LPC_SC->PCON |= 1 << 10; };
 +
void clear_deep_powerdown() { LPC_SC->PCON |= 1 << 11; };
 +
 
 +
The PLLs (phase-locked loops) are turned off upon entering deep sleep, power-down, and deep power-down. Additionally, the IRC (the 4 MHz internal reference clock) and the clock dividers are reset when entering power-down and deep power-down. Therefore, the system clocks must be reconfigured/reinitialized when exiting any of these power modes.  
  
=== Implementation ===
+
We can take advantage of sys_clock_configure() from L0_LowLevel/sys_clock.cpp to perform this initialization.
This section includes implementation, but again, not the details, just the high level.  For example, you can list the steps it takes to communicate over a sensor, or the steps needed to write a page of memory onto SPI Flash. You can include sub-sections for each of your component implementation.
 
  
== Testing & Technical Challenges ==
+
One more thing to keep in mind regarding power mode exits: when exiting deep sleep, power-down, and deep power-down, there is a non-zero amount of time that must elapse before the system is able to resume processing. In all three cases, a timer starts counting the moment the power mode is exited, and code execution can resume after this timer expires.
Describe the challenges of your project. What advise would you give yourself or someone else if your project can be started from scratch again?
+
* If the IRC was used prior to entering the power mode, then the 2-bit IRC timer is used, and it lasts is 2<sup>2</sup> = 4 cycles long.
Make a smooth transition to testing section and described what it took to test your project.
+
* If the main external oscillator was used, then the 12-bit main oscillator timer is used, and it lasts 2<sup>12</sup> = 4096 cycles long.
  
Include sub-sections that list out a problem and solution, such as:
+
Moreover, in power-down and deep power-down, the flash undergoes wake-up, and its wake-up timer must expire (approximately 100 µs) before it can be used. This means that no instructions can be fetched from flash for execution until this timer expires.
  
=== <Bug/issue name> ===
+
=== Features Summary ===
Discuss the issue and resolution.
 
  
== NXP LPC1700 Series Power Modes ==
 
 
Below is a tabulation of the features that are enabled or disabled for each power mode.
 
Below is a tabulation of the features that are enabled or disabled for each power mode.
 
{| class="wikitable"
 
{| class="wikitable"
Line 405: Line 535:
 
|}
 
|}
  
== Power Mode Entry and Exit ==
+
== Testing & Technical Challenges ==
 
 
 
 
=== Entering ===
 
 
 
Power mode entry is based on tables 44 (Power Mode Control register) and 662 (SCR bit assignments) of UM10360 [1].
 
 
 
void enter_sleep()
 
{
 
    LPC_SC->PCON = 0x0; // Table 44
 
    SCB->SCR    = 0x0; // Table 662
 
    __WFI();
 
}
 
 
void enter_deep_sleep()
 
{
 
    LPC_SC->PCON  = 0x8; // Table 44
 
    SCB->SCR    |= 0x4; // Table 662
 
    __WFI();
 
}
 
 
void enter_powerdown()
 
{
 
    LPC_SC->PCON  = 0x1; // Table 44
 
    SCB->SCR    |= 0x4; // Table 662
 
    __WFI();
 
}
 
 
void enter_deep_powerdown()
 
{
 
    LPC_SC->PCON  = 0x3; // Table 44
 
    SCB->SCR    |= 0x4; // Table 662
 
    __WFI();
 
}
 
 
 
Note the use of of __WFI(), which the compiler resolves as the assembly directive
 
__ASM ("wfi");
 
  
=== Exiting ===
+
=== Testing  ===
 +
*Power Consumption Testing
 +
**A big part of our project was to understand the power consumption of the LPC board under the different sleep modes, The results of that test are provided above.
 +
*PIR Sensor Behavior
 +
**We tested the sensor to understand the kinds of signals it produces in the LPC. There are a couple of settings on the sensor that needed to be calibrated to fit our needs.
 +
*Camera Recording
 +
**Since the Beagle bone worked off a trigger to start recording, we tested that subsystem to function well under several circumstances, like a constant high trigger, frequently fluctuating trigger as well edge cases.
  
On exiting a power mode, the associated bit on the Power Mode Control register must be cleared. As noted in the datasheet, bits 8, 9, 10, and 11 are associated to the particular power modes, and these flags are cleared in software by writing "one" to the associated bit.
 
 
void clear_sleep()          { LPC_SC->PCON |= 1 <<  8; };
 
void clear_deep_sleep()    { LPC_SC->PCON |= 1 <<  9; };
 
void clear_powerdown()      { LPC_SC->PCON |= 1 << 10; };
 
void clear_deep_powerdown() { LPC_SC->PCON |= 1 << 11; };
 
  
The PLLs (phase-locked loops) are turned off upon entering deep sleep, power-down, and deep power-down. Additionally, the IRC (the 4 MHz internal reference clock) and the clock dividers are reset when entering power-down and deep power-down. Therefore, the system clocks must be reconfigured/reinitialized when exiting any of these power modes.
+
=== Technical Challenges ===
  
We can take advantage of sys_clock_configure() from L0_LowLevel/sys_clock.cpp to perform this initialization.
+
* Stable PIR signal
 
+
** We had trouble putting the LPC to sleep since the PIR Sensors kept outputing signals even when inactive (Noise). So we had to develop logic to create a min/max values for a specific period of time to trigger the deactivation of sleep.  
One more thing to keep in mind regarding power mode exits: when exiting deep sleep, power-down, and deep power-down, there is a non-zero amount of time that must elapse before the system is able to resume processing. In all three cases, a timer starts counting the moment the power mode is exited, and code execution can resume after this timer expires.  
+
* 3D print quality
* If the IRC was used prior to entering the power mode, then the 2-bit IRC timer is used, and it lasts is 2<sup>2</sup> = 4 cycles long.
+
** We had to create multiple iterations to make the housing Fit our devices. We still need to make more exact measurements to fit our components.
* If the main external oscillator was used, then the 12-bit main oscillator timer is used, and it lasts 2<sup>12</sup> = 4096 cycles long.
+
* Contradictions in documentation
 
+
** We read through several pieces of documentation to understand the differences between the sleep modes until we came across the exact publication for the LPC module sleep modes. Same goes for the PIR sensors.
Moreover, in power-down and deep power-down, the flash undergoes wake-up, and its wake-up timer must expire (approximately 100 µs) before it can be used. This means that no instructions can be fetched from flash for execution until this timer expires.
 
  
 
== Conclusion ==
 
== Conclusion ==
Conclude your project here. You can recap your testing and problems. You should address the "so what" part here to indicate what you ultimately learnt from this project. How has this project increased your knowledge?
+
This project really helped us understand the capability of the sleep modes on the LPC system. It can definitely be used in several applications to save battery life. It is very simple to implement if you read through the data sheet completely. We would have also liked to implement the sleep mode in the Beagle bone to get a true power reading but didnt want to invest too much time in learning the beagle bone, but rather learn the LPC sleep modes as a proof of concept.  
  
 
=== Project Video ===
 
=== Project Video ===
Upload a video of your project and post the link here.
+
[https://drive.google.com/open?id=1t-SynEwjecFkUetFB0VsbPceChYXK1kJ Project Demonstration]
  
 
=== Project Source Code ===
 
=== Project Source Code ===
[https://sourceforge.net/projects/sjsu/files/CmpE_S2016/ Sourceforge Source Code Link]
+
All the power management driver code has been referenced above already. Moreover for BeagleBone video drives, the following open source code was used
 +
 
 +
[https://www.linuxtv.org/downloads/legacy/video4linux/API/V4L2_API/v4l2spec/capture.c V4L2 API Video driver for Linux]
  
 
== References ==
 
== References ==
 
=== Acknowledgement ===
 
=== Acknowledgement ===
Any acknowledgement that you may wish to provide can be included here.
+
 
 +
Thanks to Preet for always encouraging us to do great things and last but not the least, to let us use the name "MEOW" for our project.
  
 
=== References Used ===
 
=== References Used ===
Line 481: Line 577:
  
 
[2] NXP Semiconductors. (25 Feb. 2010). ''AN10915: Using the LPC1700 power modes.''
 
[2] NXP Semiconductors. (25 Feb. 2010). ''AN10915: Using the LPC1700 power modes.''
 
=== Appendix ===
 
You can list the references you used.
 

Latest revision as of 03:33, 27 May 2018

IMG 3326.jpg

Microcontroller Energy Observation Widget (M.E.O.W)

Abstract

Our project aims to provide a theft detection service by recording a video when any movement is detected in an immediate vicinity. A video feed is stored on the device to collect later on. The video feed can be used as evidence to provide authority to find the culprit. This report details the system and technology used to implement this project.

Objectives & Introduction

Show list of your objectives. This section includes the high level details of your project. You can write about the various sensors or peripherals you used to get your project completed.

Our primary goal for this project was to learn about the sleep modes that the LPC Microcontoller is capable of. In order to help us understand the functionality of the technology, we wanted to implement the sleep modes on a real life practical example.

Living in the Bay Area, a highly technological society, most tech employees travel with expensive equipment in their cars. Knowing this thieves consider this a prime area to conduct car robberies. Recently there has been an increase in these car robberies, where it can be hard to catch the criminals who have committed the theft. Often times the robbers work so quickly and discretely that a normal bystander might not consider the act suspicious. Additionally if your car is parked in remote area, far away from city cameras, it can be hard gather any evidence to catch the thief. Video surveillance evidence is highly valuable to an investigator assigned on the case.

Our video surveillance device, records footage if a crime is committed in a customers' car. Sensors in our device activate a camera to start recording when movement is detected. In its idle state, the device is in sleep mode where minimal tasks are being run on the device, which means it saves on a lot of power consumption. Alternatively if the device is constantly polling, this would use up an enormous amount of battery power. Since this device is meant to be running in a car that is not running, it is pertinent to use minimal power unless absolutely necessary to maximize the battery life.

This application can be scaled for any environment; your home, backyard, or even for city use. We can connect it every street lamp with some IOT capabilities resulting in lower crime rate across the city.

Objectives:

  • Research Power consumption capabilities of micro-controllers.
  • Build and implement a video surveillance device to feature the low power methods.

Team Members & Responsibilities

  • R "Meow Meow" Nikfar
    • Team Lead, PCB Design, Sensor Design and Implementation, Hardware Testing, Power Analysis, Sleep-Mode Firmware
  • Ahsan "Whiskers" Uddin
    • BeagleBone Testing, Video Capture Implementation, Storage, Sleep-Mode Research
  • Nelson "Fluffy" Wong
    • Deep Power Modes, Power Analysis, Communications
  • Britto "Kitty Kat" Thomas
    • CAN BUS Low Power Research, Power Analysis, System Design
  • Sai Kiran "Mittens" Rachamadugu
    • Testing, Board Communications, User Interface

Schedule

Week# Date Task Status
1 03/04
  • Research hardware and software, plan steps.
  • Team Building and Ideas.
  • Decided what the project will entail and the approach.
  • Team member tasks are given.
2 03/11
  • Team Research.
  • Individual Research on the subject. Meow Week.
3 03/18
  • Give specific tasks to team members.
  • PCB Design.
  • Finalize the project idea.
  • Divided the project into different sections.
  • Assigned roles and responsibilities to each member.
  • Initial PCB design is done in Eagle.
4 03/25
  • To finalize PCB, and order components.
  • Ordered Components, PCB was sent for printing.
5 04/01
  • Power mode research(different team members different areas).
  • Solder PCB components and test.
  • Modify the architecture and flow of project if necessary.
  • Individual research on power modes initialized.
  • Finished Soldering components on the PCB.
  • Architecture and flow of project modified and implemented.
6 04/08
  • Test and Implement the PIR motion sensors and connections.
  • Establish connections between the LPC and Beaglebone.
  • PIR sensor test and implementation done.
  • Interrupt and connections between the two microcontroller boards are done.
7 04/15
  • Test all the lower level components.
  • implement the sleep mode and power down modes.
  • Tested the lower level sensors and the power source (PCB and Lipo Battery).
  • Tested and implemented one of the power down modes.
8 04/22
  • Prototype of the shell of the project.
  • Write and further test implementation of low power modes.
  • 3D rendering of the prototype done. yet to be printed.
  • Further research and implementation of power modes done. More research needed.
9 04/29
  • Integrate code with PIR and Low Power functionalities
  • Rob Went to Napa Valley.
  • PIR Integration Complete
  • Rob drank wine.
10 05/06
  • Get the Camera and the overall system done.
  • Bitcoin will hit 10000.
  • Test the power consumption of each
  • Camera Successfully records on interrupt.
  • Bitcoin has only hit 8000
  • Testing Power modes complete
11 05/13
  • MEOW @ PREET
  • Finalize Prototyping and print the housing
  • Collect Images and Video for documentation
  • MEOWing Successful.
  • Housing completed.
  • Recorded Video and presentation images.

Parts List & Cost

  • BeagleBone Black Wireless $55
  • Logitech HD PRO WEBCAM C920 $70
  • 3 PIR sensors $45
  • 1 SJ One board $80

Design & Implementation

Hardware Design

GPIO Pins

M.E.O.W uses three PIR sensors , each of these sensors are connected to GPIO pins on port 2.3 , 2.4 and 2.5. Any motion detected asserts these pins creating a WIC to wake up the system from sleep.

GPIO pin 1.28 is asserted to signal beagle bone to start recording.

Low-Level Hardware

The low-level design starts from the PIR Motion Sensors and ends with the storage of the video data. The LPC1758 plays a big role in the communication of the overall system. The PIR sensors are each connected to the LPC1758 using a GPIO protocol and send signals if an object or and person is within their range. Once the signal is sent from the Sensors, the LPC wakes up and consumes power from the PCB which either uses the power from a plugged source or the backup LIPO battery. LPC then sends the right information to the BeagleBone board using UART protocol. Meow hardware schematic.JPG

Software Design

freeRTOS Tasks

For this project, we use two RTOS tasks, one for asserting GPIO pin needed for beagle bone and the other to put the LPC board to sleep. The PIR task which asserts GPIO pin is given a higher priority compared to the task which puts the LPC board to sleep.

Psuedo-code
Void PIRTask (void* pvParams){ 
              while(1){
                 if(xSemaphoreTake(xGetSemfromISR,portMAX_DELAY){
                 
                       // assert GPIO pin to signal beagle bone for recording video
                       LPC_GPIO1->FIOSET = 1 << “pin number”;
                }
        }
 }

Above code allows PIRTask to assert a GPIO pin to signal beagle bone to start recording. To put the LPC board to sleep a second task with lower priority is run. This task in-turn calls appropriate sleep mode.

Void PutToSleep(void* pvParams){
	While(1){
             if(xSemaphoreTake(xGetSemforSleep,portMax_DELAY){
                      //call appropriate sleep function
                       enter_powerdown();
 
             }
        }
  }

Interrupt request handler is created for above tasks which uses xSemaphoreGiveFromISR on interrupt to give a semaphore to the tasks. The code given below shows a pseudo-code for the Interrupt handler.

  void Simple_IRQHandler(){
         
        long yieldRequired = 0;
        xSemaphoreGiveFromISR(xGetSemfromISR, &yieldRequired);
        portYIELD_FROM_ISR(yieldRequired);
  
   }

Printed Circuit Board Design

In order to stabilize and provide a noise free power supply to all the components of the system, a printed circuit board(PCB) was created. This piece of hardware brings all the power consumption of the unit together. The design and the creation of the board was done in Eagle Schematics Software where the gerber files were created. Once the gerber files were ready, the files were sent to be printed. There were 2 iteratins of this board. The first lacked the necessary connections for the additional components and had several noise reduction flaws. The second board solved all these issues. Note that the final board had to be 1 layer due to the noise reduction characteristics of the material and the ability for placement of the LIPO battery on the bottom of the board.
Meow Eagle schematic.JPG

MEOW PCB schematic.JPG

NXP LPC1700 Series Power Modes

Power management functionality in LPC 176x CPU

There are mainly 4 modes of runtime power savings mode that are available in LPC 176x CPU. They are described in details as follows. Measurements were made using an Agilent Infiniium MSO9254A, a N2870A passive probe, and a 1147B current probe. It should be noted that our SJ One board generally runs at 96MHz with 5V input voltage and consumes about 177mA of current which corresponds to 885mW of power.

Deep sleep

Upon entering the Deep sleep mode, the main oscillator is powered down and the DSFLAG in PCON is turned on. We observed that the current consumed at this state was 167mA which corresponds to 835mW of power. To wake up from Deep Sleep, an EINT0 was used to resume the CPU. Note that as PLLs are shut off during this sleep, the PLLs are configured once the CPU is resumed from deep sleep.

Deep Sleep power saving scopeshot

Power Down mode

Upon entering the Power Down mode, like deep sleep the main oscillator is powered down but additionally the flash is also turned off. We observed that the current consumed at this state was 80mA which corresponds to 400mW of power. To wake up from Deep Sleep, an EINT0 was used to resume the CPU. Note that as PLLs are shut off during this sleep, the PLLs are configured once the CPU is resumed from deep sleep.

Power Down power saving scopeshot

As we learnt in this semester that frequency plays a role in power consumption, and as we know that the default frequency of the LPC board is 96MHz, we tried the same power down sequence wit 8MHz. This time we saw that the current consumption went down to 24mA which corresponds to only 120mA!!! By far, this was the most stable power saving feature we have tested and we implemented this setting in our project.

Power Down @ 8MHz power saving scopeshot

Deep Power mode

Upon entering the deep power down mode, the entire chip is powered down except the RTC and the DPDFLAG in PCON is turned on. We observed that the current consumed at this state was 60mA which corresponds to 300mW of power. To wake up from Deep Sleep, there is only one way i.e to set the RESET pin, which replicates very closely to the cold boot process.

Deep Power Down power saving scopeshot

Summary of Power modes

Below is a chart for all the power savings comparisons side by side.

Power savings comparison chart

One things that needs to be noted is that although we are manipulating the power states we are still seeing a significant amount of current being drawn constantly. For example we are claiming that in deep power down, the ASIC is switched off but yet we see 60mA of current being drawn. The answer is that is even though the ASIC is switched off, there are other peripherals that are still ON. For example the 7 segment LED. So ideally it would be interesting to see what happens when each and every single peripheral is turned off dynamically in each state and to see the absolute power savings consumption.

Entering

Power mode entry is based on tables 44 (Power Mode Control register) and 662 (SCR bit assignments) of UM10360 [1].

Please note the following, regarding the interaction between power modes and debugging status. If P2.10/EINT0/NMI is asserted voltage-low, the LPC will boot in debug mode. In debug mode, the LPC will not wake in the same manner. Since we do not program the LPC via JTAG/SWD, this is not a problem for us.

void enter_sleep()
{
   LPC_SC->PCON = 0x0; // Table 44
   SCB->SCR     = 0x0; // Table 662
   __WFI();
}

void enter_deep_sleep()
{
    LPC_SC->PCON  = 0x8; // Table 44
    SCB->SCR     |= 0x4; // Table 662
    __WFI();
}

void enter_powerdown()
{
    LPC_SC->PCON  = 0x1; // Table 44
    SCB->SCR     |= 0x4; // Table 662
    __WFI();
}

void enter_deep_powerdown()
{
    LPC_SC->PCON  = 0x3; // Table 44
    SCB->SCR     |= 0x4; // Table 662
    __WFI();
}

Note the use of of __WFI(), which the compiler resolves as the assembly directive

__ASM ("wfi");

Exiting

On exiting a power mode, the associated bit on the Power Mode Control register must be cleared. As noted in the datasheet, bits 8, 9, 10, and 11 are associated to the particular power modes, and these flags are cleared in software by writing "one" to the associated bit.

void clear_sleep()          { LPC_SC->PCON |= 1 <<  8; };
void clear_deep_sleep()     { LPC_SC->PCON |= 1 <<  9; };
void clear_powerdown()      { LPC_SC->PCON |= 1 << 10; };
void clear_deep_powerdown() { LPC_SC->PCON |= 1 << 11; };

The PLLs (phase-locked loops) are turned off upon entering deep sleep, power-down, and deep power-down. Additionally, the IRC (the 4 MHz internal reference clock) and the clock dividers are reset when entering power-down and deep power-down. Therefore, the system clocks must be reconfigured/reinitialized when exiting any of these power modes.

We can take advantage of sys_clock_configure() from L0_LowLevel/sys_clock.cpp to perform this initialization.

One more thing to keep in mind regarding power mode exits: when exiting deep sleep, power-down, and deep power-down, there is a non-zero amount of time that must elapse before the system is able to resume processing. In all three cases, a timer starts counting the moment the power mode is exited, and code execution can resume after this timer expires.

  • If the IRC was used prior to entering the power mode, then the 2-bit IRC timer is used, and it lasts is 22 = 4 cycles long.
  • If the main external oscillator was used, then the 12-bit main oscillator timer is used, and it lasts 212 = 4096 cycles long.

Moreover, in power-down and deep power-down, the flash undergoes wake-up, and its wake-up timer must expire (approximately 100 µs) before it can be used. This means that no instructions can be fetched from flash for execution until this timer expires.

Features Summary

Below is a tabulation of the features that are enabled or disabled for each power mode.

Features Sleep Deep-sleep Power-down Deep Power-down
Wake via reset Yes Yes Yes Yes
Wake via RTC interrupt Yes Yes Yes Yes
Wake via NMI Yes Yes Yes No
Wake via EINT0-3 Yes Yes Yes No
Wake via GPIO interrupts Yes Yes Yes No
Wake via Eth WOL interrupt Yes Yes Yes No
Wake via brownout detect Yes Yes Yes No
Wake via watchdog timer Yes Yes Yes No
Wake via USB-active interrupt Yes Yes Yes No
Wake via CAN-active interrupt Yes Yes Yes No
Wake via any other interrupt Yes No No No
Main oscillator? Enabled Disabled Disabled Disabled
IRC oscillator? Enabled Enabled Disabled Disabled
RTC oscillator? Enabled Enabled Enabled Optional
CPU clock? Disabled Disabled Disabled Disabled
Peripheral clocks? Enabled Enabled Disabled Disabled
USB clock? Enabled Disabled Disabled Disabled
Watchdog clock? Enabled Enabled Enabled* Disabled
PLLs? Enabled Disabled Disabled Disabled
Status of Wake-up Interrupt Controller? Active Active Active Active
Status of RTC backup registers? Active Active Active Active
Status of on-chip regulator? Active Active Active Active or power-down with external circuitry
Status of flash memory? Standby Standby Powered-down Powered-down
Status of processor state? Preserved Preserved Preserved Powered-down
Status of processor registers? Preserved Preserved Preserved Powered-down
Status of peripheral registers? Preserved Preserved Preserved Powered-down
Status of SRAM values? Preserved Preserved Preserved Powered-down
Status of chip pin logic levels? Preserved Preserved Preserved Powered-down
Access to flash memory? Disabled Disabled Disabled Disabled
Access to main SRAM? Disabled Disabled Disabled Disabled
Access to AHB SRAM? Allowed with GPDMA support Allowed with GPDMA support Disabled Disabled
Access to peripherals? Allowed with GPDMA support Allowed with GPDMA support Disabled Disabled
Dynamic power? Disabled Disabled Disabled Disabled
Special instructions after wakeup? No Yes Yes Yes
Resume from last PC? Yes Yes Yes No; system restarts

Testing & Technical Challenges

Testing

  • Power Consumption Testing
    • A big part of our project was to understand the power consumption of the LPC board under the different sleep modes, The results of that test are provided above.
  • PIR Sensor Behavior
    • We tested the sensor to understand the kinds of signals it produces in the LPC. There are a couple of settings on the sensor that needed to be calibrated to fit our needs.
  • Camera Recording
    • Since the Beagle bone worked off a trigger to start recording, we tested that subsystem to function well under several circumstances, like a constant high trigger, frequently fluctuating trigger as well edge cases.


Technical Challenges

  • Stable PIR signal
    • We had trouble putting the LPC to sleep since the PIR Sensors kept outputing signals even when inactive (Noise). So we had to develop logic to create a min/max values for a specific period of time to trigger the deactivation of sleep.
  • 3D print quality
    • We had to create multiple iterations to make the housing Fit our devices. We still need to make more exact measurements to fit our components.
  • Contradictions in documentation
    • We read through several pieces of documentation to understand the differences between the sleep modes until we came across the exact publication for the LPC module sleep modes. Same goes for the PIR sensors.

Conclusion

This project really helped us understand the capability of the sleep modes on the LPC system. It can definitely be used in several applications to save battery life. It is very simple to implement if you read through the data sheet completely. We would have also liked to implement the sleep mode in the Beagle bone to get a true power reading but didnt want to invest too much time in learning the beagle bone, but rather learn the LPC sleep modes as a proof of concept.

Project Video

Project Demonstration

Project Source Code

All the power management driver code has been referenced above already. Moreover for BeagleBone video drives, the following open source code was used

V4L2 API Video driver for Linux

References

Acknowledgement

Thanks to Preet for always encouraging us to do great things and last but not the least, to let us use the name "MEOW" for our project.

References Used

List any references used in project.

[1] NXP Semiconductors. (19 Dec. 2016). UM10360: LPC176x/5x user manual.

[2] NXP Semiconductors. (25 Feb. 2010). AN10915: Using the LPC1700 power modes.