Sunday, August 26, 2018

In a previous post, you noted that most important aspect of a system running on solar energy is how much power system consumes vs. how much power the solar panel generates; the last variable can be found from the data sheet of the solar panel at hand. The solar panel is made of a module, or electrically inter-connected multiple modules on the same frame where the solar module(s) are encapsulated to protect them from corrosion. Each solar module is made of multiple solar cells inter-connected in series or parallel with a certain packing density. This post is not meant to discuss the fabrication of solar panel, but more on how to read the electrical properties found in the data sheet....We will touch on the mismatch happening when connecting multiple panels in an array using a practical example comparing output power from two identical solar panels.
First let us talk about the electrical properties of the solar panels: In the picture below, we have two solar panels, from different manufacturers, the bigger one is 350*255mm(W*H) rated at Pmax=10W at a voltage 17.8V. The smaller one is 250*134.5mm(W*H) rated at Pmax=3.5W at a voltage of 6V. Battery charging is a current dependent action not a voltage dependent action; assuming that you have a solar charger implementing Maximum Power Point Tracking (MPPT) algorithm, your most important variable is how much current you are getting from the solar panel...

Electrical Spec. for 10W Solar Panel
Electrical Spec. for 3.5W Solar Module




















Once you note that the electrical proprieties shown in the picture above, you will find that both panels generating the same current at Ipmax, more or less. Let us try to test these panels in practice connected with a solar charger, the Sunny Buddy by Sparkfun. As per hookup guide provided for this solar charger, you have the option either to check how much the solar panel is delivering current or you can see the how much the charger is supplying current to the battery, where the later depends on Maximum Power Point Tracking algorithm to guarantee maximum power transferred to the battery guaranteed no damage happening to battery. Let us follow instructions found at Sparkfun Sunny Buddy hook-up guide to check how much current each solar panel is delivering....”A useful trick for monitoring the input current of a single panel system is to clear JP1 and close JO2, then connect an ammeter between the + pads on the two 3.5mm footprints. This will allow you to monitor the current draw from the solar panel. Note that JP1 must be resoldered and JP2 reopened before attempting to use the sunny buddy without the meter in place!






The solar charger used here, the Sunny Buddy, can be set to reduce its current draw once a certain input voltage is reached, where this voltage can be set via a potentiometer, I did not try to optimize this setting while measuring the current drawn by the solar charger. Here is a summary of the result:
Item
Dim.(W*H)(mm)
Rated Power(W)
Vmppt(V.)
Imppt(A.)
Itest(A.)
Solar panel #1
350*255
10
17.8
0.57
0.46
Solar panel #2
250*134.5
3.5
7.2
0.583
0.504

The current readings measured via the multi-meter are close to what the electrical properties section is showing for Ipmax , but the current drawn from the smaller solar panel is slightly more than that current drawn from the larger solar panel and the reason is the difference in voltage rating of each panel. This difference is due to the way the solar cell is inter-connected inside the solar module; it is up to you and solar charger to draw maximum current from solar panel.
Now, let us turn our attention to the issue of mismatch. On a module level, strings of solar cells are connected in series or parallel to produce the required current or voltage. Ideally the solar cells are identical but in practice they will be a mismatch between them which will affect the current or the voltage produced depending if the cells are connected in series or parallel. Thus, you will see the +/- tolerance in the electrical properties section of data sheet. Likewise, the solar panels can be electrically inter-connected to form strings and arrays of panels to produce required current or voltage, in this regard; any mis- match between the solar panels will affect the current or voltage of series and/or parallel combination. The mismatch happens due to the fact that you will not get exactly the same output power from different panels even if they are rated the same, manufactured in the same way and even fabricated by the same manufacturer. Check this video below showing two identical solar panels, rated at 2 watts each,  connected to run two motors, each motor is on one side of a plastic car; if the car goes straight then both solar panels are producing the same amount of power. Note that these panels are identical, from same manufacturer and rated at the same voltage and power.




As discussed above, the power extracted from a solar panel will depend on how you extract it, either using MPPT or other solutions, like linear regulators, switching regulators or any energy harvesters.

