Monday, September 6, 2010

Portable MP3 Player



Final circuit with pushbuttons (front right), MCU (front left),
Multimedia card (middle left) and decoder/DAC board (gold board in back)


Introduction

In the recent years, the MPEG Layer III (MP3) music compression format has become an extremely popular choice for digital audio compression. Its high compression ratio, and near CD quality sound make it a logical choice for storing and distributing music - especially over the internet, where space and bandwidth are important considerations. As a result of the MP3 popularity, a variety of portable MP3 players have entered into the market in an attempt to capitalize on the demand for portable, high quality music. In 1999, over 1.5 million portable MP3 players were sold worldwide and research projects the sale of over 30 million devices per year by 2005. We decided to design and implement a portable MP3 player similar to products currently available (e.g. Diamond Rio, Creative Labs Nomad, etc.).

Our goal was to design a scaled down version of an otherwise marketable product with minimal cost. Our intent was to ensure that our end result would be expandable to include all of the functionality of the most popular players on the market.


High Level Design

We used the ATMEL AT90S8535 microcontroller to control the components and data flow.

Our design supports standard MP3 file formats with a bitrate of 128Kbps. The decoder chip that we used supports rates from 8Kbps-320Kbps, but we decided it would be simpler to support one bitrate, and then expand the design to support other rates. Our decoder required the incoming bitstream to be equivalent to the decoded bitstream (128Kbps). Because our memory card has a memory latency of 1.5ms and the decoder has a 256-byte buffer - we decided to send data in 256 byte blocks. At 128Kbps, 256 bytes will expire in 16ms, requiring a new data block. A major concern of this technique was buffer underrun/overrun. We prevented this by initially filling the buffer completely before starting to decode. Once running, a block is requested every 16ms, however the first request is sent approximately 8.5 ms after decode start to ensure that the buffer never contains more than 250 bytes and leaves us with just over 7ms to request and receive a block of data. These calculations are considered trivial and left as an exercise to the reader! :)

The pushbuttons are used to control the operation of the player. The four functions implemented with four buttons are play, stop, next track, previous track.


Program/Hardware Design

The parts used in this project were:

  • ATMEL AT90S8535
  • ST MicroElectronics STA013 (MP3 decoder)
  • Crystal/Cirrus Logic CS4331 (18 bit serial DAC)
  • SanDisk Multimedia Card (16MB serial flash card)
  • 10 MHz crystal for decoder
  • 4 MHz oscillator for MCU
  • Function generator (replaceable by 11.2896MHz oscillator)
  • resistors, capacitors, bipolar transistors, diodes, and connectors

Schematic

Level shifting circuits

All the components used in the design are 3.3V except the ATMEL MCU that is 5V. As a result, every line that interfaced between the MCU and the other components needed to be level shifted. Lines that were unidirectional used the following circuits:

Step-up

Step-down

One line was bi-directional and used both the step-up and step-down circuits but were connected to two port pins on the MCU, one for input and one for output, to avoid incorrect level detection.

Interfaces

The Multimedia Card (MMC) uses an SPI interface to control the card and transfer data. It is a four-line interface: SS, SCLK, MOSI, and MISO. To send a command to the card, the user must lower SS, put data on the MOSI line, and toggle SCLK (data is sampled on the rising edge for the MMC). After receiving a command, the MMC will respond with a response byte, followed by any data that was requested. A specific initialization sequence must be followed on power-up to the card in order to put the MMC in SPI mode. On a data request, the MMC will send a 0x00 response byte, followed some time later by a data token (0xfe) and a block of data. In order to read a byte from the slave on the MISO line, the master must send a byte of 0xff on the MOSI line. The SPI interface is implemented using MCU hardware, but the SS line is toggled manually with a separate command. The MCU operates as the master, and the MMC is the slave.

***SPI Note*** The ATMEL STK200 development board has a resistor pack between the PORTB header (SPI pins) and the chip for ISP programming. As a result communication between the MCU and another device (especially another MCU as a slave) does not work correctly. The programming resistors disrupt the voltage enough to sabotage communication. The simple work-around that we came up with is connecting to the LED jumpers instead of the header. This effectively connects directly to the port pins on the chip.

The MP3 decoder chip has three interfaces: a serial interface for incoming data , an I2C interface for control, and a serial PCM interface for the decoded bitstream.

The serial input has three lines, SCLK, SDATA, and BIT_ENABLE. All data on the SDATA line is ignored while BIT_ENABLE is low. We connected the data and clock lines directly to the MMC SCLK and MISO lines and controlled the BIT_ENABLE line with the MCU. The bit enable line is raised when we receive the data token from the MMC, and is lowered after 256 bytes have exchanged.

The I2C interface is a standard two-line interface, SDA, and SCL. This is used to initialize and control the MP3 decoder. The MP3 decoder has a set of registers that must be written on start-up using I2C. The ATMEL web site has an implementation of the I2C interface which we were able to use with slight modification.

