Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1. Acknowledgement
2. Abstract
3. Introduction
4. Block Diagram
5. Circuit Diagrams
a. Power supply
b. Reset
c. Wireless Tachometer TX
d. Wireless Tachometer RX
e. LCD display
6. Hardware description
a. 89C51 micro controller
b. Crystal Oscillator
c. LCD
d. Voltage regulators
e. IR
7. Source code
8. Conclusion
9. Bibliography
Abstract:
This project ‘micro controller based contact less tachometer’ design makes use of 8051 micro
controller for interfacing to various hardware peripherals. Technology today is seeing its heights in all
the areas, especially in the area of Embedded Systems. It is true that every electronic gadget that is used
in daily life right from a PC keyboard to a refrigerator is an Embedded System. This it shows how vastly
the technology is expanding.
The current design is an embedded application which is used to calculate the speed of the motor
without the need of tachometer. In this application IR frequencies are used to calculate the speed of the
motor. Place the tx and rx in such a way that the IR transmitter continuously generates the infrared rays
and the receiver receives it. To the motor shaft arrange one circular arrangement having a small hole and
position it exactly at the middle of tx and rx arrangement in such a way that when the shaft rotates, only
at one point the IR rays falls on the rx.
Now make the motor to run at some speed. As usual the IR receiver receives the IR signals from
the transmitter when the motor was running for every one complete rotation. The IR receiver (TSOP)
sends these data to the micro controller; the controller compares the data and calculates the speed of
motor. Speed (in rpm) was displayed on the display unit (LCD). This method of calculating speed is
very inexpensive and cheap when compared to the tachometers available in the market.
Block diagram:
DISPLAY
UNIT
POWER
SUPPLY
TSOP
MICRO
CONTROLER 555 TIMER
IR
TRANSMITTER
Circuit Diagrams:
Power Supply Circuit:
Pin description:-
IR Sensors & LCD display circuit:
A) 8051 Micro controller:
Introduction:
Despite it’s relatively old age, the 8051 is one of the most popular microcontrollers in use today.
Many derivative microcontrollers have since been developed that are based on and compatible with--the
8051. Thus, the ability to program an 8051 is an important skill for anyone who plans to develop
products that will take advantage of microcontrollers.
Many web pages, books, and tools are available for the 051 developer. I hope the information
contained in this document/web page will assist you in mastering 8051 programming. While it is not my
intention that this document replaces a hardcopy book purchased at your local book store, it is entirely
possible that this may be the case. It is likely that this document contains everything you will need to
learn 8051 assembly language programming. Of course, this document is free and you get what you pay
for so if, after reading this document, you still is lost you may find it necessary to buy a book. This
document is both a tutorial and a reference tool. The various chapters of the document will explain the
8051 step by step. The chapters are targeted at people who are attempting to learn 8051 assembly
language programming. The appendices are a useful reference tool that will assist both the novice
programmer as well as the experienced professional developer.
That is to say, no knowledge of the 8051 is assumed--however, it is assumed you’ve done some
amount of programming before, have a basic understanding of hardware, and a firm grasp on the three
numbering systems mentioned above. The concept of converting a number from decimal to hexadecimal
and/or to binary is not within the scope of this document--and if you can’t do those types of conversions
there are probably some concepts that will not be completely understandable. This document attempts to
address the need of the typical programmer. For example, there are certain features that are nifty and in
some cases very useful--but 95% of the programmers will never use these features.
Types of Memory:
The 8051 has three very general types of memory. To effectively program the 8051 it is
necessary to have a basic understanding of these memory types.
On-Chip Memory refers to any memory (Code, RAM, or other) that physically exists on the
microcontroller itself. On-chip memory can be of several types, but we'll get into that shortly.
External Code Memory is code (or program) memory that resides off-chip. This is often in the
form of an external EPROM.
External RAM is RAM memory that resides off-chip. This is often in the form of standard static
RAM or flash RAM.
Code Memory:
Code memory is the memory that holds the actual 8051 program that is to be run. This memory
is limited to 64K and comes in many shapes and sizes: Code memory may be found on-chip, either
burned into the microcontroller as ROM or EPROM. Code may also be stored completely off-chip in an
external ROM or, more commonly, an external EPROM. Flash RAM is also another popular method of
storing a program. Various combinations of these memory types may also be used--that is to say, it is
possible to have 4K of code memory on-chip and 64k of code memory off-chip in an EPROM.
When the program is stored on-chip the 64K maximum is often reduced to 4k, 8k, or
16k. This varies depending on the version of the chip that is being used. Each version offers specific
capabilities and one of the distinguishing factors from chip to chip is how much ROM/EPROM space
the chip has. However, code memory is most commonly implemented as off-chip EPROM. This is
especially true in low-cost development systems and in systems developed by students.
Programming Tip: Since code memory is restricted to 64K, 8051 programs are limited to 64K. Some
assemblers and compilers offer ways to get around this limit when used with specially wired hardware.
However, without such special compilers and
Hard ware, programs are limited to 64K.
External RAM:
As an obvious opposite of Internal RAM, the 8051 also supports what is called External
RAM. As the name suggests, External RAM is any random access memory which is found off-chip.
Since the memory is off-chip it is not as flexible in terms of accessing, and is also slower. For example,
to increment an Internal RAM location by 1 requires only 1 instruction and 1 instruction cycle. To
increment a 1-byte value stored in External RAM requires 4 instructions and 7 instruction cycles. In this
case, external memory is 7 times slower! What External RAM loses in speed and flexibility it gains in
quantity? While Internal RAM is limited to 128 bytes the 8051 supports External RAM up to 64K.
Programming Tip: The 8051 may only address 64k of RAM. To expand RAM beyond this limit requires
programming and hardware tricks. You may have to do this "by hand" since many compilers and
assemblers, while providing support for programs in Excess of 64k, do not support more than 64k of
RAM. This is rather strange since it has been my experience that programs can usually fit in 64k but
often RAM is what is lacking. Thus if you need more than 64k of RAM, check to see if your compiler
supports it-- but if it doesn't, be prepared to do it by hand.
On-Chip Memory:
As mentioned at the beginning of this chapter, the 8051 includes a certain amount of on chip
memory. On-chip memory is really one of two (SFR) memories. The layout of the 8051's internal
memory is presented in the following memory map:
As is illustrated in this map, the 8051 has a bank of 128 bytes of Internal RAM. This Internal
RAM is found on-chip on the 8051 so it is the fastest RAM available, and it is also the most flexible in
terms of reading, writing, and modifying it’s contents. Internal RAM is volatile, so when the 8051 is
reset this memory is cleared. The 128 bytes of internal ram is subdivided as shown on the memory map.
The first 8 bytes (00h - 07h) are "register bank 0". By manipulating certain SFRs, a program may
choose to use register banks 1, 2, or 3. These alternative register banks are located in internal RAM in
addresses 08h through 1Fh. We'll discuss "register banks" more in a later chapter. For now it is
sufficient to know that they "live" and are part of internal RAM.
Bit Memory also lives and is part of internal RAM. We'll talk more about bit memory very
shortly, but for now just keep in mind that bit memory actually resides in internal RAM, from addresses
20h through 2Fh. The 80 bytes remaining of Internal RAM, from addresses 30h through 7Fh, may be
used by user variables that need to be accessed frequently or at high-speed. This area is also utilized by
the microcontroller as a storage area for the operating stack. This fact severely limits the 8051’s stack
since, as illustrated in the memory map, the area reserved for the stack is only 80 bytes--and usually it is
less since these 80 bytes has to be shared between the stack and user variables.
Register Banks:
The 8051 uses 8 "R" registers which are used in many of its instructions. These "R" registers are
numbered from 0 through 7 (R0, R1, R2, R3, R4, R5, R6, and R7). These registers are generally used to
assist in manipulating values And moving data from one memory location to another. For example, to
add the value of R4 to the Accumulator, we would execute the following instruction:
ADD A, R4
However, as the memory map shows, the "R" Register R4 is really part of Internal RAM. Specifically,
R4 is address 04h. This can be see in the bright green section of the memory map. Thus the above
instruction accomplishes the same thing as the following operation:
ADD A, 04h
This instruction adds the value found in Internal RAM address 04h to the value of the Accumulator,
leaving the result in the Accumulator. Since R4 is really Internal RAM 04h, the above instruction
effectively accomplished the same thing. But watch out! As the memory map shows, the 8051 has four
distinct register banks. When the 8051 is first booted up, register bank 0 (addresses 00h through 07h) is
used by default. However, your program may instruct the 8051 to use one of the alternate register banks;
i.e., register banks 1, 2, or 3. In this case, R4 will no longer be the same as Internal RAM address 04h.
For example, if your program instructs the 8051 to use register bank 3, "R" register R4 will now be
synonymous with Internal RAM address 1Ch. The concept of register banks adds a great level of
flexibility to the 8051, especially when dealing with interrupts (we'll talk about interrupts later).
However, always remember that the register banks really reside in the first 32 bytes of Internal RAM.
Programming Tip:
If you only use the first register bank (i.e. bank 0), you may use Internal RAM locations 08h
through 1Fh for your own use. But if you plan to use register banks 1, 2, or 3, be very careful about
using addresses below 20h as you may end up overwriting the value of your "R" registers!
Bit Memory:
The 8051, being a communications oriented microcontroller, gives the user the ability to access a
number of bit variables. These variables may be either 1 or 0. There are 128 bit variables available to the
user, numbered 00h through 7Fh. The user may make use of these variables with commands such as
SETB and CLR. It is important to note that Bit Memory is really a part of Internal RAM. In fact, the 128
bit variables occupy the 16 bytes of Internal RAM
From 20h through 2Fh. Thus, if you write the value FF h to Internal RAM address 20h you’ve
effectively set bits 00h through 07h. But since the 8051 provides special instructions to access these 16
bytes of memory on a bit by bit basis it is useful to think of it as a separate type of memory. However,
always keep in mind that it is just a subset of Internal RAM—and that operations performed on Internal
RAM can change the values of the bit variables.
Programming Tip: If your program does not use bit variables, you may use Internal RAM locations 20h
through 2Fh for your own use. But if you plan to use bit variables, be very careful about using addresses
from 20h through 2Fh as you may end up overwriting the value of your bits! Bit variables 00h through
7Fh are for user defined functions in their programs. However, bit variables 80h and above are actually
used to access certain SFRs on a bit-by-bit basis. For example, if output lines P0.0 through P0.7 are all
clear (0) and you want to turn on the P0.0 output line you may either execute:
Both these instructions accomplish the same thing. However, using the SETB command will turn on the
P0.0 line without affecting the status of any of the other P0 output lines. The MOV command effectively
turns off all the other output lines which, in some cases, may not be acceptable.
Programming Tip:
By default, the 8051 initializes the Stack Pointer (SP) to 08h when the microcontroller is booted.
This means that the stack will start at address 08h and expand upwards. If you will be using the alternate
register banks (banks 1, 2 or 3) you Must initialize the stack pointer to an address above the highest
register bank you will be using, otherwise the stack will overwrite your alternate register banks.
Similarly, if you will be using bit variables it is usually a good idea to initialize the stack pointer to some
value greater than 2Fh to guarantee that your bit variables are protected from the stack.
Similarly, if you want to write the value "1" to the 8051’s serial port you would write this value to the
SBUF SFR, which has an SFR address of 99 Hex. Thus, to write the value "1" to the serial port you
would execute the instruction:
As you can see, it appears that the SFR is part of Internal Memory. This is not the case. When using this
method of memory access (it’s called direct address), any instruction that has an address of 00h through
7Fh refers to an Internal RAM memory address; any instruction with an address of 80h through FFh
refers to an SFR control register.
Programming Tip:
SFRs are used to control the way the 8051 functions. Each SFR has a specific purpose and
format which will be discussed later. Not all addresses above 80h are assigned to SFRs. However, this
area may NOT be used as additional RAM memory even if a given address has not been assigned to an
SFR.
SFR’s:
What Are SFR’s?
The 8051 is a flexible microcontroller with a relatively large number of modes of operations.
Your program may inspect and/or change the operating mode of the 8051 by manipulating the values of
the 8051's Special Function Registers (SFRs). SFRs are accessed as if they were normal Internal RAM.
The only difference is that Internal RAM is from address 00h through 7Fh whereas SFR registers exist
in the address range of 80h through FFh. Each SFR has an address (80h through FFh) and a name. The
following chart provides a graphical presentation of the 8051's SFRs, their names, and their address.
As you can see, although the address range of 80h through FFh offers 128 possible addresses, there are
only 21 SFRs in a standard 8051. All other addresses in the SFR range (80h through FFh) are
considered invalid. Writing to or reading from these registers may produce undefined values or
behavior.
Programming Tip: It is recommended that you not read or write to SFR addresses that have not been
assigned to an SFR. Doing so may provoke undefined behavior and may cause your program to be
incompatible with other 8051-derivatives that use the given SFR for some other purpose.
SFR Types
As mentioned in the chart itself, the SFRs that have a blue background are SFRs related to the
I/O ports. The 8051 has four I/O ports of 8 bits, for a total of 32 I/O lines. Whether a given I/O line is
high or low and the value read from the line are controlled by the SFRs in green. The SFRs with yellow
background are SFRs which in some way control the operation or the configuration of some aspect of
the 8051. For example, TCON controls the timers, SCON controls the serial port. The remaining SFRs,
with green backgrounds, are "other SFRs." These SFRs can be thought of as auxiliary SFRs in the sense
that they don't directly configure the 8051 but obviously the 8051 cannot operate without them. For
example, once the serial port has been configured using SCON, the program may read or write to the
serial port using the SBUF register.
Programming Tip:
The SFRs whose names appear in red in the chart above are SFRs that may be accessed via bit
operations (i.e., using the SETB and CLR instructions). The other SFRs cannot be accessed using bit
operations. As you can see, all SFRs that whose addresses are divisible by 8 can be accessed with bit
operations.
SFR Descriptions
This section will endeavor to quickly overview each of the standard SFRs found in the above
SFR chart map. It is not the intention of this section to fully explain the functionality of each SFR--this
information will be covered in separate chapters of the tutorial. This section is to just give you a general
idea of what each SFR does. P0 (Port 0, Address 80h, Bit-Addressable): This is input/output port 0.
Each bit of this SFR corresponds to one of the pins on the microcontroller. For example, bit 0 of port 0
is pin P0.0, bit 7 is pin P0.7. Writing a value of 1 to a bit of this SFR will send a high level on the
corresponding I/O pin whereas a value of 0 will bring it to a low level.
Programming Tip: While the 8051 has four I/O port (P0, P1, P2, and P3), if your hardware uses external
RAM or external code memory (i.e., your program is stored in an external ROM or EPROM chip or if
you are using external RAM chips) you may not use P0 or P2. This is because the 8051 uses ports P0
and P2 to address the external memory. Thus if you are using external RAM or code memory you may
only use ports P1 and P3 for your own use.
SP (Stack Pointer, Address 81h):
This is the stack pointer of the microcontroller. This SFR indicates where the next value to be
taken from the stack will be read from in Internal RAM. If you push a value onto the stack, the value
will be written to the address of SP + 1. That is to say, if SP holds the value 07h, a PUSH instruction
will push the value onto the stack at address 08h. This SFR is modified by all instructions which modify
the stack, such as PUSH, POP, and LCALL, RET, RETI, and whenever interrupts are provoked by the
microcontroller.
Programming Tip:
The SP SFR, on startup, is initialized to 07h. This means the stack will start at 08h and start
expanding upward in internal RAM. Since alternate register banks 1, 2, and 3 as well as the user bit
variables occupy internal RAM from addresses 08h through 2Fh, it is necessary to initialize SP in your
program to some other value if you will be using the alternate register banks and/or bit memory. It's not
a bad idea to initialize SP to 2Fh as the first instruction of every one of your programs unless you are
100% sure you will not be using the register banks and bit variables.
Programming Tip:
DPTR is really DPH and DPL taken together as a 16-bit value. In reality, you almost always
have to deal with DPTR one byte at a time. For example, to push DPTR onto the stack you must first
push DPL and then DPH. You can't simply plush DPTR onto the stack. Additionally, there is an
instruction to "increment DPTR." When you execute this instruction, the two bytes are operated upon as
a 16-bit value. However, there is no instruction that decrements DPTR. If you wish to decrement the
value of DPTR, you must write your own code to do so.
PCON (Power Control, Addresses 87h):
The Power Control SFR is used to control the 8051's power control modes. Certain operation
modes of the 8051 allow the 8051 to go into a type of "sleep" mode which requires much less power.
These modes of operation are controlled through PCON. Additionally, one of the bits in PCON is used
to double the effective baud rate of the 8051's serial port.
Programming Tip:
To use the 8051's on-board serial port, it is generally necessary to initialize the following SFRs:
SCON, TCON, and TMOD. This is because SCON controls the serial port. However, in most cases the
program will wish to use one of the timers to establish the serial port's baud rate. In this case, it is
necessary to configure timer 1 by initializing TCON and TMOD.
Programming Tip:
If you write an interrupt handler routine, it is a very good idea to always save the PSW SFR on
the stack and restore it when your interrupt is complete. Many 8051 instructions modify the bits of
PSW. If your interrupt routine does not guarantee that PSW is the same upon exit as it was upon entry,
your program is bound to behave rather erratically and unpredictably--and it will be tricky to debug
since the behavior will tend not to make any sense.
Other SFRs
The chart above is a summary of all the SFRs that exist in a standard 8051. All derivative
microcontrollers of the 8051 must support these basic SFRs in order to maintain compatibility with the
underlying MSCS51 standard. A common practice when semiconductor firms wish to develop a new
8051 derivative is to add additional SFRs to support new functions that exist in the new chip. For
example, the Dallas Semiconductor DS80C320 is upwards compatible with the 8051. This means that
any program that runs on a standard 8051 should run without modification on the DS80C320. This
means that all the SFRs defined above also apply to the Dallas component. However, since the
DS80C320 provides many new features that the standard 8051 does not, there must be some way to
control and configure these new features. This is accomplished by adding additional SFRs to those listed
here. For example, since the DS80C320 supports two serial ports (as opposed to just one on the 8051),
the SFRs SBUF2 and SCON2 have been added. In addition to all the SFRs listed above, the DS80C320
also recognizes these two new SFRs as valid and uses their values to determine the mode of operation of
the secondary serial port. Obviously, these new SFRs have been assigned to SFR addresses that were
unused in the original 8051. In this manner, new 8051 derivative chips may be developed which will run
existing 8051 programs.
Programming Tip:
If you write a program that utilizes new SFRs that are specific to a given derivative chip and not
included in the above SFR list, your program will not run properly on a standard 8051 where that SFR
does not exist. Thus, only use non-standard
SFRs if you are sure that your program wil only have to run on that specific microcontroller. Likewise,
if you write code that uses non-standard SFRs and subsequently share it with a third-party, be sure to let
that party know that your code is using non-standard SFRs to save them the headache of realizing that
due to strange behavior at run-time.
Basic Registers:
The Accumulator
If you’ve worked with any other assembly languages you will be familiar with the concept of an
Accumulator register. The Accumulator, as it’s name suggests, is used as a general register to
accumulate the results of a large number of instructions. It can hold an 8-bit (1-byte) value and is the
most versatile register the 8051 has due to the shear number of instructions that make use of the
accumulator. More than half of the 8051’s 255 instructions manipulate or use the accumulator in some
way. For example, if you want to add the number 10 and 20, the resulting 30 will be stored in the
Accumulator. Once you have a value in the Accumulator you may continue processing the value or you
may store it in another register or in memory.
After executing this instruction the Accumulator will contain the value 30. You may think of the "R"
registers as very important auxiliary, or "helper", registers. The Accumulator alone would not be very
useful if it were not for these "R" registers. The "R" registers are also used to temporarily store values.
For example, let’s say you want to add the values in R1 and R2 together and then subtract the values of
R3 and R4. One way to do this would be:
MOV A, R3; Move the value of R3 into the accumulator
ADD A, R4; add the value of R4
MOV R5, A; Store the resulting value temporarily in R5
MOV A, R1; Move the value of R1 into the accumulator
ADD A, R2; add the value of R2
SUBB A, R5; Subtract the value of R5 (which now contains R3 + R4)
As you can see, we used R5 to temporarily hold the sum of R3 and R4. Of course, this isn’t the most
efficient way to calculate (R1+R2) - (R3 +R4) but it does illustrate the use of the "R" registers as a way
to store values temporarily.
B) Crystal oscillator:
A crystal oscillator (sometimes abbreviated to XTAL on schematic diagrams) is an
electronic circuit that uses the mechanical resonance of a physical crystal of piezoelectric
material along with an amplifier and feedback to create an electrical signal with a very precise
frequency.
Crystal oscillators are a common source of time and frequency signals. The crystal used therein
is sometimes called a "timing crystal".
Contents·
• Spurious frequencies
• Notation
A miniature 4.000 MHz quartz timing crystal enclosed in an hermetically sealed package.
A crystal is a solid in which the constituent atoms, molecules, or ions are packed in a
regularly ordered, repeating pattern extending in all three spatial dimensions.
Almost any object made of an elastic material could be used like a crystal, with
appropriate transducers, since all objects have natural resonant frequencies of vibration. For
example, steel is very elastic and has a high speed of sound. It was often used in mechanical
filters before quartz.
The resonant frequency depends on size, shape, elasticity and the speed of sound in the
material. High-frequency crystals are typically cut in the shape of a simple, rectangular plate.
Low-frequency crystals, such as those used in digital watches, are typically cut in the shape of a
tuning fork.
For applications not needing very precise timing, a low-cost ceramic resonator is often
used in place of a quartz crystal.
When a crystal of quartz is properly cut and mounted, it can be made to bend in an
electric field, by applying a voltage to an electrode near or on the crystal. This property is
known as piezoelectricity.
When the field is removed, the quartz will generate an electric field as it returns to its
previous shape, and this can generate a voltage. The result is that a quartz crystal behaves like a
circuit composed of an inductor, capacitor and resistor, with a precise resonant frequency.
Quartz has the further advantage that its size changes very little with temperature.
Therefore, the resonant frequency of the plate, which depends on its size, will not change much,
either. This means that a quartz clock, filter or oscillator will remain accurate.
Quartz timing crystals are manufactured for frequencies from a few tens of kilohertz to
tens of megahertz. More than two billion (2 × 109) crystals are manufactured annually. Most are
small devices for wristwatches, clocks, and electronic circuits. However, quartz crystals are also
found inside test and measurement equipment, such as counters, signal generators, and
oscilloscopes.
The crystal oscillator circuit sustains oscillation by taking a voltage signal from the
quartz resonator, amplifying it, and feeding it back to the resonator. The rate of expansion and
contraction of the quartz is the resonant frequency, and is determined by the cut and size of the
crystal.
A regular timing crystal contains two electrically conductive plates, with a slice or tuning
fork of quartz crystal sandwiched between them. During startup, the circuit around the crystal
applies a random noise AC signal to it, and purely by chance, a tiny fraction of the noise will be
at the resonant frequency of the crystal.
The crystal will therefore start oscillating in synchrony with that signal. As the oscillator
amplifies the signals coming out of the crystal, the crystal's frequency will become stronger,
eventually dominating the output of the oscillator. Natural resistance in the circuit and in the
quartz crystal filter out all the unwanted frequencies.
One of the most important traits of quartz crystal oscillators is that they can exhibit very
low phase noise. In other words, the signal they produce is a pure tone. This makes them
particularly useful in telecommunications where stable signals are needed and in scientific
equipment where very precise time references are needed.
A typical Q for a quartz oscillator ranges from 104 to 106. The maximum Q for a high
stability quartz oscillator can be estimated as Q = 1.6 × 107/f, where f is the resonance
frequency in MHz.
Environmental changes of temperature, humidity, pressure, and vibration can change the
resonant frequency of a quartz crystal, but there are several designs that reduce these
environmental effects. These include the TCXO, MCXO, and OCXO (defined below).
These designs (particularly the OCXO) often produce devices with excellent short-term
stability. The limitations in short-term stability are due mainly to noise from electronic
components in the oscillator circuits. Long term stability is limited by aging of the crystal.
Due to aging and environmental factors such as temperature and vibration, it is hard to
keep even the best quartz oscillators within one part in 10-10 of their nominal frequency without
constant adjustment. For this reason, atomic oscillators are used for applications that require
better long-term stability and accuracy.
Although crystals can be fabricated for any desired resonant frequency, within
technological limits, in actual practice today engineers design crystal oscillator circuits around
relatively few standard frequencies, such as 10 MHz, 20 MHz and 40 MHz. Using frequency
dividers, frequency multipliers and phase locked loop circuits, it is possible to synthesize any
desired frequency from the reference frequency.
Care must be taken to use only one crystal oscillator source when designing circuits to
avoid subtle failure modes of met stability in electronics. If this is not possible, the number of
distinct crystal oscillators, PLLs, and their associated clock domains should be rigorously
minimized, through techniques such as using a subdivision of an existing clock instead of a new
crystal source.
Each new distinct crystal source needs to be rigorously justified since each one
introduces new difficult to debug probabilistic failure modes, due to multiple crystal
interactions, into equipment.
Any additional circuit capacitance will thus pull the frequency down. For a parallel
resonance crystal to operate at its specified frequency, the electronic circuit has to provide a
total parallel capacitance as specified by the crystal manufacturer.
Crystals above 30 MHz (up to >200 MHz) are generally operated at series resonance
where the impedance appears at its minimum and equal to the series resistance. For this reason
the series resistance is specified (<100 Ω) instead of the parallel capacitance. For the upper
frequencies, the crystals are operated at one of its overtones, presented as being a fundamental,
3rd, 5th, or even 7th overtone crystal. The oscillator electronic circuits usually provides
additional LC circuits to select the wanted overtone of a crystal.
Spurious frequencies
Notation
On electrical schematic diagrams, crystals are designated with the class letter "Y" (Y1,
Y2, etc.) Oscillators, whether they are crystal oscillators or other, are designated with the class
letter "G" (G1, G2, etc.) (See IEEE Std 315-1975, or ANSI Y32.2-1975) On occasion, one may
see a crystal designated on a schematic with "X" or "XTAL", or a crystal oscillator with "XO",
but these forms are deprecated.
Crystal oscillators are oscillators where the primary frequency determining element is a
quartz crystal. Because of the inherent characteristics of the quartz crystal the crystal oscillator
may be held to extreme accuracy of frequency stability. Temperature compensation may be
applied to crystal oscillators to improve thermal stability of the crystal oscillator.
Crystal oscillators are usually, fixed frequency oscillators where stability and accuracy
are the primary considerations. For example it is almost impossible to design a stable and
accurate LC oscillator for the upper HF and higher frequencies without resorting to some sort of
crystal control. Hence the reason for crystal oscillators.
The frequency of older FT-243 crystals can be moved upward by crystal grinding.
The transistor could be a general purpose type with an Ft of at least 150 Mhz for HF use.
A typical example would be a 2N2222A.
The turn’s ratio on the tuned circuit depicts an anticipated nominal load of 50 ohms. This
allows a theoretical 2K5 ohm on the collector. If it is followed by a buffer amplifier (highly
recommended) I would simply maintain the typical 7:1 turn’s ratio. I have included a formula
for determining L and C in the tuned circuits of crystal oscillators in case you have forgotten
earlier tutorials. Personally I would make L a reactance of around 250 ohms. In this case I'd
make C a smaller trimmer in parallel with a standard fixed value.
You can use an overtone crystal for the crystal and set L * C for the odd particular multiple of
overtone wanted in your crystal oscillators.
Of particular interest to those people wanting to develop a variable crystal oscillator is the Super
VXO. Worth a look oscillation is the periodic variation, typically in time, of some measure as
seen, for example, in a swinging pendulum. The term vibration is sometimes used more
narrowly to mean a mechanical oscillation but sometimes is used to be synonymous with
oscillation. Oscillations occur not only in physical systems but also in biological systems and in
human society. Oscillations are the origin of the sensation of musical tone
1. Harmonic oscillator.
2. Relaxation oscillator.
Harmonic oscillator
The harmonic oscillator produces a sinusoidal output. The basic form of an harmonic oscillator
is an electronic amplifier with the output attached to a narrow-band electronic filter, and the
output of the filter attached to the input of the amplifier. When the power supply to the amplifier
is first switched on, the amplifier's output consists only of noise. The noise travels around the
loop, being filtered and re-amplified until it increasingly resembles the desired signal.
A piezoelectric crystal (commonly quartz) may be coupled to the filter to stabilise the frequency
of oscillation, resulting in a crystal oscillator.
There are many ways to implement harmonic oscillators, because there are different ways to
amplify and filter. For example:
· Hartley oscillator
· Colpitts oscillator
· Clapp oscillator
· Phase-shift oscillator
Relaxation oscillator
The relaxation oscillator is often used to produce a non-sinusoidal output, such as a square wave
or saw tooth. The oscillator contains a nonlinear component such as a transistor that periodically
discharges the energy stored in a capacitor or inductor, causing abrupt changes in the output
waveform.
Square-wave relaxation oscillators can be used to provide the clock signal for sequential logic
circuits such as timers and counters, although crystal oscillators are often preferred for their
greater stability.
Triangle-wave or saw tooth oscillators are used in the time base circuits that generate the
horizontal deflection signals for cathode ray tubes in analogue oscilloscopes and television sets.
In function generators, this triangle wave may then be further shaped into a close approximation
of a sine wave.
The multivibrator and the rotary traveling wave oscillator are another types of relaxation
oscillators
Variable-frequency oscillator
A variable frequency oscillator is needed in any radio receiver or transmitter that works by the
super heterodyne principle, and which can be tuned across various frequencies. Altering the
frequency of the VFO will control the frequency to which the radio is tuned.
2 . Analogue VFO
2.2 Varactor
3. Digital VFO
4. Performance
4.1 Accuracy
4.1.1 Stability
4.1.2 Repeatability
4.2 Purity
4.2.1 Spurii
In a simple superhet radio receiver, incoming radio frequencies from the antenna are
made to mix (or multiply) with an internally generated radio frequency from the VFO in a
process called mixing.
· at frequencies that equal the difference between two of the mixed frequencies
If the required incoming radio frequency and the VFO frequency were both rather high
(RF) but quite similar, then by far the lowest frequency produced from the mixer will be their
difference. In very simple radios, it is relatively straightforward to separate this from all the
other spurious signals using a filter, to amplify it and then further to process it into an audible
signal. In more complex situations, many enhancements and complications get added to this
simple process, but this mixing or heterodyning principle remains at the heart of it.
There are two main types of VFO in use: analogue and digital.
Analogue VFO
An analogue VFO could be an electronic oscillator where the value of at least one of the
active components is adjustable under user control so as to alter its output frequency. The active
component whose value is adjustable is usually a capacitor, but could be a variable inductor.
Tuning Capacitor
A reversed-biased semiconductor diode exhibits capacitance. Since the width of its non-
conducting depletion region depends on the magnitude of the reverse bias voltage, this voltage
can be used to control the junction capacitance. The varactor bias voltage may be generated in a
number of ways and there may need to be no significant moving parts in the final design.
Varactor have a number of disadvantages including temperature drift and ageing , electronic
noise, low Q factor and non-linearity.
Digital VFO
Modern radio receivers and transmitters usually use some from of digital frequency
synthesis to generate their VFO signal. The advantages of this are manifold, including smaller
designs, lack of moving parts, and the ease with which preset frequencies can be stored and
manipulated in the digital computer that is usually embedded in the design for other purposes
anyway.
It is also possible for the radio to become extremely frequency-agile in that the control
computer could alter the radio's tuned frequency many tens, thousands or even millions of times
a second. This capability allows communications receivers effectively to monitor many channels
at once, perhaps using digital selective calling (DSC) techniques to decide when to open an
audio output channel and alert users to incoming communications. Pre-programmed frequency
agility also forms the basis of some military radio encryption and stealth techniques. Extreme
frequency agility lies at the heart of spread spectrum techniques that are currently gaining
mainstream acceptance in computer wireless networking such as Wi-Fi.
There are disadvantages to digital synthesis such as the inability of a digital synthesizer
to tune smoothly through all frequencies, but with the channelisation of many radio bands, this
can also be seen as an advantage in that it prevents radios from operating in between two
recognized channels.
Digital frequency synthesis almost always relies on crystal controlled frequency sources.
Crystal controlled oscillators have enormous advantages over inductive and capacitively
controlled ones in terms of stability and repeatability as well as low noise and high Q factor.
The disadvantage comes when you try to alter the resonant frequency to tune the radio, but a
wide range of digital techniques have made this unnecessary in modern practice.
· Direct Digital Synthesis (DDS): Enough data points for a mathematical sine
function are stored in digital memory. These are recalled at the right speed and fed to a digital to
analogue converter where the required sine wave is built up.
It is this last, the PLL technique, that dominates most radio VFO design thinking today.
Performance
The performance of a radio's VFO strongly influences the performance of the radio itself.
Accuracy
It is useful if the frequency produced by the VFO is both stable and repeatable.
Stability
An unstable VFO's output frequency will drift with time. The root cause of this can often
be traced to temperature dependency in some of the voltages and component values involved.
Often as radios warm up it is necessary slightly to re-tune them to remain on frequency.
Repeatability
Ideally, for the same selected radio channel, the VFO in your radio is generating exactly
the same frequency today as it was on the day the radio was first assembled and tested. This will
mean that any built-in errors seen that day during the manufacture will have been calibrated out,
and this calibration will not have changed through to today. If this is not the case, then you will
not be able entirely to trust your tuning dial.
This would be a source of irritation on a receiver, where you may have to tune slightly
off the known frequency to receive a certain station. The problem can be more serious in a
transmitter as you could unwittingly and illegally be transmitting on a frequency for which you
are not authorized or licensed. If you do so, it is your responsibility, and trying to blame your
badly calibrated circuitry will be no defense.
Purity
You can imagine the shape of the VFO's frequency vs. amplitude graph to be the shape of
the 'window' through which the radio receives (and in the case of a transmitter, through which it
transmits when you ask it to transmit a pure sine-wave tone). In the ideal case, this
frequency/amplitude plot is very simple, i.e. there is absolutely no output at any frequency
except one, and plenty of pure output at exactly that frequency. In this ideal case, of course, the
'window' is unique and infinitely narrow. The ideal radio will receive and transmit only exactly
what is expected.
Spurii
A VFO's frequency vs. amplitude graph (or Fourier analysis) may exhibit not one but
several narrow peaks, probably harmonically related. Each of these other peaks can potentially
mix with some other incoming signal and produce a spurious response. This spurii (sometimes
spelt spuriae) result in you hearing two stations at once, even though the other is nowhere near
this one on the band.
The extra peaks may be many hundreds or thousands of times lower in value than the
main one, but don't forget that the other, interfering station may be hundreds or thousands of
times more powerful at the antenna than the one you are after.
In a transmitter, these spurious signals are actually generated along with the one you
expect. If they are not completely filtered out before they are transmitted, then the license-
holder may again be in breach of the terms of his or her license.
Phase noise
When examined with very sensitive equipment, the pure sine-wave peak in a VFO's
frequency graph will most likely turn out not to be sitting on a flat noise-floor. Slight random
'jitters' in the signal's timing will mean that the peak is sitting on 'skirts' of phase-noise at
frequencies either side of the desired one, These are also troublesome in crowded bands. They
allow through unwanted signals that are fairly close to the one we expect, but because of the
random quality of these phase-noise 'skirts', the signals are usually unintelligible, appearing just
as extra noise in the signal we are after. The effect is that what should be a clean signal in a
crowded band can appear to be a very noisy signal, because of the effects of all the strong
signals nearby.
The effect of VFO phase noise on a transmitter is that random noise is actually
transmitted either side of the required signal. Again, this must be avoided at all costs for legal
reasons in many cases.
Crystal control
In all performances cases, crystal controlled oscillators are better behaved than the
semiconductor- and LC-based alternatives. They tend to be more stable, more repeatable, have
fewer and lower harmonics and lower noise than all the alternatives in their cost-band. This in
part explains their huge popularity in low-cost and computer-controlled (i.e. PPL and
synthesizer-based) VFOs
Crystal oven
The crystal is mounted within a thermally-insulated enclosure; the enclosure also contains one
or more electric (resistive) heaters. Closed-loop control is used to modulate the heater and
ensure that the crystal is heated to the specific temperature desired. Because the oven operates
above ambient temperature, the crystal or oscillator within usually requires a warm-up period
after power has been applied. During this warm-up period, the frequency may not be fully
stable.
Because of the power required power to run the heater, oscillators using crystal ovens
require more power than oscillators that run at ambient temperature and the requirement for the
heater, thermal mass, and thermal insulation means that oscillators using ovens are physically
larger than their ambient counterparts. However, in return, the oven-controlled oscillator
achieves the best frequency stability possible from a crystal. Achieving better performance
requires switching to an atomically-stabilized technique such as a rubidium standard, cesium
standard, or hydrogen maser.
C) LCD:
In recent years the LCD is finding widespread use replacing LED's. This is due to
1) The declining prices of LCD's.
2) The ability to display numbers, characters, and graphics. This is in contrast to LED's which
are limited to numbers and a few characters.
3) Incorporation of a refreshing controller in to the LCD, thereby relieving the CPU of the task
of refreshing the LCD. In contrast, the LED must be refreshed by the CPU to keep displaying
the data.
4) Ease of programming for characters and graphics.
LCD PIN DESCRITION:
A general purpose alphanumeric LCD display, with two lines of 16 characters is shown
in the figure.
A liquid crystal display (LCD) is a thin, flat display device made up of any
number of color or monochrome pixels arrayed in front of a light source or reflector. It
is prized by engineers because it uses very small amounts of electric power, and is
therefore suitable for use in battery-powered electronic devices.
To save cost in the electronics, LCDs are often multiplexed. In a multiplexed display,
electrodes on one side of the display are grouped and wired together, and each group
gets its own voltage source. On the other side, the electrodes are also grouped, with
each group getting a voltage sink. The groups are designed so each pixel has a unique,
unshared combination of source and sink. The electronics or the software driving the
electronics then turns on sinks in sequence, and drives sources for the pixels of each
sink.
Types of regulators:
1. Electromechanical regulators ·
2 .Mains regulators
5 .Active regulators
These regulators operate by controlling the field current reaching the generator (or alternator)
and in this way controlling the output voltage produced by the generator.
Mains regulators
AC voltage stabilizers
DC voltage stabilizers
Many simple DC power supplies regulate the voltage using a shunt regulator such
as a zener diode, avalanche breakdown diode, or voltage regulator tube. Each of these devices
begins conducting at a specified voltage and will conduct as much current as required to hold
its terminal voltage to that specified voltage. The power supply is designed to only supply a
maximum amount of current that is within the safe operarating capability of the shunt
regulating device (commonly, by using a series resistor). In shunt regulators, the voltage
reference is also the regulating device.
If the stabiliser must provide more power, the shunt regulator output is only used
to provide the standard voltage reference for the electronic device, known as the voltage
stabiliser. The voltage stabiliser is the electronic device, able to deliver much larger currents on
demand.
Active regulators
Because they (essentially) dump the excess current not needed by the load, shunt
regulators are inefficient and only used for low-power loads. When more power must be
supplied, more sophisticated circuits are used. In general, these can be divided into several
classes:
· Linear regulators
· Switching regulators
· SCR regulators
Linear regulators
Linear regulators insert a variable resistance in series with the load current. In the
past, one or more vacuum tubes were commonly used as the variable resistance. Modern
designs use one or more transistors instead. Linear designs have the advantage of very "clean"
output with little noise introduced into their DC output.
Entire linear regulators are available as integrated circuits. These chips come in either fixed or
variable voltage types.
Switching regulators
· Linear regulators are best when a fast response to input and output disturbances is
required.
· Switching regulators are required when the only power supply is a DC voltage,
and a higher output voltage is required.
In many cases either one would work. So the choice comes down to which costs
less. At high levels of power (above a few watts), switching regulators are cheaper. At low
levels of power, linear regulators are cheaper.
SCR regulators
Regulators powered from AC power circuits can use silicon controlled rectifiers
(SCRs) as the series device. Whenever the output voltage is below the desired value, the SCR
is triggered, allowing electricity to flow into the load until the AC mains voltage passes
through zero (ending the half cycle). SCR regulators have the advantages of being both very
efficient and very simple, but because they can not terminate an on-going half cycle of
conduction, they are not capable of very accurate voltage regulation in response to rapidly-
changing loads.
Many power supplies use more than one regulation method in series. For
example, the output from a switching regulator can be further regulated by a linear regulator.
The switching regulator accepts a wide range of input voltages and efficiently generates a
(somewhat noisy) voltage slightly above the ultimately desired output. That is followed by a
linear regulator that generates exactly the desired voltage and eliminates nearly all the noise
generated by the switching regulator. Other designs may use an SCR regulator as the "pre-
regulator", followed by another type of regulator
Examples are a voltage regulator (which can be a transformer whose voltage ratio of
transformation can be adjusted, or an electronic circuit that produces a defined voltage), a gas
regulator, such as a diving regulator, which maintains its output at a fixed pressure lower than
its input, and a fuel regulator (which controls the supply of fuel).
Regulators can be designed to control anything from gasses or fluids, to light or
electricity. Speed can be regulated by; electronic, mechanical, or electro-mechanical means.
Such instances include;
· Electronic regulators as used in model railway sets where the voltage is raised or
lowered to control the speed of the engine
sbit rs =P2^4;
sbit rw =P2^5;
sbit en =P2^6;
void main()
{
lcd_cmd(0x38);
lcd_cmd(0x01);
lcd_cmd(0x84);
lcd_cmd(0x0f);
lcd_data ('0');
lcd_data ('0');
lcd_data ('0');
lcd_data ('0');
lcd_data ('0');
lcd_data ('0');
lcd_data ('0');
lcd_data ('0');
lcd_data ('0');
lcd_data ('0');
TMOD=0x16;
IE=0x8A;
IP =0x02;
TH0 =0xff;
TL0 =0xff;
TH1=TL1 =0;
TR0 =1;
While (1);
}
a=da/10;
b=da%10;
c=a/10;
d=a%10;
e=c/10;
f=c%10;
g=e/10;
h=e%10;
i=g/10;
j=g%10;
k=i/10;
l=i%10;
m=k%10;
n=k/10;
lcd_cmd(0x01);
lcd_cmd(0x84);
lcd_data(n|0x30);
lcd_data(m|0x30);
lcd_data(l|0x30);
lcd_data(j|0x30);
lcd_data(h|0x30);
lcd_data(f|0x30);
lcd_data(d|0x30);
lcd_data(b|0x30);
}
Star
t
=P1^0
Tsop = 1
P2=0x00
B
timer
If(Tsop==
0)
Counter++
If (
Counter=1
)
timer
A
A
B
Star
t
Keil Compiler:
Keil is also a cross compiler The process of development of the soft code on a processor for a particular
application and which can be implemented on the target processor is known as Cross Development.
In our design the main heart of the hardware module is the micro controller which is the
programmable IC .The programming language used for developing the software to the
micro controller is Embedded C /Assembly. The KEIL cross compiler is used to edit
,compile and debug this program Micro Flash programmer is used for burning the
developed code on Keil in to the micro controller Chip.
Software Development Cycle
When you use the Keil Software tools, the project development cycle is roughly the
same as it is for any other software development project.
1. Create a project, select the target chip from the device database, and configure the tool
settings.
2. Create source files in C or assembly.
3. Build your application with the project manager.
4. Correct errors in source files.
5. Test the linked application.
µVision2 IDE:
The µVision2 IDE combines project management, a rich-featured editor with interactive
error correction, option setup, make facility, and on-line help. Use µVision2 to create
your source files and organize them into a project that defines your target application.
µVision2 automatically compiles, assembles, and links your embedded application and
provides a single focal point for your development efforts.
Source files are created by the µVision2 IDE and are passed to the C51 Compiler or A51
assembler. The compiler and assembler process source files and create relocatable object
files.
The Keil C51 Compiler is a full ANSI implementation of the C programming language
that supports all standard features of the C language. In addition, numerous features for
direct support of the 8051 architecture have been added. The Keil A51 macro assembler
supports the complete instruction set of the 8051 and all derivatives.
µVision2 Debugger
The µVision2 symbolic, source-level debugger is ideally suited for fast, reliable program
debugging. The debugger includes a high-speed simulator that let you simulate an entire
8051 system including on-chip peripherals and external hardware. The attributes of the
chip you use are automatically configured when you select the device from the Device
Database.
The µVision2 Debugger provides several ways for you to test your programs on real
target hardware.
_ Install the MON51 Target Monitor on your target system and download your program
using the Monitor-51 interface built-in to the µVision2 Debugger.
_ Use the Advanced GDI interface to attach use the µVision2 Debugger front end with
your target system.
µVision2 Integrated Development Environment
The µVision2 IDE is a Windows-based software development platform that combines a robust editor,
project manager, and make facility. µVision2 supports all of the Keil tools for the 8051 including the C
compiler, macro assembler, linker/locator, and object-HEX converter. µVision2 helps expedite the
development process of your embedded applications by providing the following:
_ Full-featured source code editor,
_ Device database for configuring the development tool setting,
_ Project manager for creating and maintaining your projects,
_ Integrated make facility for assembling, compiling, and linking your embedded
applications,
_ Dialogs for all development tool settings,
_ True integrated source-level Debugger with high-speed CPU and peripheral simulator,
_ Advanced GDI interface for software debugging in the target hardware and for
connection to Monitor-51,
_ Links to development tools manuals, device datasheets & user’s guides.
The Keil C51 Cross Compiler is an ANSI C Compiler that was written specifically to
generate fast, compact code for the 8051 microcontroller family.
The C51 Compiler generates object code that matches the efficiency and speed of
assembly programming.
Using a high-level language like C has many advantages over assembly language
programming:
_ Knowledge of the processor instruction set is not required. Rudimentary knowledge of
the memory structure of the 8051 CPU is desirable (but not necessary).
_ Details like register allocation and addressing of the various memory types and data
types is managed by the compiler.
_ Programs get a formal structure (which is imposed by the C programming language)
and can be divided into separate functions. This contributes to source code reusability as
well as better overall application structure.
_ The ability to combine variable selection with specific operations improves program
readability.
_ Keywords and operational functions that more nearly resemble the human thought
process may be used.
_ Programming and program test time is drastically reduced.
_ The C run-time library contains many standard routines such as: formatted output,
numeric conversions, and floating-point arithmetic.
_ Existing program parts can be more easily included into new programs because of
modular program construction techniques.
_ The language C is a very portable language (based on the ANSI standard) that enjoys
wide popular support and is easily obtained for most systems. Existing program
investments can be quickly adapted to other processors as
needed.
C51 Language Extensions
Even though the C51 Compiler is ANSI-compliant, some extensions were added to
support the facilities of the 8051 microprocessor. The C51 Compiler includes extensions
for:
_ Data Types,
_ Memory Types,
_ Memory Models,
_ Pointers,
_ Reentrant Functions,
_ Interrupt Functions,
_ Real-Time Operating Systems,
_ Interfacing to PL/M and A51 source files.
Code Optimizations
The C51 Compiler is an aggressive optimizing compiler that takes numerous steps to
ensure that the code generated and output to the object file is the most efficient (smallest
and/or fastest) code possible. The compiler analyzes the generated code to produce the
most efficient instruction sequences. This ensures that your C program runs as quickly
and effectively as possible in the least amount of code space.
The C51 Compiler provides nine different levels of optimizing. Each increasing level
includes the optimizations of levels below it. The following is a list of all optimizations
currently performed by the C51 Compiler.
General Optimizations
Debugging:
The C51 Compiler uses the Intel Object Format (OMF51) for object files and
generates complete symbol information. Additionally, the compiler can include all the
necessary information such as; variable names, function names, line numbers, and so on
to allow detailed and thorough debugging and analysis with the µVision2 Debugger or
any Intel-compatible emulators.
The A51 Assembler is a macro assembler for the 8051 microcontroller family. It
translates symbolic assembler language mnemonics into executable machine code. The
A51 Assembler allows you to define each instruction in an 8051 program and is used
where utmost speed, small code size, and exact hardware control is essential. The
assembler’s macro facility saves development and maintenance time since common
sequences need only be developed once.
Source-Level Debugging
The A51 Assembler generates complete line number, symbol, and type information in the object file
created. This allows exact display of program variables in your debugger. Line numbers are used for source-
level debugging of your assembler programs with the µVision2 Debugger or third-party emulator.
Functional Overview
The A51 Assembler translates an assembler source file into a relocatable object module.
It generates a listing file optionally with symbol table and cross reference. The A51
Assembler supports two different macro processors:
_ The Standard Macro Processor is the easier macro processor to use. It allows you to
define and use macros in your 8051 assembly programs. The standard macro syntax is
compatible with that used in many other assemblers.
_ The Macro Processing Language (MPL) is a string replacement facility that is fully
compatible with the Intel ASM51 macro processor. MPL has several predefined macro
processor functions that perform many useful operations like string manipulation or
number processing. Another powerful feature of the A51 Assembler macro processors is
conditional assembly depending on command line directives or assembler symbols.
Conditional assembly of sections of code can help you achieve the most compact code
possible. It also allows you to generate different applications from one assembly source
file.
ASSEMBLY VS C: