To find the largest no. using classes

| |

#include<iostream>
using namespace std;
      class set
      { int m,n;
      public:
             void input(void);
             void display(void);
             int largest(void);
             };
             int set::largest(void)
             { if(m>=n)
             return(m);
             else
             return(n);
             }
             void set::input(void)
             { cout<<"Input values of m and n:"<<"\n";
             cin>>m>>n;
             }
             void set::display(void)
             { cout<<"largest value="<<largest()<<"\n";
             }
             int main()
             {
                 set A;
                 A.input();
                 A.display();
              
                 return 0;
                 }
Read More

Find Grtr no. using C++

| |
#include<iostream>
using namespace std;
      class set
      { int m,n;
            public:
                 void input(void);
                 void display(void);
             int largest(void);
                };
             int set::largest(void)
                 { if(m>=n)
                   return(m);
                    else
                    return(n);
                        }
             void set::input(void)
                 { cout<<"Input values of m and n:"<<"\n";
                     cin>>m>>n;
                   }
             void set::display(void)
                { cout<<"largest value="<<largest()<<"\n";
                          }
             int main()
                {
                    set A;
                   A.input();
                   A.display();
              
                   return 0;
                      }
Read More

Signal filter

| |

What is a filter?

A filter is a device that passes electric signals at certain frequencies or
frequency ranges while preventing the passage of others. — Webster.
Filter circuits are used in a wide variety of applications. In the field of telecommunication,
band-pass filters are used in the audio frequency range (0 kHz to 20 kHz) for modems
and speech processing. High-frequency band-pass filters (several hundred MHz) are
used for channel selection in telephone central offices. Data acquisition systems usually
require anti-aliasing low-pass filters as well as low-pass noise filters in their preceding sig-
nal conditioning stages. System power supplies often use band-rejection filters to sup-
press the 60-Hz line frequency and high frequency transients.
In addition, there are filters that do not filter any frequencies of a complex input signal, but
just add a linear phase shift to each frequency component, thus contributing to a constant
time delay. These are called all-pass filters.
At high frequencies (> 1 MHz), all of these filters usually consist of passive components
such as inductors (L), resistors (R), and capacitors (C). They are then called LRC filters.
In the lower frequency range (1 Hz to 1 MHz), however, the inductor value becomes very
large and the inductor itself gets quite bulky, making economical production difficult.
In these cases, active filters become important. Active filters are circuits that use an op-
erational amplifier (op amp) as the active device in combination with some resistors and
   capacitors to provide an LRC-like filter performance at low frequencies .

Read More

Dual power supply

| |

Many times need of electronic enginner to have a simple, dual power supply for a project. Existing powersupplies may be too big either in power output or physical size. Just a simple Dual Power Supply is required.For most non-critical applications the best and simplest choice for a voltage regulator is the 3-terminal type.The 3 terminals are input, ground and output.

The 78xx & 79xx series can provide up to 1A load current and it have onchip circuitry to prevent damage in the event of over heating or excessive current. That is, the chip simply shuts down rather than blowing out. These regulators are inexpensive, easy to use, and they make it practical to design a system with many PCBs in which an unregulated supply is brought in and regulation is done locally on each circuit board.

This Dual Power Supply project provides a dual power supply. With the appropriate choice of transformer and 3-terminal voltageregulator pairs you can easily build a small power supply delivering up to one amp at +/- 5V, +/- 9V, +/- 12V, +/-15V or +/-18V. You have to provide the centre tapped transformer and the 3-terminal pair of regulators you want:7805 & 7905, 7809 & 7909, 7812 & 7912, 7815 & 7915or 7818 & 7918.

Note that the + and - regulators do not have to be matched: you can for example, use a +5v and -9V pair. However,the positive regulator must be a 78xx regulator, and the negative a 79xx one. We have built in plenty of safety into this project so it should give many years of continuous service.

The user must choose the pair he needs for his particular application.