The PCM interface is used to send decoded data to the DAC for conversion to an audio signal. There is an over sampling clock which is supplied by an external oscillator (11.2896MHz - we did not realize this clock needed to be supplied, and ended up using a function generator because we did not have time to order another oscillator). There is an left-right channel clock that is operating at 44.1Khz (the sampling frequency of the MP3 files) that is obtained from the OCLK. There is also a serial data line and a serial clock line. The DAC used can operate in a variety of modes, configurable through the STA013.

Memory Format

Programming the MMC was done through a PC's parallel port. We wrote a programmer in C++ which initializes the MMC and programs it (Source code is included). The programmer is a DOS executable, and a file named tracks.lst must be included in the same directory along with all MP3 files that are to be written to the card. Tracks.lst contains the filenames of the MP3 files in the format:

track1.mp3
track2.mp3
.
.
.
lasttrack.mp3

There cannot be any extra characters at the end of a line (spaces, periods, etc.), filenames should be limited to 8 characters, and there is no bounds checking in the programmer. The user is responsible for ensuring the file size does not exceed the size of the MMC (we chose to do it this way so that larger memory cards could be programmed with the same programmer).

The programmer also builds and writes a table of contents for the MMC, which we designed to allow for simple addition of tracks without reprogramming the entire card (this feature was not included in the programmer). Address locations are 32 bits, so four bytes are allotted for each track in the TOC. Address location 0x0000 contains the number of tracks on the card. Address locations 0x0001, 0x0002, 0x0003, 0x0004 contain the address of track 1 with the MSB in 0x0001. The next track address is placed in the next 4 bytes. The 4 bytes following the address of the last track contains the address of the first non-valid memory location on the card. This allows us to stop decoding before reaching invalid data.

Address

Contents

0x0000

number of tracks

0x0001

MSB of track 1 address

0x0002

track 1 address

0x0003

track 1 address

0x0004

LSB of track 1 address

. . .

. . .

. . .

. . .

. . .

. . .

0x000?

MSB of invalid data addr

+1

invalid data address

+1

invalid data address

+1

LSB of invalid data addr

On start-up of the MMC the TOC is read from the MMC and put into SRAM. This allows for quick and easy determination of the memory locations of any track. The formula for the location of the address of the next track is 4*current track + 1.

Program Structure

Setup the MCU:
Setup SPI
Setup I2C interface ports
Setup pushbutton ports
Setup timer1 for reset on compare match (do not enable timer yet) ~8.5ms
Setup UART (for testing and design only)
Initialize all variables
Enable interrupts

Initialize the MMC:
Power up sequence
Put in SPI mode
Set Read Block length to block size (256 bytes)

Read the TOC and put into SRAM
Load the address of track 1 into address registers
Load the end of card addresses into the endcard registers

Initialize the Decoder:
Initialize I2C
Write all registers

Send 1 Block to Decoder
Write the RUN register of the decoder to enable decoding
Write the PLAY register of the decoder to start decoding
Start timer1

State Machine:
MMC_read yet?
Send the next block - set the timer to interrupt on 16ms
Increment the address - check for end of card
Error checking for mp3 decoding ( there is a frame count register in the decoder that should be incrementing)
Check push buttons?
Alter play state, and address counters as appropriate - checking for end of card


Results of the Design

The player successfully played our test MP3s! We were able to add pushbutton functionality to control play, stop, next and prev. This allowed us to change tracks and stop at any time.

Sound quality was as good as could be expected from a protoboard and several feet of interconnecting wires. We did not achieve CD quality, but we were not expecting to get it. The decoder does drop an occasional MPEG frame, causing a crack or hiss. This was probably attributable to the inaccuracy of the function generator in supplying the oversampling clock. We did try several oscillator circuits to try to replace the function generator but could not get them to work at 11MHz.

We also were able to remove the ATMEL chip from the development board and use 4 AA cell batteries to draw power for the MCU, the decoder, and the MMC. The ATMEL chip uses all four batteries, while the other components are only using two cells to generate 3V. Moving the MCU to the protoboard allows the unit to become portable (with the exception of the function generator).


What would we do differently next time???

There are a couple of things we would do differently or add to the design if we had to do it again. The first thing would be to use an MCU that is capable of running at 3.3V. This would have eliminated the extraneous level shifting circuitry that took up so much space and time (not to mention Tylenol). We also believe that our sound quality would have been better if we were able to remove the extra wires and transistors.

Another issue in the design was the use of surface mount components - the STA013 was only available in surface mount, and the DAC recommended by STM was also surface mount. This was very time consuming, but really just an inconvenience and probably did not affect the result significantly.

Our implementation was not as portable as we had hoped. Given more time, or the opportunity to do this again, we would probably have used an oscillator instead of the function generator.

The last change we would have made to our design would be to support variable bitrates. We chose 128Kbps because we found it to be common and was easy to work with. In order to work at higher bitrates, we would have had to adjust the SPI interface to run at CLK/4 instead of CLK/16. We experimented with different SPI clock rates but could not effectively communicate with the MMC at the higher rate. This could have been a result of the level shifting circuitry adding delay, extra capacitance, or even as simple as a setting in the SPI register. Because we were only going to add variable bitrates as an add-on we did not explore the problem in depth.

Digital Multiple Voltage Power Supply