In above video, we are not using a solar charger to deliver power to the DC motors but using a nano power energy harvesting power supply based on the LTC3588-1, breakout is made by sparkfun and below circuit diagram is a snap shoot taken from the application information section of the LTC3588-1 data sheet.
Curtsy of LTC-3588-1 Data Sheet

 The video for the solar car, two circuits, similar to figure-11 above, are soldered on the board mounted above the car. Unlike the circuit suggested in the application information, no back batteries were connected to the circuit; in the input side there is a solar panel and output of the IC has a super capacitor plus the load (DC motor) connected in parallel.

We will explain more on the LTC3588 in future posts... stay tuned to know more.......

Note:All technical information in this post, except videos of solar panels and solar car and related circuits, are with reference to PV3X Solar Energy Engineering: Photovoltaic Systems from Deflt University  offered at Edx.org 

Saturday, August 11, 2018


Welcome back to my first blog after long break, greetings from Saudi, where the sun meets the sand





Really, there is more to Saudi Arabia than just sand, in the pictures above you see mountains, sea,......Having told you my where about, there is plenty of sun here to harvest. In next few posts you will go throught some projects regarding harvesting the sun's energy in different ways.

One way to harvest energy from the sun is through a solar charger, it will help you obtain a steady output from the solar panel when there is enough sun, an output that is used to charge a battery. Main driver for a solar charge is an algorithm called maximum power point tracking (MPPT), one that has many flavors but its main theme:collecting maximum output power from a solar panel. Please refer to this excellent presentation by Texas Instruments (TI) on MPPT algorithm. You will find in the presentation a reference to Ti's bq25895 IC, which is a solar charger that implements MPPT algorithm.


In this post we will look at a similar solar charger based on LTC3652 IC, it was made by linear technology and the PCB was designed by sparkfun and named The Sunny Buddy. LTC3652 implements MPPT in its simplest form, which drives the solar panel at 90% of solar panel's open voltage value at which the LTC3652 will reduce its current draw to maintain peak power input from the solar panel. You can reference post below from voltaicsystems for comparison of different solar chargers.
  
To let you know more about solar chargers, let us choose Sparksfun's Sunny Buddy board, plug-in couple of solar panels, and hook up a micro controller to watch solar charger in action, charging a Lipo battery. Well, the first thing was to setup the system,

Solar charger ---->Sunny buddy V1.3 based on LTC3652
Solar panels---> 2X2W Si-Silicon based solar panels
Lipo Fuel gauge---> Lipo fuel gauge based on MAX17043G+U IC
Mcu---> Arduino Mini Pro 16Mhz, 5V.
Battery---->  Lipo 3.7V, 750mAh
Circuit schematic

Let us's do the calculation of power delivered from the solar panel, and how much power needed by Mcu, and how much is the safe charging current for Lipo battery. Start with last item on the list: Lipo battery safe charging current is 1/C which is equal to 750mAh, i.e. it is safe to set the charge current on the sunny buddy to 750ma or less. Mcu chosen for this demo is Arduino mini Pro, running at 5V and 16Mzh, typical power consumption values can be found in this post, which assumes that Mcu will go to sleep and wake up via watch dog timer.

Indeed, taking the Mcu into sleep is recommended to reduce the power consumption and reduce the load on the solar charger, allowing it to do its job, charge the battery. In this demo, we will let Mcu sleep for 8 second and wake up to check the battery state of charge using information provided by LiPo Fuel Gauge plus information like charge/idle state provided by the solar charger. This means the Mcu is sleep 83% of the time and active for 27% of the time, using the information found in the above post, we can multiple %sleep
*Power consumption during sleep + multiply %awake* active power consumption.

The rest of circuit component:
Lipo Fuel gauge consume 50Mu A on active status and can be sent to sleep state via I2c interface commands
Lipo Boost Converter used to convert voltage level from 3.7V. to 5 V. with efficiency curve shown below
A level shift is needed to convert LTC3652's pin logic levels, which are pulled to Vbat=3.7V as per sparkfun design.

 
Curtsy:TI's TPS61200 datasheet (SLVS577B)
Note that the code snap shoot below reference low power library and Lipo Fuel gauge library which can be find online

#include <Wire.h>
#include <LiFuelGauge.h>
#include "LowPower.h"
void lowPower();
// Use pin 2&3 as wake up pin
const int wakeUpPinINT0 = 2;
const int wakeUpPinINT1 = 3;
const int DigiPin4 = 4;

