Saturday 31 March 2012

Global Positioning System – How does the receiver calculate the range from satellites?

It is now clear from the previous discussion that the receiver has to calculate the distance of the GPS antenna (range) w.r.t each of the satellites that it is tracking1.

The GPS satellite signal structure plays a major role in this range estimation. GPS transmissions utilize Direct Sequence Spread Spectrum (DSSS CDMA) modulation technique in which each satellite is associated with a unique code (called the Pseudo-random code or PRN code). The data from each satellite is first encoded using this PRN code and then transmitted using BPSK modulation.

There are two types of codes that a GPS satellite uses – the coarse acquisition or the C/A code and the precise P code. Most of the commercial GPS equipments only utilize the C/A code for position determination (More on the signal structure in future blogs). For the moment let us just note that these codes are a special category of PRN codes called the “Gold codes” which have exceptional auto-correlation and cross-correlation property. These properties mean that –

  • The PRN code of a satellite has very little or no similarity with the shifted version of itself
  • The PRN code of any one satellite has very little or no similarity with the PRN codes (even shifted versions) of all other satellites

Hence in order to decode the data from the satellite, the receiver must produce a replica of the PRN code (which acts like a key to the locked data), which not only matches with the satellite Id but also matches the time shifts incurred due to propagation from satellite t user. Let us see this in more detail.

Consider the following case in which the satellite has transmitted the signal at t = t0 s. But due to the propagation delay, it has reached the receiver after a delay of td seconds –

The task of the receiver is thus to generate the replicas of the PRN code for the satellite with all possible shifts and determine that amount of shift for which the incoming PRN code matches the generated code (i.e. has the  maximum correlation).
Now, if the time at which the satellite has transmitter the signal is known (t0) and the satellite clock and receiver clock are in perfect synchronization, then the shift required to match the incoming signal would exactly provide us with the propagation delay td. The range or the distance is immediately determined as this ∆t multiplied by the speed of light c (approximately 3 x 108 m/s).

But, the story is not that simple. The satellite clock is a very high precision atomic clock and the clock at the receiver is a low precision clock. Hence the propagation delay thus obtained suffers from what is called “user clock bias”.  One good thing about this clock bias is that since all the satellites are perfectly synchronized (or in other words, their errors can be estimated to high degree of accuracy), this user clock bias is a common error to all the satellite signals. This clock bias is the fourth variable in the range equations that needs to be estimated.


The range information thus obtained does not truly provide us with the geometric range of the satellite to the user but contains
  1. Geometric range from satellite to user
  2. User clock bias factor
  3. Offset between the system time and satellite clocks
  4. Other delays due to atmospheric errors (ionospheric and tropospheric)
Hence this range is referred to as “Pseudo range” rather than actual range.


Let us assume that the satellite clock bias can be accurately estimated and the atmospheric errors can be neglected (as of now). We can thus construct the range equations from the pseudo-range measurements from (at-least) four satellites as:

R1=√((x1 - xu)2 + (y1 - yu)2) + (z1 - zu)2) + ctu

R2=√((x2 - xu)2 + (y2 - yu)2) + (z2 - zu)2) + ctu

R3=√((x3 - xu)2 + (y3 - yu)2) + (z3 - zu)2) + ctu

R4=√((x4 - xu)2 + (y4 - yu)2) + (z4 - zu)2) + ctu

Where,
  • R1 to R4 are the pseudo-ranges from four satellites being tracked
  • (x1,y1,z1) correspond to the position of satellite 1 in x, y, z coordinates (and similarly for other satellites)
  • (xu,yu,zu) correspond to the position of user in x, y, z coordinates is the range due to user clock bias
Solving these equations for a Least-Square solution yields us the estimations of the user position.
The GPS system not only provides us with accurate position information but also accurate velocity and time information as well. Hence the complete GPS solution is called a PVT solution (Position, Velocity and Time). We shall discuss more on how each of them is extracted in future blogs.
1Tracking is a process of continuously monitoring the satellite signal parameters and extracting information from them

Saturday 17 March 2012

Sending SMS using AT Commands

This article describes sending a SMS from a Microcontroller through a GSM modem using AT Commands. through RS232. AT commands can be sent to a GSM modem via a computer serial port or from the serial port of a 8051 Microcontroller.

Computer serial port


1. Connect your GSM modem to the computer serial port. New systems nowadays dot not have serial port, hence you would need to buy a USB to serial converter and connect the GSM modem to it.

2. If you are using Windows XP® OS, open Programs -> Accessories -> Communications -> HyperTerminal

3. Select the COM port you have the modem connected to.

4. Check the port settings, make sure that the baud rate matches with that of the GSM modem and and also that the Flow Control is set to "None".

5. Type the AT Commands below in the HyperTerminal Editor

AT+CMGF = 1 and Enter
AT+CMGS="+919449XXXXXX" and Enter
"Electronicprojs.Blogspot.com" and Hit CTRL+Z

6. In Windows 7® OS though, there is no hyperterminal program inbuilt. You will have to download a similar one. There are many good free programs available.

