Sunday, 28 August 2016

Lowest square wave frequency that we can generate using mode 1 and mode 2 At XLAT=16MHZ

2KHZ Frequency Wave Generation Programme:


#include<reg51.h>
sbit OUTPUT=P1^7;
void delay()
{
    unsigned int i;
    TMOD=TMOD & 0xF0;
    TMOD=TMOD | 0x01;
    TH0=0xFD;
    TL0=0x66;
    TR0=1;
    while(TF0==0);
    TR1=0;
}
void main()
{
    while(1)
    {
        OUTPUT=1;
        delay();
        OUTPUT=0;
    }
}



Lowest Frequency Generation Explanation:


 Lowest Square Wave Frequency Means Highest Time Delay.

 Here Our Crystal Or Oscillator Frequency Is 20KHZ.
 So Our CP=12/16KHZ=0.75 micro
 To Get Maximum Time Delay We Must Have Value Of THX-TLX is 0(zero).

For Mode 1:
    Mode 1 is 16bit-Timer.
    When We Take Initial Value as a 2^16 Than THX-TLX become 0(zero).
    so Initial Value= 2 ^ 16 = 65536
    And We Know CP=0.6 micro
    So TIME= CP * Initial Value
           = 0.75 * 10^-6 * 65536
           = 49152 microsecond
    Now Frequency=1/TIME
                 =1/(49152 * 10^-6)
                 =20.3450 HZ

For Mode 2:
    Mode 1 is 8bit-Timer.
    When We Take Initial Value as a 2^16 Than THX-TLX become 0(zero).
    so Initial Value= 2 ^ 8 = 256
    And We Know CP=0.6 micro
    So TIME= CP * Initial Value
           = 0.75 * 10^-6 * 256
           = 192 microsecond
    Now Frequency=1/TIME
                 =1/(192 * 10^-6)
                 =5.2083 KHZ

Program Timer 0 to generate a square wave of 0.5KHz

 XLAT = 20MHz


#include<reg51.h>
sbit OUTPUT=P1^7;
void delay()
{
    unsigned int i;
    TMOD=TMOD & 0xF0;
    TMOD=TMOD | 0x01;
    TH0=0xF2;
    TL0=0xFB;
    TR0=1;
    while(TF0==0);
    TR1=0;
}
void main()
{
    while(1)
    {
        OUTPUT=1;
        delay();
        OUTPUT=0;
    }
}

8051 C program to generate wave of 60 % duty cycle(XLAT=12MHz)

#include<reg51.h>
sbit OUTPUT=P1^7;
void delay(unsigned in T)
{
    unsigned int i;
    TMOD=TMOD & 0x0F;
    TMOD=TMOD | 0x10;
    for(i=0;i<T;i++)
    {
        TMOD=TMOD & 0xF0;
        TMOD=TMOD | 0x01;
        TR0=1;
        while(TF0==0);
        TR0=0;
    }
}
void main()
{
    while(1)
    {
        OUTPUT=1;
        delay(60);
        OUTPUT=0;
    }
}

Genrate Frequancy In 8051 GPIO Pin Using Switch

A switch is connected to pin P1.2. Write an 8051 C program to monitor SW and create the following frequencies on pin P1.7:
SW = 0 :-  500 Hz
SW  = 1 :- 750 Hz
XLAT=14MHz





#include<reg51.h>
sbit S=P1^2;
sbit OUTPUT=P1^7;
void delay_1(unsigned int T)
{
    unsigned int i;
    TMOD=TMOD & 0xF0;
    TMOD=TMOD | 0x01;
    for(i=0;i<T;i++)
    {
        TH0=0xFC;
        TL0=0x18;
        TR0=1;
        while(TF0==0);
        TR0=0;
    }
}
void delay_2(unsigned int T)
{
 unsigned int i;
 TMOD=TMOD & 0xF0;
     TMOD=TMOD | 0x02;
 TH0=255;
 for(i=0;i<T;i++)
 {
  TR0=1;
  while(TF0==0);
  TR0=0;
 }
}
void main()
{
    if(S==0)
    {
        OUTPUT=1;
        delay_1(2);
        OUTPUT=0;
    }
    else
    {
        OUTPUT=1;
        delay_2(1333);
        OUTPUT=0;
    }
}

8051 C program to toggle all bits of P2 continuously every 500 ms.