Description
This is simple to build microcontroller controlled power supply that can switch between 5 (or 32 or more) preconfigured voltages between 1.2 to 33 volts dc and up to 3 amps. This guide will walk you through every aspect of the building process; however some basic familiarity with electronics and microcontrollers will be required to program the microcontroller.


Specifications

Input Voltage: 33 Volts DC* Max
Input Current: 3 Amps Max
Output Voltage: 5 Preset Voltages Between 1.2 to 33** Volts DC
Output Current: 3 Amps Max
*There is no bridge rectifier so the input voltage
must be DC
**Output voltage won�t exceed input voltage


The hart of this circuit is a LM350 adjustable positive voltage regulator (T2). The voltage regulator is capable of supplying in excess of 3 amps over an output voltage range of 1.2Vdc to 33Vdc. Its ease of use, thermal overload protection, large voltage range, current limiting, and high ripple rejection make it a great choice for a variable power supply. The voltage (on the Vout pin) is regulated by the current traveling out the ADJ pin through a resistor to ground. Therefore by changing the resistance the outputted voltage will change.
Changing the resistance is controlled by an Atmel ATtiny2313 microcontroller (U1). The microcontroller has 2 main functions collecting user input and changing the output. Collecting user input is easy; there are two buttons (S1-S2), one to go to the next voltage and the other to go to the previous voltage. The buttons are connected to the microcontroller pins PD2 and PD3. When a button is pressed the microcontroller sees a high signal (+5 volts) on the corresponding pin. The rest of the time, when a button is not pressed the microcontroller sees a low signal (0 volts) on the corresponding pin because the pin in connected to ground trough a resistor (R2-R3), called a pull down resistor.


When the microcontroller sees an input pin change from low to high, it sends a high signal (+5 volts) to an output pin. There are five output pins PB0 PB1 PB2 PB3 PB4, each going through a small current limiting resistor (R4-R8) to a led (D2-D6), so you can see what the current selected voltage is, then to the base pin of a small 2n2222 transistor (Q1-Q5).



Each transistor has a resistor connected to its collector pin and its emitter pin connected to ground. When the transistor receives voltage on its base pin, power will flow from the collector to the emitter. This basically turns a resistor on or off which changes the current on the ADJ pin of the LM350 (T2).
The LM7805 (T1) is just a basic fixed 5 volt dc regulator to provide power to the microcontroller.
Diode D1 protects the circuit from a positive voltage being attached to ground.
Capacitors C1 C2 C3 C4 and C5 are used to keep steady power and decouple parts of the circuits.

The LEDs don�t need to be mounted to the PCB. They can be mounted in a panel to easily display the selected voltage, or excluded completely and replaced with a jumper wire. They are currently set at the following values:
D2 -> 3.3v, D3 -> 5v, D4 -> 7v, D5 -> 9v, D6 -> 12v
Changing the value of R9-R15 will change the preset voltages to any voltage you want.
Where Ra is the component R9 and Rb is the component R10-R14 in parallel with R15. Remember that R10-R14 is in parallel with R15 and their value needs to be calculated as such.





Schematic


click for higher resolution

Diagramms





Parts List

Quantity

Reference

Description
1

R1

12k Ohm 1/8 Watt Resistor
2

R2, R3

10k Ohm 1/8 Watt Resistor
5

R4-R8

220 Ohm 1/8 Watt Resistor
1

R9

220 Ohm 1/4 Watt Resistor
1

R10

430 Ohm 1/8 Watt Resistor
1

R11

940 Ohm 1/8 Watt Resistor
1

R12

1874 Ohm 1/8 Watt Resistor
1

R13

3.6k Ohm 1/8 Watt Resistor
1

R14

13.6k Ohm 1/8 Watt Resistor
1

R15

2.2k Ohm 1/8 Watt Resistor





1

C1

2000uF 50v Capacitor
1

C2

470nF 50v Capacitor
2

C3, C4

100nF Capacitor
1

C5

47uF Capacitor





1

U1

Atmel ATTINY2313 Microcontroller





5

Q1-Q5

2N2222 NPN Transistor





1

D1

1N5402 3 Amp Diode
5

D2-D6

5mm generic LED





1

T1

7805 voltage regulator 5volt
1

T2

LM350T





2

S1, S2

Generic Momentary Switch or Button
2

J1*, J2*

Tyco 282841-2
*Not necessary

MCU Programming

The C# code for the microcontroller is in the file: MCU_Power_Supply.c
It can be easily modified to control 36 different voltages with this same circuit.

Set the SUT_CKSEL fuse to: �Int. RC Osc. 4 MHz; Start-up time: 14 CK + 65 ms�
Make sure the CKDIV8 fuse is not set.

The PCB also has connections for Rx Tx and PD6 so that an LCD display
, computer control, and extra inputs and outputs can easily be added.

Low Cost Universal Battery Charger Schematic

Low cost solution for charging of both NiCd and NiMh batteries


Here is the circuit diagram of a low cost universal charger for NiCD - NiMH batteries. This circuit is Ideal for car use. It has ability to transform a mains adapter in to a charger . This one can be used to charge cellular phone, toys, portables, video batteries, MP3 players, ... and has selectable charge current. An LED is located in circuit to indicate charging. Can be built on a general purpose PCB or a veroboard. I hope you really like it.