Transformer

This Dual Power Supply design uses a full wave bridge rectifier coupled with a centre-tapped transformer. A transformer with a power output rated at at least 7VA should be used. The 7VA rating means that the maximum current which can be delivered without overheating will be around 390mA for the 9V+9V tap; 290mA for the 12V+12V and 230mA for the 15V+15V. If the transformer is rated by output RMS-current then the value should be divided by 1.2 to get the current which can be supplied. For example, in this case a 1A RMS can deliver 1/(1.2) or 830mA.



Rectifier

We use an epoxy-packaged 4 amp bridge rectifier with at least a peak reverse voltage of 200V. (Note the part numbers of bridge rectifiers are not standardised so the number are different from different manufacturers.) For safety the diode voltage rating should be at least three to four times that of the transformers secondary voltage. The current rating of the diodes should be twice the maximum load current that will be drawn.

Filter Capacitor

The purpose of the filter capacitor is to smooth out the ripple in the rectified AC voltage. Theresidual amount of ripple is determined by the value of the filer capacitor: the larger the value the smaller the ripple.The 2,200uF is a suitable value for all the voltages generated using this project. The other consideration inchoosing the correct capacitor is its voltage rating. The working voltage of the capacitor has to be greater than thepeak output voltage of the rectifier. For an 18V supply the peak output voltage is 1.4 x 18V, or 25V. So we havechosen a 35V rated capacitor.


Regulators

The unregulated input voltage must always be higher than the regulators output voltage by at least 3V inorder for it to work. If the input/output voltage difference is greater than 3V then the excess potential must bedissipated as heat. Without a heatsink 3 terminal regulators candissipate about 2 watts. A simple calculation of the voltage differential times the current drawn will give the watts tobe dissipated. Over 2 watts a heatsink must be provided. If not then the regulator will automatically turn off if theinternal temperature reaches 150oC. For safety it is always best to use a small heatsink even if you do not think youwill need one.



Stability

C4 & C5 improve the regulators ability to react to sudden changes in load current and to preventuncontrolled oscillations.



Decoupling

The monoblok capacitor C2 & C6 across the output provides high frequency decoupling which keepsthe impedence low at high frequencies.

LED

Two LED's are provided to show when the output regulated power is on-line. You do not have to use theLED's if you do not want to. However, the LED on the negative side of the circuit does provide a minimum load tothe 79xx regulator which we found necessary during testing. The negative 3-pin regulators did not like a zeroloadsituation. We have provided a 470R/0.5W resistors as the current limiting resistors for the LED's.

Diode Protection

These protect mainly against any back emf which may come back into the power supply when itsupplies power to inductive loads. They also provide additional short circuit protection in the case that thepositive output is connected by accident to the negative output. If this happened the usual current limiting shutdownin each regulator may not work as intended. The diodes will short circuit in this case and protect the 2 regulators.










Part list





Read More

Car stereo amplifier

| |


Introduction To 18W Car Stereo Amplifier Project
This car stereo amplifier project is a class AB audio power amplifier using the Hitachi HA13118 module. It not only can be used in car application but also in any portable or home amplifier system. It is easy to construct and has a minimum of external components. The module has a high power output from a low voltage supply using the bridge tied load method, and a high gain of 55dB.
This project will be especially useful in applications where the input signal is a low level, without requiring the use of a separate pre-amplifier. This IC module has a built in surge protection circuit, thermal shut down circuit, ground fault protection circuit and power supply fault protection circuit making it extremely reliable.
The Specifications of this project are:
D.C. Input : 8 - 18V at 1-2 A

Power output : 18W maximum, 4 ohm load, 18V DC supply

S/N ratio : > 70 dB

THD : < 0.2% @ 1W

Freq. Response : ~ 30 Hz to 30 kHz, -3 dB

Input level : < 25 mV, for full output (G > 50dB)

Input Impedance : ~ 30 k ohm