A. Use Timer 1, mode 1 to create delay.





  1. XLAT = 11.0592 MHz

    #include <reg51.h>
    #define TOG P2;
    void delay(int time)
    {
                    unsigned int i;
                    TMOD=TMOD & 0x0f;
                    TMOD=TMOD | 0x10;

                     for(i=0;i<time;i++)
                     {
                    TH1=0xfc;
                    TL1=0x66;
                    TR1=1;
                     while(TF1==0);
                    TR0=0;
                    }
            }

          void main()
         {
                    while(1)
                    {
                    TOG=0xff;
                    delay(500);
                    TOG=0x00;
                    delay(500);
                    }
          }









  2. XLAT = 12 MHz

    #include <reg51.h>
    #define TOG P2;
    void delay(int time)
    {
                        unsigned int i;
        TMOD=TMOD & 0x0f;
        TMOD=TMOD | 0x10;

        for(i=0;i<time;i++)
        {
            TH1=0xfc;
            TL1=0x18;
            TR1=1;
            while(TF1==0);
            TR0=0;
        }
    }
                   
    void main()
    {
        while(1)
        {
            TOG=0xff;
            delay(500);
            TOG=0x00;
            delay(500);
        }
    }


















  3. XLAT = 22 MHz

    #include <reg51.h>
    #define TOG P2;
    void delay(int time)
    {
        unsigned int i;
        TMOD=TMOD & 0x0f;
        TMOD=TMOD | 0x10;
                   
                       for(i=0;i<time;i++)
        {
            TH1=0xf8;
            TL1=0xd7;
            TR1=1;
            while(TF1==0);
            TR0=0;
        }
    }

    void main()
    {
        while(1)
        {
            TOG=0xff;
            delay(500);
            TOG=0x00;
            delay(500);
        }
    }

















    B. Use Timer 0 , mode 2 to create delay.



  1. XLAT = 11.0592 MHz

    #include <reg51.h>
    #define TOG P2;
    void delay(int time)
    {
        unsigned int i;
        TMOD=TMOD & 0xf0;
        TMOD=TMOD | 0x02;
        TH0=0xA3;
        for(i=0;i<time*10;i++)
        {
            TR0=1;
            while(TF0==0);
            TR0=0;
        }
    }

    void main()
    {
        while(1)
        {
            TOG=0xff;
            delay(500);
            TOG=0x00;
            delay(500);
        }
    }

















  2.  XLAT = 12 MHz

    #include <reg51.h>
    #define TOG P2;
    void delay(int time)
    {
        unsigned int i;
        TMOD=TMOD & 0xf0;
        TMOD=TMOD | 0x02;
        TH0=156;
        for(i=0;i<time*10;i++)
        {
            TR0=1;
            while(TF0==0);
            TR0=0;
        }
    }

    void main()
    {
        while(1)
        {
            TOG=0xff;
            delay(500);
            TOG=0x00;
            delay(500);
        }
    }
















  3.  XLAT = 22 MHz



    #include <reg51.h>
    #define TOG P2;
    void delay(int time)
    {
        unsigned int i;
        TMOD=TMOD & 0xf0;
        TMOD=TMOD | 0x02;
        TH0=72;
        for(i=0;i<time*10;i++)
        {
            TR0=1;
            while(TF0==0);
            TR0=0;
        }
    }

    void main()
    {
        while(1)
        {
            TOG=0xff;
            delay(500);
            TOG=0x00;
            delay(500);
        }
    }

Wednesday, 1 June 2016

Type Of Motion Sensor

Types of Motion Sensors

Passive Infrared (PIR)


Detects body heat (infrared energy). Passive infrared sensors are the most widely used motion in home security systems. When your system is armed, your motion sensors are activated. Once the sensor warms up, it can detect heat and movement in the surrounding areas, creating a protective "grid." If a moving object blocks too many grid zones and the infrared energy levels change rapidly, the sensors are tripped.

MircoWave (MW):


Sends out microwave pulses and measures the reflection off a moving object. They cover a larger area than infrared sensors, but they are vulnerable to electrical interference and are more expensive.

Dual Technology Motion Sensors:


Motion sensors can have combined features in an attempt to reduce false alarms. For example, a passive infrared (PIR) sensor could be combined with a microwave sensor. Since each operates in different areas of the spectrum, and one is passive and one is active, Dual Technology motion sensors are not as likely as other types to cause false alarms, because in order for the alarm to be triggered, both sensors have to be tripped. However, this does not mean that they never cause false alarms.

Area Reflective Type:

Emits infrared rays from an LED. Using the reflection of those rays, the sensor measures the distance to the person or object and detects if the object is within the designated area.

Ultrasonic:

Sends out pulses of ultrasonic waves and measures the reflection off a moving object.

Vibration:

Detects vibration. These can be purchased or easily made at home. A homemade vibration sensor uses a small mass on a lever, which is activated by a switch to an alarm when it vibrates. Homemade motion sensors can work, but they can also be unreliable.


Link

http://www.safewise.com/resources/motion-sensor-guide