Picture of the circuit:
Circuit diagram:
A Low Cost Universal Battery Charger Circuit Diagram For NiCD and NiMH
A Low Cost Universal Charger Circuit Diagram
A Low Cost Universal Battery Charger Circuit Schematic For NiCD and NiMH
A Low Cost Universal Charger Circuit Schematic

Circuit diagram:

A Low Cost Universal Battery Charger Circuit Diagram For NiCD and NiMH
A Low Cost Universal Charger Circuit Diagram

Parts:

R1 = 120R-0...5W
R2 = See Diagram
C1 = 220uF-35V
D1 = 1N4007
D2 = 3mm. LED
Q1 = BD135
J1 = DC Input Socket


Specifications:

* Ideal for in car use.
* LED charge indication.
* Selectable charge current.
* Charges Ni Cd or NiMH batteries.
* Transforms a mains adapter into a charger.
* Charge cellular phone, toys, portables, video batteries …



Features:

* LED function indication.
* Power supply polarity protected.
* Supply current: same as charge current.
* Supply voltage: from 6.5VDC to 21VDC (depending on used battery)
* Charge current (±20%): 50mA, 100mA, 200mA, 300mA, 400mA. (selectable)



Determining the supply voltage:

This table indicates the minimum and maximum voltages to supply the charger. See supply voltage selection chart below.

Example:

To charge a 6V battery a minimum supply voltage of 12V is needed, the maximum voltage is then 15V.

Voltage selection:

Voltage Selection Chart - Low Cost Universal Battery Charger Circuit Diagram For NiCD and NiMH
Voltage Selection Chart For Low Cost Universal Battery Charger

Determining the charge current:

Before building the circuit, you must determinate how much current will be used to charge the battery or battery pack. It is advisable to charge the battery with a current that is 10 times smaller then the battery capacity, and to charge it for about 15 hours. If you double the charge current , then you can charge the battery in half the time. Charge current selection chart is located in diagram.

Example:

A battery pack of 6V / 1000mAh can be charged with 100mA during 15 hours. If you want to charge faster, then a charge current of 200mA can be used for about 7 hours.


Caution:

The higher charge current, the more critical the charge time must be checked. When faster charging is used, it is advisable to discharge the battery completely before charging. Using a charge current of 1/10 of the capacity will expand the lifetime of the battery. The charge time can easily be doubled without damaging the battery.

Note:

* Mount the transistor together with the heatsink on the PCB, bend the leads as necessary. Take care that the metal back of the transistor touches the heatsink. Check that the leads of the transistor do not touch the heatsink.

Low Cost Universal Battery Charger Schematic

Low cost solution for charging of both NiCd and NiMh batteries


Here is the circuit diagram of a low cost universal charger for NiCD - NiMH batteries. This circuit is Ideal for car use. It has ability to transform a mains adapter in to a charger . This one can be used to charge cellular phone, toys, portables, video batteries, MP3 players, ... and has selectable charge current. An LED is located in circuit to indicate charging. Can be built on a general purpose PCB or a veroboard. I hope you really like it.





Picture of the circuit:
A Low Cost Universal Battery Charger Circuit Schematic For NiCD and NiMH
A Low Cost Universal Charger Circuit Schematic

Circuit diagram:

A Low Cost Universal Battery Charger Circuit Diagram For NiCD and NiMH
A Low Cost Universal Charger Circuit Diagram

Parts:

R1 = 120R-0...5W
R2 = See Diagram
C1 = 220uF-35V
D1 = 1N4007
D2 = 3mm. LED
Q1 = BD135
J1 = DC Input Socket


Specifications:

* Ideal for in car use.
* LED charge indication.
* Selectable charge current.
* Charges Ni Cd or NiMH batteries.
* Transforms a mains adapter into a charger.
* Charge cellular phone, toys, portables, video batteries …



Features:

* LED function indication.
* Power supply polarity protected.
* Supply current: same as charge current.
* Supply voltage: from 6.5VDC to 21VDC (depending on used battery)
* Charge current (±20%): 50mA, 100mA, 200mA, 300mA, 400mA. (selectable)



Determining the supply voltage:

This table indicates the minimum and maximum voltages to supply the charger. See supply voltage selection chart below.

Example:

To charge a 6V battery a minimum supply voltage of 12V is needed, the maximum voltage is then 15V.

Voltage selection:

Voltage Selection Chart - Low Cost Universal Battery Charger Circuit Diagram For NiCD and NiMH
Voltage Selection Chart For Low Cost Universal Battery Charger

Determining the charge current:

Before building the circuit, you must determinate how much current will be used to charge the battery or battery pack. It is advisable to charge the battery with a current that is 10 times smaller then the battery capacity, and to charge it for about 15 hours. If you double the charge current , then you can charge the battery in half the time. Charge current selection chart is located in diagram.

Example:

A battery pack of 6V / 1000mAh can be charged with 100mA during 15 hours. If you want to charge faster, then a charge current of 200mA can be used for about 7 hours.


Caution:

The higher charge current, the more critical the charge time must be checked. When faster charging is used, it is advisable to discharge the battery completely before charging. Using a charge current of 1/10 of the capacity will expand the lifetime of the battery. The charge time can easily be doubled without damaging the battery.