int CHC_val=0;
int FAULT_val=0;
// LiFuelGauge constructor parameters
// 1. IC type, MAX17043 or MAX17044
// 2. Number of interrupt to which the alert pin is associated (Optional) 
// 3. ISR to call when an alert interrupt is generated (Optional)
//
// Creates a LiFuelGauge instance for the MAX17043 IC
// and attaches lowPower to INT0 (PIN2 on most boards, PIN3 on Leonardo)
LiFuelGauge gauge(MAX17043 , 0, lowPower);

// A flag to indicate a generated alert interrupt
volatile boolean alert = false;
volatile boolean flag_charge = false;
volatile boolean flag_fault = false;


void setup()
{
    // Configure wake up pin as input.
    // This will consumes few uA of current.
    pinMode(wakeUpPinINT0, INPUT);
    pinMode(wakeUpPinINT1, INPUT);
    pinMode(DigiPin4, INPUT);
    //pinMode(12, INPUT);
    //pinMode(13, OUTPUT);   
    Serial.begin(9600); // Initializes serial port
    // Waits for serial port to connect. Needed for Leonardo only
    //while ( !Serial ) ;
    
    gauge.reset();  // Resets MAX17043
    delay(200);  // Waits for the initial measurements to be made
    
    // Sets the Alert Threshold to 10% of full capacity
    gauge.setAlertThreshold(10);
    Serial.println(String("Alert Threshold is set to ") + 
                   gauge.getAlertThreshold() + '%');
}

void loop()
{
    Serial.end();
    
    attachInterrupt(wakeUpPinINT1,wakeUp3, CHANGE);
    // Enter power down state with ADC and BOD module disabled.
    // Wake up when wake up pin is low.
    LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); 
    // Disable external pin interrupt on wake up pin.
    detachInterrupt(1); 
    // Do something here
    Serial.begin(9600); // Initializes serial port
    if (gauge.sleeping())
    {gauge.wake();
     gauge.reset();  // Resets MAX17043
     delay(200);  // Waits for the initial measurements to be made
     
}
    if (flag_charge)
    {
      CHC_val=digitalRead(wakeUpPinINT1);
      FAULT_val=digitalRead(DigiPin4);
    Serial.print("SOC: ");
    Serial.print(gauge.getSOC());  // Gets the battery's state of charge
    Serial.print("%, VCELL: ");
    Serial.print(gauge.getVoltage());  // Gets the battery voltage
    Serial.println('V');
    if (!CHC_val)
    {if(FAULT_val)
      {Serial.println("Charghing");
      }
      else
      {Serial.println("Fault");}
    }
    if (CHC_val)
    {if(FAULT_val)
      {Serial.println("Idle");
      }
      else
      {Serial.println("Bat. Fault");}
    }
    CHC_val=0;
    FAULT_val=0;
    }
        
    if ( alert )
    {
        Serial.print("SOC: ");
        Serial.print(gauge.getSOC());  // Gets the battery's state of charge
        Serial.print("%, VCELL: ");
        Serial.print(gauge.getVoltage());  // Gets the battery voltage
        Serial.println('V');
        Serial.println("Beware, Low Power!");
        Serial.println("Finalizing operations...");
        gauge.clearAlertInterrupt();  // Resets the ALRT pin
        alert = false;
        Serial.println("Storing data...");
        Serial.println("Sending notification...");
        Serial.println("System operations are halted...");
        gauge.sleep();  // Forces the MAX17043 into sleep mode
     }
    
    //delay(2000);
}

void lowPower() { alert = true; }
void wakeUp3()
{
    // Just a handler for the pin interrupt.
    flag_charge=!flag_charge;
    
}

This code ran on the Mcu for 12 hours, where battery S.O.C dropped from 96% to 12%. In the first three hours, no charging was being done and then 8 hours of charging did not help to raise the S.O.C of the battery. From log of Lipo Fuel gauge, it is noted a 6.25% drop of battery S.O.C. each hour which amounts ~49mA power consumption per hours.



From the above first run of the system, it was clear that a path forward with this setup was not possible; the amount of energy consumed versus the charging speed of the battery will cause the battery to be depleted before the sun of the next day. It was necessary to check the amount of current delivered by the solar panel and the solar charger at hand. After examining the amount of current delivered by each solar panel at full sun irradiance, it was found to be a humble of 50mA, which far less than 2Watt, claimed by the supplier. The Sunny Buddy, was faithful in delivering the full amount of energy produced by 2X2Watt panels, a combined sum of 100mA.