7. You would need to note that in this case we are connecting the serial port cable from Female pin (GSM Modem) to Male pin (Computer). Hence no crossing is required. In other words, we should use a straight cable.

8051 MicroController Serial port


1. 8051 SFR's are programmed for a baud rate of 9600.

2. Send the AT commands in #5 above through code. For Enter use escape character "\r" and for CTRL+Z use ASCII 0x1A.

3. The serial port cable is connecting from Female pin (GSM Modem) to Female (8051 Board). So you need a have a female to male converter. Also, make sure that the Rx and Tx inside in the converter are crossed. In otherwords, the Rx pin of GSM Modem should go to Tx pin of 8051 microntroller. This is called a crossed cable.

4. Below is the C program using Keil® Compiler for 8051. We added infinite while loop after the sendsms() routine because otherwise we found that the code compiled was sending the SMS in a infinite loop.

Note : Beginners always complain about their code working through serial port of a computer but the same not working through chip. It is very essential to understand the difference between crossed cable and straight cable as well as the pins configurations of male and female connectors before starting.

C program

#include <REGX51.H>
#include <AT89X51.H>

unsigned char *command_AT = "AT\r";
unsigned char *command_CMGF = "AT+CMGF=1\r";
unsigned char *command_CMGS = "AT+CMGS=\"+919449XXXXX\"\r";
unsigned char *message = "electronicprojs.blogspot.com";
unsigned char CTRLZ = 0x1A;

void puts(unsigned char* ptr);
void putc(unsigned char chr);
void sendsms(void);
void initialize();

main()
{
initialize();
sendsms();
while(1);
}

void initialize()
{
SCON  = 0x50;   /*SCON: mode 1, 8-bit UART, enable receive      */
TMOD |= 0x20;   /*TMOD: timer 1, mode 2, 8-bit                  */
TH1   = 0xFD;   /*TH1:  for 9600 baud                           */
TR1   = 1;      /*TR1:  timer 1 run                             */

}

void sendsms()
{
puts(command_AT);
puts(command_CMGF);
puts(command_CMGS);
puts(message);
putc(CTRLZ);
}

void puts(char* p)
{
char *temp = p;  /*temp pointer so that the actual pointer is not displaced */
while(*temp != 0x00)
{
putc(*temp);
temp++;
}
}

void putc(unsigned char chr)
{
SBUF = chr;
while(TI==0);  /*Wait until the character is completely sent */
TI=0;                    /*Reset the flag */
}

Tuesday 6 March 2012

Global Positioning System (GPS) - Introduction

Global positioning system (GPS) is a satellite based navigation system that provides the user with accurate position and time information. Today we find GPS receivers in almost every field – right from car navigations systems to missile launches, mobiles to aircraft - GPS is becoming an integral part of our lives. Here is an attempt to make the readers better understand the GPS system and to some extent, the techniques involved in its working

GPS consists of a constellation of satellites (at least 24) that are deployed into orbits of 20000km. The data transmitted by the satellites is a Direct sequence spread spectrum (DSSS) signal with each satellite having a unique PRN (pseudo random noise) code of its own. The satellites are identified by this unique code that is a part of the signal that they transmit. The satellites have Ids from 1 to 32.

The orbits are inclined at an angle of 55 degrees to the equatorial plane. The choice of orbit is such that there are at-least 5 satellites visible to a GPS receiver (with an open sky view) from any point on earth. The satellites orbit the earth with an orbital period of 12hrs. Hence the visibility scenario at any point on earth repeats itself every 24 hrs. It simply means that, if at a particular point on earth, I see satellites with Ids 2, 4, 10, 17, 25, and 20 then I would see the same set of satellites tomorrow at the same time.

The basic idea of GPS positioning – Trilateration

Trilateration is the basic theory behind GPS positioning. Let me explain this in very simple terms.Consider a planar (2D) system in which I have three reference points or base stations (BS) which are transmitting signals and a mobile station (MS) or a receiver capable of receiving and decoding the signal from these base stations. The positions of these BS are fixed and are known to the MS.

Let us assume that the data sent by each of the BS has sufficient information such that the MS is able to calculate the accurate range or distance from the BS i.e. if MS decodes signal from BS1, it can obtain its exact distance from BS1.


Now, I know my distance (d1) from BS1 and as said earlier, I know the location of BS1. This means that the position of the MS is anywhere on the circle centered at BS1 and with a radius d1.




Similarly if the MS can decode the signal from BS2 and obtain the distance d2 from it, then the ambiguity associated with the position of MS reduces to the intersection of the two circles (with BS1 and BS2 as centers and d1 and d2 as radius respectively). Hence the position is either point A or point B as shown in the figure. Extending this idea to one more BS reduces the ambiguity to a point that is the intersection of all the three circles thus formed.


Now that you are convinced with the position determination in 2D space, we can extend the same to position determination in 3D space with MS being your GPS receiver and BS being the satellites in orbit. The range information from one satellite would give you a sphere, two satellites would give you a circle and three satellites would give you two points. One of these points, the true position will be towards the surface of the earth and the other will be on the other side of the satellite orbit and is discarded.

