Wednesday, December 13, 2017

Programs for Arm Embedded Lab


                                   PINOUT of LPC 1768

LED:light-emitting diode (LED) is a two-lead semiconductor light source. It is a p–n junction diode that emits light when activated [forward biased]. When a suitable current flows through the leads, electron hole recombination takes place within the device, releasing energy in the form of photons. This effect is called electroluminescence, and the color of the light (corresponding to the energy of the photon) is determined by the energy band gap of the semiconductor.


Application: LEDs were often used as indicator lamps for electronic devices, replacing small incandescent bulbs. They were soon packaged into numeric readouts in the form of seven-segment displays and were commonly seen in digital clocks.
LED uses fall into four major categories:
  • Visual signals where light goes more or less directly from the source to the human eye, to convey a message or meaning
  • Illumination where light is reflected from objects to give visual response of these objects
  • Measuring and interacting with processes involving no human vision[174]
  • Narrow band light sensors where LEDs operate in a reverse-bias mode and respond to incident light, instead of emitting light

Advantages:LEDs have many advantages over incandescent light sources, including lower energy consumption, longer lifetime, improved physical robustness, smaller size, and faster switching.

The color of light emitted from an LED is neither coherent nor monochromatic, but the spectrum is narrow with respect to human vision,


Reasons for using Active LOW logic for LED in board design:
  • Let us assume that you want to choose a device between n-channel MOSFET and p-channel MOSFET for your application. One would always prefer going for n-channel as electrons are the majority carriers in this type of device and have the highest mobility then holes. In this case, when the transistor is ON, the output is driven low. So, a normal condition is that output is high and when transistor in on output is low. This is one of the factor which makes implementation of active low state easy. Same mobility case applies to BJT also where NPN is preferred compared to PNP.
  • Active LOW always helps eliminate indeterminate states due to improper supply voltages. 
  • A genuine reason is that it is easier to pull down a signal than pulling it up. 
  • Under a Active low condition, it is always easy to use wired-or condition and apply common reset to several chips. So, fanout can be increased

To blink an LED
/*   Blink LED
                 LED is connected to Port 2.12
*/
Block Diagram


#include <LPC17xx.h>

int main( void )
{
                int i, n=1000000;
                SystemInit();                     //System initialization
                SystemCoreClockUpdate();  // Clock initialization

              // Function Selection as GPIO
                LPC_PINCON->PINSEL4 = 0X00000000;   // PORT 2, 12th bit as zero, P2.12 as GPIO

                // set Direction of 12th pin as output by passing 1
                LPC_GPIO2->FIODIR = 0x00001000;

                while( 1 )
                {             
                                LPC_GPIO2->FIOCLR = 0X00001000;   // 1 Turn on LED
                                for( i = 0; i < n; i++ );                        // delay
                                LPC_GPIO2->FIOSET = 0X00001000;   // 1 Turn OFF LED
                                for( i = 0; i < n; i++ );                        // delay
                }
}

*****************************************************************************************
Push Button:push-button (also spelled pushbutton) or simply button is a simple switch mechanism for controlling some aspect of a machine or a process. Buttons are typically made out of hard material, usually plastic or metal. The surface is usually flat or shaped to accommodate the human finger or hand, so as to be easily depressed or pushed. Buttons are most often biased switches, although many un-biased buttons (due to their physical nature) still require a spring to return to their un-pushed state.

Applications:The "push-button" has been utilized in calculatorspush-button telephoneskitchen appliances, and various other mechanical and electronic devices, home and commercial.

Pull-up Resistor mode:

 Lets assume Our LPC1768 port pin is assigned GPIO functionality and If there is nothing connected to the pin and our program tries to read the state of the pin, now the question is, will it be high (pulled to VCC) or low (pulled to ground)? It is difficult to tell, isn't it?. This phenomena is referred to as floating
To prevent this unknown state, a pull-up or pull-down resistor will ensure that the pin is in either a high or low state, while also using a low amount of current.

With a pull-up resistor, the input pin will read a high state when the button is not pressed. In other words, a small amount of current is flowing between VCC and the input pin (not to ground), thus the input pin reads close to VCC. When the button is pressed, it connects the input pin directly to ground. The current flows through the resistor to ground, thus the input pin reads a low state.

By default in LPC1768 onboard pullup resistances will be activated or we can make use of PINMOD register to switch between pullup, pulldown resistance modes, neither pullup nor pulldown and repeater modes.

The value of the pull-up resistor needs to be chosen to satisfy two conditions:
  1. When the button is pressed, the input pin is pulled low. The value of resistor R1 controls how much current you want to flow from VCC, through the button, and then to ground.
  2. When the button is not pressed, the input pin is pulled high. The value of the pull-up resistor controls the voltage on the input pin.
The general rule for condition 2 is to use a pull-up resistor (R1) that is an order of magnitude (1/10th) less than the input impedance (R2) of the input pin.

// program to read a push button switch position and turn on or off the LED
/*  
                 Push button key is connected to P2.11 LED is connected to Port 2.12
*/
Block Diagram

case a: switch open

                                                                     case b: switch close

  #include <LPC17xx.h>

int main( void )
{
  unsigned int key;
  SystemInit();                                      // System initialization
  SystemCoreClockUpdate();              // Clock initialization

// Function Selection
 LPC_PINCON->PINSEL4 = 0X00000000;   // PORT 2, 12th pin function is governed by 25:24
//bits of PINSEL4 reg, by writing value 0 0 on to 25 24 we can get GPIO functionality of P2.12

// set Direction of 12th pin as output by passing 1
// set Direction of 11th pin as input by passing 0
 LPC_GPIO2->FIODIR = 0x00001000;

// reading key status continuously
while( 1 )
          {
               Key = LPC_GPIO2->FIOPIN; //reading status of Port2 and storing it in variable key
               key = key & 0x00000800 ;    //bitwise and operation, as I need to check only 11th bit value

                  if(key == 0x00000800)   //KEY IS NOT PRESSED   if(key & 0x0000800)
                        {
                                   LPC_GPIO2->FIOSET = 0X00001000;                    //Off
                                 }
                  else                   
                        {                                                               
                                   LPC_GPIO2->FIOCLR = 0X00001000;  //  Turn On LED
                                 }                                           
                   }                          
}
click here to Download the C file

or copy paste the link:https://drive.google.com/file/d/1EFcoyLD0m9PI6zxFapcEjknBNN8U6y2l/view
********************************************************************************

No comments:

Post a Comment

lab record

TECHNICAL SPECIFICATIONS of LPC1768 (15-16 of ARMCTXM3) ******************************************************************************...