The solution was one of the below:

1- A: Replace Solar panel with more powerful or more efficient solar panel
     B: Replace the Micro-controller or its voltage, and/or clock speed, which reduces the power                   consumption and remove some of the unnecessary components.
2- Use an auxiliary power supply that is made of a second battery useful to maintain system until the first battery is fully charge, i.e. System will be supplied from a DC bus, with a redundant power source. Auxiliary power supply should have a mechanism to recharge its battery when not in use.
Option (1-A) Replace Solar panel with more powerful or more efficient panel


Keep tuned, in the next post we will explore all solutions (1 & 2), waiting to see you in the next post.


Monday, December 15, 2014

Using Arduino as an IR remote and some other ideas


This post is about a simple project that was the basis of anther project posted on my blog. In this project, we are going to show how to use Arduino as a remote control for a TV. The requirement for the project was: a TV is connected to a security camera, camera is always ON, and we want to turn the TV ON/OFF from a distance/angle that the TV infrared (IR) remote does not support, please see Figure-1 below.

Figure-1 TV, Security camera and the Arduino mounted on the lower left side of the TV



As you know, the IR remote that comes with the TV works at a line of sight distance: this means you have to be facing the TV to be able to use the remote. The TV you see in Figure-1 was placed in the second floor and we want to turn it ON using a device placed at the first floor. Usually, the best thing to turn power ON/OFF is to use a relay, well that is true but note that nowadays TV needs to be turned ON using a remote after turning the main power ON. Nevertheless, the relay had to be controller from anther location, the first floor, this made things a little bit complicated!!

Best engineering practice is to divide the problem into parts, called divide and conquer approach. First, the simple part: using a relay will only help to turn on the power to the TV; but, if we connect the TV and an Arduino to the relay then relay will power the TV and in the same time power the Arduino. Bingo, think of the idea of using the Arduino as a remote: connect an Infrared (IR) LED to it and let it send the ON signal to TV after main power was turned on using the relay. What about the OFF signal? No need for it since the relay will turn the TV OFF anyway. Seems simple project!! It is simple but the relay was placed next to the TV, at the second floor, and controlling the relay was done from the first floor. Hence, the relay had to be controlled via Radio Frequency (RF)

Fortunately, a relay that can be controlled via Radio Frequency (RF) was available at hand. The relay comes with anther unit, a push button connected to a RF unit; push button used to turn the relay ON/OFF. Neither the details of the relay unit nor the details of the RF unit are available at this time; somebody else bought it, many thanks to him.    

Let us talk about the software side then we can talk about physical connection. To use the Arduino as an IR remote you need IR LED and you need to know the protocol and codes your TV use to communicate with its actual IR remote; M. McCracken explains this in details in his post and provides useful links about IR protocols and codes each TV use (you may need to be logged as registered user to hifi-remote.com). One great thing about Arduino, you can find library for anything you need; some people already did a lot of work using Arduino and made their software available to public. One name to mention here is Ken Shirriff’s work to provide an open source multi-protocol IR library for the Arduino; currently, his library is included with Ardunio and Energia distributions.

You can easily figure out the rest of steps regarding using Ardunio as an IR remote: either use the links on McCracken post to lookup the protocol your device uses and the associated ON code for your device or you us an IR detector to decipher the protocol and the codes your IR remote sends based on the Ken Shirriff’s  library. One thing to note when you are programming your Arduino to mimic a remote sending ON signal, it is timing; keep reading the hardware part to know more….

Hardware setup is simple; see Figure-2 and Figure-3 below. The multi-outlet has the relay plugged to the top receptacle and the lower receptacle has the camera AC-DC convertor plugged to it. The relay its self is powering both the TV and the Arduino AC-DC convertor using the white extension cord. Next, let us talk about the Arduino hardware. This project used ArduinoOSEPP UNO hardware; I have to admit that during the testing period, more than a month, the board never stopped responding or malfunction due to repeated restarts. On Figure-3, you can see that the IR LED is connected to a PCB breadboard and an additional resistor is used to limit the current going to IR LED; on the UNO board pin 11 and the ground pin are used to connect the IR LED. Note that the whole setup was mounted to the wall next to the TV such that IR LED is positioned as close as possible to the IR detector found in the TV. A simple AC-DC converter provides the input voltage for OSEPP UNO, 6-12 volts allowed, in this project an AC-DC 12 volts convertor was used with no issues.  One final note, when you program the Arduino, you will need to add some delay just before sending the ON signal using Pulse Width Modulation, this will the allow some time for the TV to initialize and actually turn the IR detector on. Also, it is better to add the code to send ON signal in the setup part of the Arduino code.