The supply voltage required for this project is 8 -18V DC, at least 1 to 2 Amps. Maximum output power will only be obtained with a power supply of 18V at greater than 2 A, using a 4 ohm speaker. The power supply should be well filtered to reduce mains hum, a regulated supply will reduce noise even further. Extra filtering is unnecessary if operating from a battery supply.



Most of the circuitry is contained within the amplifier module. C10 is the input coupling capacitor and blocks DC from the input. C11 bypasses any RF which may be present at the input. C1 & C2 provide an AC ground for the inverting inputs of the IC. R1/C7 and R2/C8 provide a high frequency load for stability with difficult speakers. C5 and C6 provide "bootstrap" feedback for the IC. C9 and C12 provide power supply filtering.
An externally mounted logarithmic potentiometer of between 10k ohm and 50k ohm, is used depending on the desired input impedance. The impedance should be keep as high as possible for a guitar amp, unless using a separate pre-amp. Make surethat the heat sink is mounted to the module.

 PART LISTS





Read More

CONNECT ROBOT TO PC

| |


 MICROCONTROLLER UART TUTORIAL

What is the UART?
The UART, or Universal Asynchronous Receiver / Transmitter, is a feature of your microcontroller useful for communicating serial data (text, numbers, etc.) to your PC. The device changes incoming parallel information (within the microcontroller/PC) to serial data which can be sent on a communication line.
Adding UART functionality is extremely useful for robotics. With the UART, you can add an LCD, bootloading, bluetooth wireless, make a datalogger, debug code, test sensors, and much more!
Understanding the UART could be complicated, so I filtered out the useless information and present to you only the useful need-to-know details in an easy to understand way . . . The first half of this tutorial will explain what the UART is, while the second half will give you instructions on how to add UART functionality to your  robot.
What is RS232, EIA-232, TTL, serial, and USB?
These are the different standards/protocols used from transmitting data. They are incompatible with each other, but if you understand what each is, then you can easily convert them to what you need for your robot.