Note:

* Mount the transistor together with the heatsink on the PCB, bend the leads as necessary. Take care that the metal back of the transistor touches the heatsink. Check that the leads of the transistor do not touch the heatsink.

Hardware Control via SMS

System Overview
The system consists of two mobile connected by the existing cellular mobile network. One of the mobile is connected to the computer by USB data cable. The computer contains the series of computer program that is capable of retrieving SMS, processing and directing hardware to produce the desired output. The hardware part is connected to the computer by the parallel port.



2.2 Hardware Description:
2.2.1 Mobiles
The basic component of our project starts with two mobiles. These mobiles are used to send and receive SMS through the available cellular network configurations. One of the mobile is connected to the computer through usb data cable. The other is used by the user to send the SMS to the connected mobile. Since the project’s backbone is the SMS, the SMS has to be fed to the computer and this is done by mobile software which will be discussed under software discription portion.

2.2.2 USB data cable
The USB data cable is the connector that connects different hardwares to the computer. In our project, we have used this cable to connect the mobile to the comptuer.

2.2.3 Parallel Port
Another hardware that plays vital role in the project is the parallel port. The primary use of parallel port is to connect printers to computer and is specifically designed for this purpose. Thus it is often called as printer Port. The lines in parallel port connector are divided in to three groups, they are

1) Data lines (data bus)
2) Control lines
3) Status lines
As the name refers, data is transferred over data lines, Control lines are used to control the peripheral and of course, the peripheral returns status signals back computer through Status lines. These lines are connected to Data, Control and Status registers internally. The details of parallel port pin configuration and signal lines are given below

At this stage, we have tried to light on the led. This is at the simplest stage of the project. When successful in this we intend to extend this part and try other circuits. Many other hardware components can be controlled by using parallel port. Upto this moment, we have used 8 output pins of parallel port indivudally or combination of them. The hardware circuit consists leds that are connected through diodes and reistors. Diodes are used to prevent the back-flow of voltage. It prevents the computer from being damaged since diodes allow one directional current/voltage flow. The output can be taken from pins 1-9, 14, 16, 17 of parallel port .The hardware configuration is shown below.
2.2 Software Discription
As already stated that the project is the combination of SMS, computer program and output hardware, software is the soul of the project. There are various steps of program used in the project which are described below:-
2.2.1 Batch file programming
Batch file is a type of file in computer that allows to store dos commands. We took help of it inorder to convert the SMS file type (*.vmg) to the text file (*.txt) where .vmg and .txt are the extension of the file. The batch file runs as an auto executable file (that is this file will be run at the time of computer startup).These extensions help to recognize the format of the file. The batch file was also used to copy the SMS from mobiles’ phone browser folder to the computer’s memory. This was needed because it was almost impossible to operate on the file with the previous SMS type and location of SMS. The code of the program is as follows:-


@echo off
IF EXIST *.vmg (
Del d:\ \ text.txt
Copy *.vmg d:\
Rename d:\<> *.vmg text.txt
Del *.vmg
Del d:\\*.vmg
Autocopy.bat
)
Autocopy.bat

The batch file is named as autocopy.bat. At first the batch file searches if there appears any new message at inbox or not. If the condition satisfies, the previous text message from destined location will be deleted and new .vmg message will be copied to the required location. This SMS will then be renamed as text file. Then it deletes the SMS from the inbox as well as from the location. Now, again the same autocopy.bat file will be executed to continuously search for the SMS.

2.3.2 Turbo C Programming
Normally, data, control and status registers will have following addresses. We need to provide these addresses in program.
Table 2: Registers address
Register
LPT1
Data register (Base Address + 0)
0x378
Status register (Base Address + 1)
0x379
Control register (Base Address + 2)
0x37a


Now we are using eight data resistors for our output, each of which is read as binary value as below.
D7 - “10000000” D6 – “01000000” D5 – “00100000” D1 – “ 00000010”
Similarly, to read D1, D2 and D6 respectively at once: “01000110”
However; with actual programming, this binary value is replaced by equivalent decimal number to perform the required task.

2.3.2.1 Coding for Parallel Output:
Reaching the ports by using a language differ from port to port. Using Windows 98 we can easily reach the ports with a function which is "outportb". However; when upgraded to Windows 2000 this fails because of its kernel. We can not reach the ports directly in NT, 2000 and XP because of their kernel and their printer drivers. For eg. first we made the circuit as in the fig. 4 and then restarted the computer; for Windows 98, there was no light in the circuit but in Win2000 and XP all the 8 lights are on so we know that the signal is coming and the pins are registered by their kernel with the printerdriver.

Since, our operating system will not be windows 98, as it doesn’t support pc-suite, we need to go hardware interferance as in the below flow chart.


So we have to import inpout32.dll to our debug or release directory. It takes two variables which are address and value. If the data ports are set in "0x378" we have to write "888" because "378" Hexadecimal is equal to "888" in decimal.

The below program will function in windows 98:

#include <conio.h>
#include <dos.h>
#define port 0x378 // Port Address
#define data port+0 // Data Port of the parallel cable
void main (void)
{
outportb(data, 255); // For all lights on
outportb(data, 0); // For all lights off
}