Figure-2 Wiring setup showing a picture of the relay on the bottom
 
Figure-3 OSEPP Arduino mounted next to the TV; note IR LED is in front of the IR detector inside TV


Sunday, December 7, 2014

Project: Motion Sensing over wireless link using MSP430 and Anaren Booster Pack

In a previous post, problem of finding suitable programming environment for the Anaren Booster Pack has been discussed; we talked about how easy it was to program MSP430 using the Energia environment. In the newer versions of Energia 0101E0013 (09/05/2014), Anaren has included a library with some cool functions and couple of code examples for sensor-hub communication, control example, and simple wireless communication test example. Stay tuned to read a nice post about a simple modification to Anaren code to include acknowledgment mechanism. But for this post will cover a cool project that I was asked to do.

Requirements were simple: we have a TV connected to a security camera (camera always on). Turn TV ON whenever motion happens in a certain area. To safe power, TV had to be turned OFF when no motion is detected for a specified period.  


Remember in a previous post you have seen how to program a pair of TI MSP430 Microcontroller Units (MCU) to communicate motion detection event coming from Passive Infra Red (PIR) sensor. Well, this is just what we are going to do in this cool project. One end, where motion is to be detected, will have a PIR sensor connected to MSP430 MCU plus Anaren Booster Pack RF module in order to communicate motion detection event to the other end. On the TV/Security camera end we have to turn the TV ON when receiving a signal on the RF module. While first thing comes into your mind is a RELAY to turn TV ON, remember that now days all TV’s need to be turned on using an IR remote even if the power source is on!! To satisfy your curiosity, yes we will have a post about using a relay to turn TV. In that project, my contribution was only the part of turning TV on using Infra Red (IR) signal coming from IR LED connected to the MCU after the relay turns power source on; stay tuned to see how to get MCU acting like a remote!! This post will only deal with the end composed of MSP430 LaunchPad, PIR sensor and the Anaren Booster Pack. 





Figure 1 TI MSP430 LuanchPad, Anaren Booster Pack inside the enclosure

 First thing is to decide program structure, next we can talk about the choosing enclosure, mounting, and power supply. As mentioned above, code examples published by Anaren included a sensor-hub example code; this is exactly what we need. The sensor will send data and hub will receive data; we can choose to have the hub acknowledging sensor’s packets but this project did not go this direction, we will talk more about using an acknowledgment in the end of this post. Since one requirement is to count no motion period, we have to use timers. Since MSP430 is busy with counting (timer), we can not afford to have the MCU waiting on a positive edge from PIR (when it detects motion); interrupts will be the best choice to alarm for a positive edge. Next, we get to choose the pin on MCU to connect to PIR output. Note that some pins do not have interrupt enabled, and some pins are used by the Anaren Booster Pack. This leaves us with very limited choice, either pin 1_3 or pin 2_3. In our code we choose pin 1.3 which is defined as PUSH2 in Energia, it happens to be connected to a push button on TI LaunchPad. Next, lets us choose the timer; note that we need to measure periods in order of minutes when counting no motion period. This means the timer should drive its clock from a low frequency oscillator; MSP430 has many choices for oscillator. MSP430 runs its system clock of 1.1MHz oscillator, but the best thing with MSP430 is you can run multiple oscillators same time.  You can have a 1.1Mhz oscillator as the source of the system clock and anther low frequency oscillator for peripherals.For a low frequency , the VLO oscillator is one choice, it runs somewhere around 12KHz, and the second choice would be to attach an external crystal, the one supplied with TI Launchpad provide 32KHz clock. VLO was the choice for this setup, and this allows a timer as long as 40seconds.  If you allow the timer to overflow certain number of times you can get the time period you like; allowing the timer to overflow 15 times will allow periods of10 minutes. Well, this is it about the program structure. Below is code:

#include <SPI.h>
#include <AIR430BoostFCC.h>
// -----------------------------------------------------------------------------
/**
 *  Defines, enumerations, and structure definitions
 */