RS232
RS232 is the old standard and is starting to become obsolete. Few if any laptops even have RS232 ports (serial ports) today, with USB becoming the new universal standard for attaching hardware. But since the world has not yet fully swapped over, you may encounter a need to understand this standard.
Back in the day circuits were noisy, lacking filters and robust algorithms, etc. Wiring was also poor, meaning signals became weaker as wiring became longer (relates to resistance of the wire). So to compensate for the signal loss, they used very high voltages. Since a serial signal is basically a square wave, where the wavelengths relate to the bit data transmitted, RS232 was standardized as +/-12V. To get both +12V and -12V, the most common method is to use the MAX232 IC (or ICL232 or ST232 - different IC's that all do the same thing), accompanied with a few capacitors and a DB9 connector. But personally, I feel wiring these up is just a pain . . . here is a schematic if you want to do it yourself (instead of a kit):


EIA232F
Today signal transmission systems are much more robust, meaning a +/-12V signal is unnecessary. The EIA232F standard (introduced in 1997) is basically the same as the RS232 standard, but now it can accept a much more reasonable 0V to 5V signal. Almost all current computers (after 2002) utilize a serial port based on this EIA-232 standard. This is great, because now you no longer need the annoying MAX232 circuit!
Instead what you can use is something called the RS232 shifter - a circuit that takes signals from the computer/microcontroller (TTL) and correctly inverts and amplifies the serial signals to the EIA232F standard.
If you'd like to learn more about these standards, check out this RS232 and EIA232 tutorial (external site).
The cheapest RS232 shifter I've found is the $7 RS232 Shifter Board Kit from SparkFun. They have schematics of their board posted if you'd rather make your own.
This is the RS232 shifter kit in the baggy it came in . . .


And this is the assembled image. Notice that I added some useful wire connectors that did not come with the kit so that I may easily connect it to the headers on my microcontroller board. Also notice how two wires are connected to power/ground, and the other two are for Tx and Rx (I'll explain this later in the tutorial).


TTL and USB
The UART takes bytes of data and transmits the individual bits in a sequential fashion. At the destination, a second UART re-assembles the bits into complete bytes.
You really do not need to understand what TTL is, other than that TLL is the signal transmitted and received by your microcontroller UART. This TTL signal is different from what your PC serial/USB port understands, so you would need to convert the signal.
You also do not really need to understand USB, other than that its fast becoming the only method to communicate with your PC using external hardware. To use USB with your robot, you will need an adaptor that converts to USB. You can easily find converters under $20, or you can make your own by using either the FT232RL or CP2102 IC's.
Signal Adaptor Examples
Without going into the details, and without you needing to understand them, all you really need to do is just buy an adaptor.
For example:
TTL -> TTL to RS232 adaptor -> PC
TTL -> TTL to EIA-232 adaptor -> PC
TTL -> TTL to EIA-232 adaptor -> EIA-232 to USB adaptor -> PC
TTL -> TTL to USB adaptor -> PC
TTL -> TTL to wireless adaptor -> wireless to USB adaptor -> PC
If you wanted bluetooth wireless, get a TTL to bluetooth adaptor, or if you want ethernet, get a TTL to ethernet adaptor, etc. There are many combinations, just choose one based on what adaptors/requirements you have. For example, if your laptop only has USB, buy a TTL to USB adaptor as shown with my SparkFun Breakout Board for CP2103 USB:


There are other cheaper ones you can buy today, you just need to look around.
On the left of this below image is my $15 USB to RS232 adaptor, and the right cable is my RS232 extension cable for those robots that like to run around:


Below is my USB to wireless adaptor that I made in 2007 (although now companies sell them wired up for you). It converts a USB type signal to a TTL type signal, and then my Easy Radio wireless transmitter converts it again to a method easily transmitted by air to my robot:


And a close-up of the outputs. I soldered on a male header row and connected the ground, Tx, and Rx to my wireless transmitter. I will talk about Tx and Rx soon:



Even my bluetooth transceiver has the same Tx/Rx/Power/Ground wiring:

If you have a CMUcam or GPS, again, the same connections.

Other Terminology . . .

Tx and Rx
As you probably guessed, Tx represents transmit and Rx represents receive. The transmit pin always transmits data, and the receive pin always receives it. Sounds easy, but it can be a bit confusing . . .
For example, suppose you have a GPS device that transmits a TTL signal and you want to connect this GPS to your microcontroller UART. This is how you would do it:


Notice how Tx is connected to Rx, and Rx is connected to Tx. If you connect Tx to Tx, stuff will fry and kittens will cry. If you are the type of person to accidentally plug in your wiring backwards, you may want to add a resistor of say ~2kohm coming out of your UART to each pin. This way if you connect Tx to Tx accidentally, the resistor will absorb all the bad ju-ju (current that will otherwise fry your UART).
Tx pin -> connector wire -> resistor -> Rx pin
And remember to make your ground connection common!
Baud Rate
Baud is a measurement of transmission speed in asynchronous communication. The computer, any adaptors, and the UART must all agree on a single speed of information - 'bits per second'.
For example, your robot would pass sensor data to your laptop at 38400 bits per second and your laptop would listen for this stream of 1s and 0s expecting a new bit every 1/38400bps = 26us (0.000026 seconds). As long as the robot outputs bits at the pre-determined speed, your laptop can understand it.
Remember to always configure all your devices to the same baud rate for communication to work!
Data bits, Parity, Stop Bits, Flow Control
The short answer: don't worry about it. These are basically variations of the signal, each with long explanations of why you would/wouldn't use them. Stick with the defaults, and make sure you follow the suggested settings of your adaptor. Usually you will use 8 data bits, no parity, 1 stop bit, and no flow control - but not always. Note that if you are using a PIC microcontroller you would have to declare these settings in your code (google for sample code, etc). I will talk a little more about this in coming sections, but mostly just don't worry about it.
Bit Banging
What if by rare chance your microcontroller does not have a UART (check the datasheet), or you need a second UART but your microcontroller only has one? There is still another method, called bit banging. To sum it up, you send your signal directly to a digital input/output port and manually toggle the port to create the TTL signal. This method is fairly slow and painful, but it works . . .

Asynchronous Serial Transmission
As you should already know, baud rate defines bits sent per second. But baud only has meaning if the two communicating devices have a synchronized clock. For example, what if your microcontroller crystal has a slight deviation of .1 second, meaning it thinks 1 second is actually 1.1 seconds long. This could cause your baud rates to break!
One solution would be to have both devices share the same clock source, but that just adds extra wires . . . All of this is handled automatically by the UART, but if you would like to understand more, continue reading . . .
Asynchronous transmission allows data to be transmitted without the sender having to send a clock signal to the receiver. Instead, the sender and receiver must agree on timing parameters in advance and special bits are added to each word which are used to synchronize the sending and receiving units.
When a word is given to the UART for Asynchronous transmissions, a bit called the "Start Bit" is added to the beginning of each word that is to be transmitted. The Start Bit is used to alert the receiver that a word of data is about to be sent, and to force the clock in the receiver into synchronization with the clock in the transmitter. These two clocks must be accurate enough to not have the frequency drift by more than 10% during the transmission of the remaining bits in the word. (This requirement was set in the days of mechanical teleprinters and is easily met by modern electronic equipment.)


When data is being transmitted, the sender does not know when the receiver has 'looked' at the value of the bit - the sender only knows when the clock says to begin transmitting the next bit of the word.
When the entire data word has been sent, the transmitter may add a Parity Bit that the transmitter generates. The Parity Bit may be used by the receiver to perform simple error checking. Then at least one Stop Bit is sent by the transmitter.
When the receiver has received all of the bits in the data word, it may check for the Parity Bits (both sender and receiver must agree on whether a Parity Bit is to be used), and then the receiver looks for a Stop Bit. If the Stop Bit does not appear when it is supposed to, the UART considers the entire word to be garbled and will report a Framing Error to the host processor when the data word is read. The usual cause of a Framing Error is that the sender and receiver clocks were not running at the same speed, or that the signal was interrupted.
Regardless of whether the data was received correctly or not, the UART automatically discards the Start, Parity and Stop bits. If the sender and receiver are configured identically, these bits are not passed to the host.
If another word is ready for transmission, the Start Bit for the new word can be sent as soon as the Stop Bit for the previous word has been sent.
In short, asynchronous data is 'self synchronizing'.
The Loop-Back Test
The loop-back test is a simple way to verify that your UART is working, as well as to locate the failure point of your UART communication setup.
For example, suppose you are transmitting a signal from your microcontroller UART through a TTL to USB converter to your laptop and it isn't working. All it takes is one failure point for the entire system to not work, but how do you find it?
The trick is to connect the Rx to the Tx, hence the loop-back test.
For example, to verify that the UART is outputting correctly:
  • connect the Rx and Tx of the UART together
  • printf the letter 'A'
  • have an if statement turn on a LED if 'A' is received
If it still doesn't work, you know that your code was the failure point (if not more than one failure point). Then do this again on the PC side using HyperTerminal, directly connecting Tx and Rx of your USB port.
And then yet again using the TTL to USB adaptor.
You get the idea . . .
I'm willing to bet that if you have a problem getting it to work, it is because your baud rates aren't the same/synchronized.
You may also find it useful to connect your Tx line to an oscilloscope to verify your transmitting frequency:

Top waveform: UART transmitted 0x0F
Bottom waveform: UART received 0x0F

Adding UART Functions to AVR and your  Robot
To add UART functionality to your robot (or any AVR based microcontroller) you need to make a few minor modifications to your code and add a small amount of extra hardware.
Full and Half Duplex
Full Duplex is defined by the ability of a UART to simultaneously send and receive data. Half Duplex is when a device must pause either transmitting or receiving to perform the other. A Half Duplex UART cannot send and receive data simultaneously. While most microcontroller UARTs are Full Duplex, most wireless transceivers are Half Duplex. This is due to the fact that it is difficult to send two different signals at the same time under the same frequency, resulting in data collision. If your robot is wirelessly transmitting data, in effect it will not be able to receive commands during that transmission, assuming it is using a Half Duplex transmitter.
Step-by-step instructions on how to add UART functionality to your  robot is uploaded in fewdays .










Read More

Theory of radio

| |

One of the more fascinating applications of electricity is in the generation of invisible ripples of energy called radio waves. The limited scope of this lesson on alternating current does not permit full exploration of the concept, some of the basic principles will be covered.

With Oersted's accidental discovery of electromagnetism, it was realized that electricity and magnetism were related to each other. When an electric current was passed through a conductor, a magnetic field was generated perpendicular to the axis of flow. Likewise, if a conductor was exposed to a change in magnetic flux perpendicular to the conductor, a voltage was produced along the length of that conductor. So far, scientists knew that electricity and magnetism always seemed to affect each other at right angles. However, a major discovery lay hidden just beneath this seemingly simple concept of related perpendicularity, and its unveiling was one of the pivotal moments in modern science.

This breakthrough in physics is hard to overstate. The man responsible for this conceptual revolution was the Scottish physicist James Clerk Maxwell (1831-1879), who "unified" the study of electricity and magnetism in four relatively tidy equations. In essence, what he discovered was that electric and magnetic fields were intrinsically related to one another, with or without the presence of a conductive path for electrons to flow. Stated more formally, Maxwell's discovery was this:

A changing electric field produces a perpendicular magnetic field, and

A changing magnetic field produces a perpendicular electric field.

All of this can take place in open space, the alternating electric and magnetic fields supporting each other as they travel through space at the speed of light. This dynamic structure of electric and magnetic fields propagating through space is better known as an electromagnetic wave.

There are many kinds of natural radiative energy composed of electromagnetic waves. Even light is electromagnetic in nature. So are X-rays and "gamma" ray radiation. The only difference between these kinds of electromagnetic radiation is the frequency of their oscillation (alternation of the electric and magnetic fields back and forth in polarity). By using a source of AC voltage and a special device called an antenna, we can create electromagnetic waves (of a much lower frequency than that of light) with ease.

An antenna is nothing more than a device built to produce a dispersing electric or magnetic field. Two fundamental types of antennae are the dipole and the loop:



While the dipole looks like nothing more than an open circuit, and the loop a short circuit, these pieces of wire are effective radiators of electromagnetic fields when connected to AC sources of the proper frequency. The two open wires of the dipole act as a sort of capacitor (two conductors separated by a dielectric), with the electric field open to dispersal instead of being concentrated between two closely-spaced plates. The closed wire path of the loop antenna acts like an inductor with a large air core, again providing ample opportunity for the field to disperse away from the antenna instead of being concentrated and contained as in a normal inductor.

As the powered dipole radiates its changing electric field into space, a changing magnetic field is produced at right angles, thus sustaining the electric field further into space, and so on as the wave propagates at the speed of light. As the powered loop antenna radiates its changing magnetic field into space, a changing electric field is produced at right angles, with the same end-result of a continuous electromagnetic wave sent away from the antenna. Either antenna achieves the same basic task: the controlled production of an electromagnetic field.



When attached to a source of high-frequency AC power, an antenna acts as a transmitting device, converting AC voltage and current into electromagnetic wave energy. Antennas also have the ability to intercept electromagnetic waves and convert their energy into AC voltage and current. In this mode, an antenna acts as a receiving device:

Read More