However; if the OS is Windows NT or above, first we must interface with the driver as shown in the flow chart. We are currently working with this type of interface to have better idea before we actually implement such type of coding.

So we have to import inpout32.dll to our debug or release directory. It takes two variables which are address and value. If the data ports are set in "0x378" we have to write "888" because "378" Hexadecimal is equal to "888" in decimal.

The below program will function in windows 98:

#include <conio.h>
#include <dos.h>
#define port 0x378 // Port Address
#define data port+0 // Data Port of the parallel cable
void main (void)
{
outportb(data, 255); // For all lights on
outportb(data, 0); // For all lights off
}

However; if the OS is Windows NT or above, first we must interface with the driver as shown in the flow chart. We are currently working with this type of interface to have better idea before we actually implement such type of coding.
Content of message.txt, fetched from the PC-SUITE:


BEGIN:VMSG
VERSION:1.1
X-IRMC-STATUS:READ
X-IRMC-BOX:INBOX
X-NOK-DT:20081215T085618Z
BEGIN:VCARD
VERSION:2.1
N:
TEL:+9779841346181
END:VCARD
BEGIN:VENV
BEGIN:VCARD
VERSION:2.1
N:
TEL:
END:VCARD
BEGIN:VENV
BEGIN:VBODY
Date:15.12.2008 13:56:18
# SWITCH OFF : 1 #
END:VBODY
END:VENV
END:VENV
END:VMSG
The above program will fetch only the required message #SWITCH OFF : 1# from the program and makes the string compare with the already defined strings to make logical operation and hence to direct output.

Electronic Locker

This circuit is an Electronic Locker. It is controlled by a switches combination (by a code). There is a switch matrix on the door of the locker. This one is a unit of switches connected into 4 arranged of 4 columns for a total of eight terminals. When we press on a switch, this one establishes the contact between its column and its line. This switch matrix is also used in the telephones, for example. But it is numbered from 0 to 9 and from A to F for a total of 16 switches. To open the locker, we have to press 4 specific and different switches in the good order. If for example the code is 0,1,2,3 and we press two times to the same switches: 0,1,2,2,3 the locker won't open. In this circuit, the code is 0,1,2,3 but we can set the desired code when we built de circuit. The desired line (called "stage" in the schematic) is connected to the ground and to a pin of the 3.3k resistor and the other line is connected to an input of the 7408 and to the other pin of the resistor.





Circuit diagram