#define ADDRESS_LOCAL    0x02
#define ADDRESS_REMOTE   0x01
#define PIR_Settling_Time 20000 //Allow PIR learn its environment up to 40sec (datasheet)
#define CC110L_Settling_Time 5000//Startup time between MSP430 and CC110L
 /**
 *  sPacket - packet format.
 */
struct sPacket
{
  uint8_t from;           // Local node address that message originated from
  uint8_t message[1];    // Local node message
};

// -----------------------------------------------------------------------------
/**
 *  Global data
 */
 struct sPacket txPacket;
volatile boolean Lockhigh=true;
volatile unsigned char counter = 0;
 // -----------------------------------------------------------------------------
// Main example

void setup()
{
     //Allow setup time for PIR and CC110L
     if (PIR_Settling_Time>CC110L_Settling_Time){
      delay(PIR_Settling_Time);}
       else{delay(CC110L_Settling_Time);}
  /**
   * 
   *  Note: Set radio first to ensure that GDO2 line isn't being driven by the
   *  MCU as it is an output from the radio.
   */
    Radio.begin(ADDRESS_LOCAL, CHANNEL_1, POWER_MAX);

  txPacket.from = ADDRESS_LOCAL;
  memset(txPacket.message, 0, sizeof(txPacket.message));

   WDTCTL = WDTPW + WDTHOLD;      // stop WDT
  
   pinMode(PUSH2,INPUT);//P1.3 is PIR input
   attachInterrupt (PUSH2, Port_1, CHANGE);//activate interrupt on pin P1_3
   P1DIR = BIT0; // set P1.0 as output (RED LED on LaunchPad)
   P1OUT =~BIT0;// Turn OFF RED LED
     
   BCSCTL1 = CALBC1_1MHZ;    // Set DCO to calibrated 1 MHz.
   DCOCTL = CALDCO_1MHZ;
   BCSCTL3 =LFXT1S_2;   //Set VLO
   TACCR0 = 60000 - 1;    // A period of 60,000 cycles (~40sec@VLO)
   TACCTL0 = CCIE;        // Enable interrupts for CCR0.
   TACTL = TASSEL_1 + ID_3 + MC_1 + TACLR;  // ACKL, div 8, up mode,clear timer
 
}

void loop()
{
 
}

//// Timer A interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A()
{
       if(counter == 10 & !Lockhigh ) {// this is when the PIR indicate no motion for 10min
        counter = 0;
        txPacket.message[1] = 'O';
        Radio.transmit(ADDRESS_REMOTE, (unsigned char*)&txPacket, sizeof(txPacket));
        P1OUT =~BIT0; // RED LED OFF
        Lockhigh=true;
       }
        else {// this is when PIR indicate motion or while no motion w/time <Total Wait Time
         counter++;
            
      }
}
  
// Port 1 interrupt service routine
//__interrupt void Port_1()
void Port_1(void)
{
 
   if (digitalRead(P1_3) && Lockhigh){
   P1OUT = BIT0; // Trun on RED LED in case of motion being detected
   txPacket.message[1] = 'A';//
   Radio.transmit(ADDRESS_REMOTE, (unsigned char*)&txPacket, sizeof(txPacket));
   Lockhigh=!Lockhigh;//Toggel Lock (indicate no motion period /end of no motion period)
   }
    else {counter=0;}//any other signal from PIR rests timer
 }


Next, we will talk about the final product including hardware, enclosure, mounting and power source. Note that Anaren Booster Pack can be a stand alone; you can mount the TI MSP430G2553 onto the board and connect led, push button and power supply with some capacitors, please see Figure 2 below from Anaren manual. In this project, soldering surface mount components was not possible; the final product used LuanchPad to hold the MCU and Anaren Booster Pack as shown in figure 1 above. Since PIR sensor has to sticking outside the mount, you need to choose a mount with flat surface on one side. Drill through the flat surface a hole such you can mount the PIR sensor with its lens outside as shown in figure 3. Note in this figure; the power source is sticking to the side of the enclosure; a simple phone charger with USB output has been used.
 
Figure 2 Picture courtesy of Anaren
Figure 3 Enclosure with PIR sensor sticking out of it


Trouble shooting:
Possible problems that you may face are as follow
1-      Failed communication between the unit holding the sensor and unit responsible for turning TV ON. If this happens you will note indicator led, shown in figure one above, tuned ON while the TV is OFF or visa versa. Just rest the unit by unplugging the power from the unit with PIR and make sure the TV is turn off .Then plug power to the MCU connected to PIR, make sure to allow some period of no motion while the PIR learns the environment.
2-       Wires are loose; this may happen and it will cause the unit to not function correctly. Refer to figure 1 for correct connection and secure the wire to pins.
3-      Infra Red LED on the unit responsible for turning TV ON may get out of focus with the Infra Red detector on the TV. Just make sure the Infra Red LED on the MCU is in front of the Infra Red detector on the TV.
4-      If MCU goes bad then they can be replaced and programmed via the LaunchPad using the code provided.


Please stay tuned to read a nice post about a simple modification to Anaren sample code to include acknowledgment mechanism.


Monday, September 8, 2014

Programming Anaren Booster Pack: thoughts and a demo


     In a previous post, establishing Radio Frequency (RF) communication between Anaren Booster Pack modules diverged to focus more on Passive Infra Red (PIR) motion sensor and how to program MSP430 Launch Pad to display motion detection status. Instead, this post will focus more on the programming task, hopefully.
       To recap, objective was to establish RF communication with some payload (a frame of data) to indicate the detection output status of a motion sensor. Also, there was supply power conflict (+5V versus +3V) between Texas Instrument micro controller and the sensor. While you can read more on interfacing motion sensor to the micro controller in here, we will talk about programming the communication modules in this post and save talk about power supply for a following post.
     Anaren Booter Pack has two boards with Anaren RF chips pre-installed, plus two microcontrollers pro-flashed with Anaren software stack. “It is all about the protocol stack” according to Anaren; it is open source and based on Texas Instruments Simplicity protocol stack. While their documentation is kind of detailed for almost every important function in the stack, the length of the code is terrible to say the least. 
     After spending a week on understanding where/what function to modify in Anaren protocol stack, I was confessed that there is some price to pay for their protocol stack and the graphical user interface that they advertised.
Figure 1 Anaren GUI, note the windows showing RSSi and Temperature
        
As you can see above, many options for the RF chip can be controlled from GUI; almost all the parameters including: transmit power ( tx power), transmit frequency, channel, and FCC/ETSI compliance. Furthermore, you can see actual serial data communicated between the micro controller and the RF chip, done through SPI. Off course, the GUI has two windows to display the received signal strength on each chip and the temperature of each chip, yes TI has built in functions to measure the temperature, battery strength,…etc. Actually you will learn in the end of this post that TI does a very good job of providing support to their chips, unlink Anaren.Now, do not get me wrong!! I have to be thankful for humble price of their board, nicely labeling it, effort made to document functions in their stack and providing two versions of their protocol stack: one for Code Composer Studio and one for IAR workbench for TI MSP430 environment. 
Figure 2 Anaren Protocol Stack (IAR Embedded Workbench for MSP430 Environment)

     Lines and lines of code is what you get when you look into their protocol stack. As you can see above, main components include FCC/ETSI setting, application layer, protocol layer and the framework layer. The later is what we need to modify in most cases to make advantage of Anaren protocol stack. The application layer code, as name implies, is made of the set of instruction to allow successful communication between the nodes and the hub; the main topology is Star topology. In addition to data exchange (data/configuration data), this layer implements a full communication protocol: adding/removing a node from the network (assigning node ID), network validation, setting cycle time and radio sleep/wake process. The application layer intended to facilitate communication between the RF module and the Launch Pad through SPI protocol (to change settings, to receive sensor data and to listen to incoming packets received on the RF module). As we just mentioned, to make any advantage of the protocol stack you must manipulate the framework layer to make it interface your hardware used, like sensors, batteries, display, …etc.  
      Yes, you are right, if you do not like it why use it, probably that is what you are thinking. Let me explain the problems you come to meet once you try to understand/used Anaren protocol stack:


  1.      IAR workbench for MSP430 environment has a limitation of 2k byte of code; when you try to compile and load a large program like Anaren protocol stack you will get a message “code size exceeds limit for this version”
  2.  Code Composer version of the protocol stack I have not tried but you can figure from feedback that it is not easy to use it
  3.  Protocol Stack has too many layers; it is well organized for someone who wrote it. But if you want to tweak the code to achieve certain programming task it is a nightmare to go through whole stack.
     One thing tempts you to think of alternatives to Anaren code is Texas Instruments resources, starting with code snippet for many modules in their micro controller to Simplicity protocol stack written by Texas Instruments. In short, the learning curve for Anaren code is equal to going through Texas Instruments code available on line and starting to tweak them to you own desire. Remember Texas Instruments warning about side effects when combining their code snippet and not making your own program.
      On lines of what we mentioned above, you can find here code to run Anaren RF modules based on the code provided by Texas Instruments for allowing communication between chip CC2520/CC110L and a TI board, like Launch Pad or EZ430 board.  An interrupt coming on the SPI pin (pin 1.6) will indicate the RF chip received something, and when you want to send something you just put it on the SPI pin and let the RF chip send it. Basically, you will use the RF chip as queue: allow it to transmit anything that it gets on the SPI port and allow it to write to SPI port anything it receives. The author of this code added a mechanism to check for successful transmission of a packet, an acknowledgment sent from the receiver on the other side. Obviously, this approach does not work well when you have a sequence of data to transmit. According to comments from people using this code, it can be used with more than one transmitter/receiver talking to the hub node, I can not refute or confirm.  I changed the main program in the code above to make it suit my purpose; turn ON RED LED on one Launch Pad once motion is detected on the other Launch Pad. 


      Below you will find a video showing how to use code above, after some modification, to transmit the status of PIR sensor to anther Anaren RF Module. In the video you will note a booster circuit that we will talk about in a following post, please stay tuned.