NOTE:
  • Even though it seems that only three satellites are essential for position determination, in practice 4 are required due to the low precision clock on the receiver (more about this later)
  • The positioning can also be thought of as a linear system of three unknowns (position co-ordinates x, y, and z) of the receiver, which requires at-least three equations to solve. These three equations are obtained by three satellites.
  • The fourth unknown called the user clock bias requires the range information from the fourth satellite.

Sunday 4 March 2012

Ultrasonic Transmitter and Receiver


Introduction


Ultrasound is a form of cyclic sound pressure with a frequency greater than the upper limit of human hearing, this limit being approximately 20KHz. Some animals – such as dogs, dolphins, bats, and mice – have an upper frequency limit that is greater than that of the human ear and thus can hear ultrasound. Ultrasonic waves, however, being inaudible to humans, have little or no effect on the ear even at high intensities. Ultrasonics have found wide industrial use like nondestructive testing an object is irradiated with ultrasonic waves; variation in velocity or echo of the transmitted waves indicates a flaw. Fine machine parts, ball bearings, surgical instruments, and many other objects can be cleaned ultrasonically. Metals can be welded together by placing their surfaces in contact with each other and irradiating the contact with ultrasound. The molecules are stimulated into rearranged crystalline form, making a permanent bond. Ultrasonic whistles, which cannot be heard by human beings, are audible to dogs and are used to summon them.

Transmitter


Working

  • The 555 IC is used here as an astable multivibrator
  • It oscillates at a frequency of about 40kHz. An ultrasonic transmitter transducer is used here to transmit ultrasonic sound very effectively
  • A 10k pot is provided to vary the frequency of the astable multivibrator to adjust for maximum performance
  • During the positive half cycle npn transistor SL100 is turned on while during the negative half cycle pnp transistor SK100 is turned on effectively doubling the peak to peak voltage fed to the ultrasonic transducer
Design

f = 1 / (0.693 * ( Ra+ 2Rb)*C))
f = 40kHz which is the center frequency of most ultrasonic transducers
Let C  = 680pF     
      Rb = 10kOhm
Let Ra be made up of two resistors, fixed Ra1 and variable VRa so that
      Ra = Ra1  + VRa
Let Ra1 = 4.7kOhm
Then VRa = 16.47kOhm so that Ra ≈ 22kOhm
Practically we use VRa = 20KOhm variable resistor and tune it

Note : In our case, the closest capacitor to 680pF available in the market was 560pF. We replaced the same in the circuit and it worked with tuning of VRa


Receiver

  • When there is an obstacle the ultrasonic sound is received by ultrasonic receiver transducer. It converts it to electrical variations of the same frequency
  • Ultrasonic receiver also uses a two-stage amplifier, a rectifier and an operational amplifier in non-inverting mode. Output of op-amp is connected to a buzzer
  • These signals are amplified. The amplified signals are then rectified and filtered
  • The filtered DC voltage is given to non inverting pin of high frequency op-amp CA3140. The inverting pin of op-amp is connected to a variable resistor
  • The 9v ouput voltage of comparator is made microcontroller compatible by using a 7805 voltage regulator


Circuit Diagram



Ultrasonic Transmitter and Receiver Circuit
Ultrasonic Transmitter and Receiver Circuit

People Counting Machine with GSM

The main objective of this project is to design a system which counts the number of people present inside a premises with the count being sent automatically as an SMS upon dialing the phone number.


It consists of 3 modules

1. Infrared Transmitter and Receiver
There are two of them say IR1 and IR2. Breaking the beam of IR1 first and then IR2 will increment the count by 1 where as breaking the beam IR2 and then IR1 will decrement the count. The output of IR1 and IR2 are connected to microntroller interrupts INT0 and INT1 respectively. Complete design of IR Tx and Rx can be found here : Infrared Beam break Detector


2. Microncontroller with LCD
The microcontroller used here is 89c51. INT0 and INT1 of the micronctroller is connected to output of IR1 and IR2 respectively. It is connected to a GSM module via a serial port. And the microncontroller is also connected to a LCD which displays the total count at any given point of time. The microntroller increments or decrements the count based on weather INT0 interrupt occurs first and then INT1 or vice versa and continuously displays on the LCD. Micronctroller will also receive a serial interrupt when there is an incoming call in whch time it will read the phone number, disconnect and send the total count as a SMS

3. GSM Module
The microcontroller sends AT commands to GSM module to read the phone number, disconnect and send an SMS to the calling number. Below are the AT commands used.

1. Disconnect a call
ATH  and Enter

2. Read the phone number of an incoming call
  • Set the below AT command only once
  • AT+CLIP=1 and Enter
  • When there is a incoming call, the data from GSM will be similar to below for default settings
    • RING
      +CLIP: "+919449XXXXXX",145,"","",0
      RING
      +CLIP........
    • Read the phone number above into an array and send the SMS
    3. Send an SMS

    AT+CMGF=1 and Enter
    AT+CMGS="+919449XXXXXX" and Enter
    "Hello World" and CTRL+Z

    During programming CTRL+Z requires to be sent as 0x1A Ascii character while the escape character for Enter is '\r'. For better understanding on sending a SMS and C code, refer to Sending SMS using AT commands