All the desired numbers of the code are in the same line. To set the order of the number of the code, we have to set the good connection between the node of the 7414 input and the appropriate node of the capacitor. For example, if we select the first line (y1) and the code is 0,1,2,3 the first number (#1) is connected to the top left contact (x1). The switch 0 is corresponding to x1/y1. These points of contact are colored in orange in the schematic. When the locker is locked, the red LED is turned on and the green LED is turned off. When the locker is opened, the red LED is turned off and the green LED is turned on. To lock the locker, we can push any of the 16 switches of the matrix. The locker is powered by a 6V source. I recommend using a 6V rechargeable battery because this one lasts a long time (at least 3 full days) and can be re-used. Otherwise, we can use four 1.5V battery connected in serial. These least only 5 hours but are less expensive.
To save energy, we can remove the red LED. When the locker is powered on, it is locked. The electric motor or the inductors close the door while a bit of time and after, stop working. When we open the locker, the electric motor or the inductors open the door while a bit of time and after, stop working. To control the state of the door (open or lock) we can use an electric motor or a pair of inductors. If we use a electric motor, when the locker is closed, the motor turns in the anti-clockwise direction during a certain time and moves down a toothed bar. After this time, the motor stops turning and the locker remains closed. When the locker is opened, the motor turns in the clockwise direction during a certain time and moves up the toothed bar.

After this time, the motor stops turning and the locker remains opened. If we use two inductors, when the locker is closed, the second inductor works during a certain time and moves left a magnetic bar by attraction. After this time, the inductor stops working and the locker remains closed. When the locker is opened, the first inductor works during a certain time and moves right the magnetic bar. After this time, the inductor stops turning and the locker remains opened. The buffer (L293D) who controls the motor or the inductors has two Vcc inputs and four ground connections. The both Vcc inputs must be connected to the +6V and all ground connections must be connected to the ground of the circuit. All the parts of the circuits are placed in the rack except the DELs and the switch matrix which them, are placed on the door.

Digital Stopwatch 0-60sec

Introduction
By using the same circuit of the "Digital Stopwatch 0-99sec", we can add an AND gate, and transform the 0 – 99sec stopwatch to a 0 – 60sec stopwatch.
We must find a way to control the RESET function of the BCD counter, which is responsible for the counting of the seconds. As we studied above, the circuit resets when we have 99 to 100, that is 1001 1001 à 0001 0000 0000. To make a transformation successfully we must force the pulse from 59 to 60 0011 1001 à 0100 0000 on the output of the BCD counter.
By placing the AND gate, with its inputs on the Q1 and Q2 of the BCD counter of the decades, we make sure that when the gate closes, the RST input of the BCD counter will be set to logical “1”, which on its turn, will force the circuit to start over. The transformed circuit appears in picture 2.
Circuit diagram





Digital

Led display digital Voltmeter



front side
Copyright of this circuit belongs to smart kit electronics. In this page we will use this circuit to discuss for improvements and we will introduce some changes based on original schematic.
General Description
This is an easy to build, but nevertheless very accurate and useful digital voltmeter. It has been designed as a panel meter and can be used in DC power supplies or anywhere else it is necessary to have an accurate indication of the voltage present. The circuit employs the ADC (Analogue to Digital Converter) I.C. CL7107 made by INTERSIL. This IC incorporates in a 40 pin case all the circuitry necessary to convert an analogue signal to digital and can drive a series of four seven segment LED displays directly. The circuits built into the IC are an analogue to digital converter, a comparator, a clock, a decoder and a seven segment LED display driver. The circuit as it is described here can display any DC voltage in the range of 0-1999 Volts.





Technical Specifications - Characteristics
Supply Voltage: ............. +/- 5 V (Symmetrical)
Power requirements: ..... 200 mA (maximum)
Measuring range: .......... +/- 0-1,999 VDC in four ranges
Accuracy: ....................... 0.1 %
FEATURES
- Small size
- Easy construction
- Low cost.
- Simple adjustment.
- Easy to read from a distance.
- Few external components.
How it Works
In order to understand the principle of operation of the circuit it is necessary to explain how the ADC IC works. This IC has the following very important features:
- Great accuracy.
- It is not affected by noise.
- No need for a sample and hold circuit.
- It has a built-in clock.
- It has no need for high accuracy external components.

Schematic (fixed 22-2-04)

7-segment display pinout MAN6960
An Analogue to Digital Converter, (ADC from now on) is better known as a dual slope converter or integrating converter. This type of converter is generally preferred over other types as it offers accuracy, simplicity in design and a relative indifference to noise which makes it very reliable. The operation of the circuit is better understood if it is described in two stages. During the first stage and for a given period the input voltage is integrated, and in the output of the integrator at the end of this period, there is a voltage which is directly proportional to the input voltage. At the end of the preset period the integrator is fed with an internal reference voltage and the output of the circuit is gradually reduced until it reaches the level of the zero reference voltage. This second phase is known as the negative slope period and its duration depends on the output of the integrator in the first period. As the duration of the first operation is fixed and the length of the second is variable it is possible to compare the two and this way the input voltage is in fact compared to the internal reference voltage and the result is coded and is send to the display.

back side
All this sounds quite easy but it is in fact a series of very complex operations which are all made by the ADC IC with the help of a few external components which are used to configure the circuit for the job. In detail the circuit works as follows. The voltage to be measured is applied across points 1 and 2 of the circuit and through the circuit R3, R4 and C4 is finally applied to pins 30 and 31 of the IC. These are the input of the IC as you can see from its diagram. (IN HIGH & IN LOW respectively). The resistor R1 together with C1 are used to set the frequency of the internal oscillator (clock) which is set at about 48 Hz. At this clock rate there are about three different readings per second. The capacitor C2 which is connected between pins 33 and 34 of the IC has been selected to compensate for the error caused by the internal reference voltage and also keeps the display steady. The capacitor C3 and the resistor R5 are together the circuit that does the integration of the input voltage and at the same time prevent any division of the input voltage making the circuit faster and more reliable as the possibility of error is greatly reduced. The capacitor C5 forces the instrument to display zero when there is no voltage at its input. The resistor R2 together with P1 are used to adjust the instrument during set-up so that it displays zero when the input is zero. The resistor R6 controls the current that is allowed to flow through the displays so that there is sufficient brightness with out damaging them. The IC as we have already mentioned above is capable to drive four common anode LED displays. The three rightmost displays are connected so that they can display all the numbers from 0 to 9 while the first from the left can only display the number 1 and when the voltage is negative the «-« sign. The whole circuit operates from a symmetrical ρ 5 VDC supply which is applied at pins 1 (+5 V), 21 (0 V) and 26 (-5 V) of the IC.
Construction
First of all let us consider a few basics in building electronic circuits on a printed circuit board. The board is made of a thin insulating material clad with a thin layer of conductive copper that is shaped in such a way as to form the necessary conductors between the various components of the circuit. The use of a properly designed printed circuit board is very desirable as it speeds construction up considerably and reduces the possibility of making errors. To protect the board during storage from oxidation and assure it gets to you in perfect condition the copper is tinned during manufacturing and covered with a special varnish that protects it from getting oxidised and also makes soldering easier.
Soldering the components to the board is the only way to build your circuit and from the way you do it depends greatly your success or failure. This work is not very difficult and if you stick to a few rules you should have no problems. The soldering iron that you use must be light and its power should not exceed the 25 Watts. The tip should be fine and must be kept clean at all times. For this purpose come very handy specially made sponges that are kept wet and from time to time you can wipe the hot tip on them to remove all the residues that tend to accumulate on it.
DO NOT file or sandpaper a dirty or worn out tip. If the tip cannot be cleaned, replace it. There are many different types of solder in the market and you should choose a good quality one that contains the necessary flux in its core, to assure a perfect joint every time.
DO NOT use soldering flux apart from that which is already included in your solder. Too much flux can cause many problems and is one of the main causes of circuit malfunction. If nevertheless you have to use extra flux, as it is the case when you have to tin copper wires, clean it very thoroughly after you finish your work.
In order to solder a component correctly you should do the following:
- Clean the component leads with a small piece of emery paper.
- Bend them at the correct distance from the component’s body and insert the component in its place on the board.
- You may find sometimes a component with heavier gauge leads than usual, that are too thick to enter in the holes of the p.c. board. In this case use a mini drill to enlarge the holes slightly. Do not make the holes too large as this is going to make soldering difficult afterwards.

Parts placement

PCB dimensions: 77,6mm x 44,18mm or scale it at 35%
- Take the hot iron and place its tip on the component lead while holding the end of the solder wire at the point where the lead emerges from the board. The iron tip must touch the lead slightly above the p.c. board.
- When the solder starts to melt and flow wait till it covers evenly the area around the hole and the flux boils and gets out from underneath the solder. The whole operation should not take more than 5 seconds. Remove the iron and allow the solder to cool naturally without blowing on it or moving the component. If everything was done properly the surface of the joint must have a bright metallic finish and its edges should be smoothly ended on the component lead and the board track. If the solder looks dull, cracked, or has the shape of a blob then you have made a dry joint and you should remove the solder (with a pump, or a solder wick) and redo it.
- Take care not to overheat the tracks as it is very easy to lift them from the board and break them.
- When you are soldering a sensitive component it is good practice to hold the lead from the component side of the board with a pair of long-nose pliers to divert any heat that could possibly damage the component.
- Make sure that you do not use more solder than it is necessary as you are running the risk of short-circuiting adjacent tracks on the board, especially if they are very close together.
- When you finish your work, cut off the excess of the component leads and clean the board thoroughly with a suitable solvent to remove all flux residues that may still remain on it.


As it is recommended start working by identifying the components and separating them in groups. There are two points in the construction of this project that you should observe:
First of all the display IC’s are placed from the copper side of the board and second the jumper connection which is marked by a dashed line on the component side at the same place where the displays are located is not a single jumper but it should be changed according to the use of the instrument. This jumper is used to control the decimal point of the display.
If you are going to use the instrument for only one range you can make the jumper connection between the rightmost hole on the board and the one corresponding to the desired position for the decimal point for your particular application. If you are planning to use the voltmeter in different ranges you should use a single pole three position switch to shift the decimal point to the correct place for the range of measurement selected. (This switch could preferably be combined with the switch that is used to actually change the sensitivity of the instrument).
Apart from this consideration, and the fact that the small size of the board and the great number of joints on it which calls for a very fine tipped soldering iron, the construction of the project is very straightforward.
Insert the IC socket and solder it in place, solder the pins, continue with the resistors the capacitors and the multi-turn trimmer P1. Turn the board over and very carefully solder the display IC’s from the copper side of the board. Remember to inspect the joints of the base of the IC as one row will be covered by the displays and will be impossible to see any mistake that you may have made after you have soldered the displays into place.
The value of R3 controls in fact the range of measurement of the voltmeter and if you provide for some means to switch different resistors in its place you can use the instrument over a range of voltages.
For the replacement resistors follow the table below:
0 - 2 V ............ R3 = 0 ohm 1%
0 - 20 V ........... R3 = 1.2 Kohm 1%
0 - 200 V .......... R3 = 12 Kohm 1%
0 - 2000 V ......... R3 = 120 Kohm 1%
When you have finished all the soldering on the board and you are sure that everything is OK you can insert the IC in its place. The IC is CMOS and is very sensitive to static electricity. It comes wrapped in aluminium foil to protect it from static discharges and it should be handled with great care to avoid damaging it. Try to avoid touching its pins with your hands and keep the circuit and your body at ground potential when you insert it in its place.
Connect the circuit to a suitable power supply ρ 5 VDC and turn the supply on. The displays should light immediately and should form a number. Short circuit the input (0 V) and adjust the trimmer P1 until the display indicates exactly «0».
Parts
R1 180k
R2 22k
R3 12k
R4 1M
R5 470k
R6 560 Ohm
C1 100pF
C2, C6, C7 100nF
C3 47nF
C4 10nF
C5 220nF
P1 20k trimmer multi turn
U1 ICL 7107
LD1,2,3,4 MAN 6960 common anode led displays
If it does not work
Check your work for possible dry joints, bridges across adjacent tracks or soldering flux residues that usually cause problems.
Check again all the external connections to and from the circuit to see if there is a mistake there.
- See that there are no components missing or inserted in the wrong places.
- Make sure that all the polarised components have been soldered the right way round. - Make sure the supply has the correct voltage and is connected the right way round to your circuit.
- Check your project for faulty or damaged components.
Sample Power supply 1

Sample Power Supply 2

Labels

About Me

My photo
I am an electrical and electronics engineering kathmandu university batch 2007
 
ELECTRICAL AND ELECTRONICS PROJECT COLLECTION. Design by Wpthemedesigner. Converted To Blogger Template By Anshul Tested by Blogger Templates.