Sunday, August 24, 2014

Infrared, wireless and MSP430



     Couple of years ago, Anaren marketed a radio frequency chip with an integrated antenna working at 900Mhz and based on Code Division Multiple Access Technology (CDMA) technology. Their product was based on Texas Instruments (TI) cc1110 chip and thus TI supported Anaren to market the booster pack board. In addition to anaren RF chip, the booster pack included a board having a prototyping area and a space to place a TI msp430 microcontroller. Off course, Anaren’s booster pack would best work with TI msp430 Launch Pad, see pictures below.
Figure 1 from right to left Anaren booster pack, TI Luanch Pad, and PIR motion detector sensor


     Now, Anaren have their Zigbee chip, Bluetooth chip and finally the celebrated Bluetooth SMART chip. Since their first RF chip (CDMA, 900MHz) was soled at a humble price, and because taking this course helped me to know how to program msp430 ( had to buy and use a TI msp430 lunch pad to do assignments!), I have decided buy one of Anaren booster pack and play around with it. The booster pack has two boards with Anaren RF chips, two microcontrollers pro-flashed with Anaren software stack. Since the later is the most important part in Anaren product, this post will mainly talk about programming the msp430 micro controller to do a certain task involving RF communication. First I had to establish communication between the boards without adding any payload from an external source, this was the easy part. See this link and picture below.





     While experimenting with the booster pack, I needed payload to transmit over the radio frequency link. There were many options including Boolean one/zero, digital data from a sensor, analog data converted by microcontroller to digital data stream. The choices are governed by the fact that booster pack is best used with msp430 launch kit. My choice was a simple one/zero coming from a passive infrared sensor (PIR sensor). You can buy PIR sensor from Radio shack or you can order it from Parallex website. The sensor is made of a basic Pyroelectric sensor and a Fresnel lens covering the sensor; the later is made of a material that pass infrared spectrum between 8-14µm only. Pyroelectric sensor is divided into two half; each half will detect the infrared level on its side as shown below. When both sides reports same levels of infrared they will cancel each other out and no motion is reported. Now parallax claims a field of view (FOV)of 90 degrees; for a explanations of FOV you can see this link (one of my favorite blogs).


Figure 2 Radiated Spectrum with Infrared light wave length marked
 
Picture courtesy of http://electronicsgurukulam.blogspot.com
     

     The programming task of any application involving the booster pack is to allow the micro controller to send and receive data over the radio frequency link and in the same time process data coming from an external source. The normal solution to this problem was to use interrupts.
     Since I had some cool project in mind, the following requirements were already set as the goal of my program:
Upon detecting motion, turn on a led,
As long as motion continues, keep led on,
If motion stops, do not turn led off until a certain time period has elapsed with no motion.