Monday, July 30, 2007

PIC Tutorial (PIC Tutorial 5-Subroutines)

Subroutines
A subroutine is a section of code, or program, than can be called as and when you need it. Subroutines are used if you are performing the same function more than once, for example creating a delay. The advantages of using a subroutine are that it will be easier to alter the value once inside a subroutine rather than, say, ten times throughout your program, and also it helps to reduce the amount of memory your program occupies inside the PIC.
Let us look at a subroutine:
ROUTINE COUNT equ 255
LABEL decfsz COUNT,1
Goto LABEL
RETURN
First, we have to give our subroutine a name, and in this case we have chosen ROUTINE. We then type the code that we want to perform as normal. In this case, We have chosen the delay in our flashing led program. Finally, we end the subroutine by typing the RETURN instruction.
To start the subroutine from anywhere in our program, we simply type the instruction CALL followed by the subroutine name.
Let us look at this in slightly more detail. When we reach the part of our program that says CALL xxx, where xxx is the name of our subroutine, the program jumps to wherever the subroutine xxx resides. The instructions inside the subroutine are carried out. When the instruction RETURN is reached, the program jumps back to our main program to the instruction immediately following our CALL xxx instruction.
You can call the same subroutine as many times as you want, which is why using subroutines reduces the overall length of our program. However, there are two things you should be aware of. First, as in our main program, any constants must be declared before they are used. These can be either declared within the subroutine itself, or right at the start of the main program. We would recommend that you declare everything at the start of your main program, as then you know that everything is in the same place. Secondly, you must ensure that the main program skips over the subroutine. What We mean by this is if you put the subroutine right at the end of your main program, unless you use a ‘Goto’ statement to jump away from where the subroutine is, the program will carry on and execute the subroutine whether you want it to or not. The PIC does not differentiate between a subroutine and the main program.
Let us look at our flashing led program, but this time we will use a subroutine for the delay loop. Hopefully, you will see how much simpler the program looks, and also you will see how the subroutine works for real.

;*****Set up the Constants****
STATUS equ 03h ;Address of the STATUS register
TRISA equ 85h ;Address of the tristate register for port A
PORTA equ 05h ;Address of Port
ACOUNT1 equ 08h ;First counter for our delay loops
COUNT2 equ 09h ;Second counter for our delay loops
;****Set up the port****
bsf STATUS,5 ;Switch to Bank 1
movlw 00h ;Set the Port A pins
movwf TRISA ;to output.
bcf STATUS,5 ;Switch back to Bank 0
;****Turn the LED on****
Start movlw 02h ;Turn the LED on by first putting it
movwf PORTA ;into the w register and then on the port

;****Add a delay
call Delay

;****Delay finished, now turn the LED off****
movlw 00h ;Turn the LED off by first putting it
movwf PORTA ;into the w register and then on the port

;****Add another delay****
call Delay

;****Now go back to the start of the program
goto Start ;go back to Start and turn LED on again

;****Here is our Subroutine

DelayLoop1 decfsz COUNT1,1 ;This second loop keeps the LED
goto Loop1 ;turned off long enough for us to
decfsz COUNT2,1 ;see it turned off
goto Loop1 ;return

;****End of the program****
end ;Needed by some compilers, and also
;just in case we miss the goto instruction.
Hopefully, you can see that by using a subroutine for our delay loop, we have reduced the size of the program. Each time we want a delay, either when the LED is on or off, we simply call the delay subroutine. At the end of the subroutine, the program goes back to the line following our ‘Call’ instruction. In the example above, we turn the LED on. We then call the subroutine. The program then returns so that we can turn the LED off. We call the subroutine again, and when the subroutine has finished, the program returns and the next instruction it sees is ‘goto Start’.
For those of you who are interested, our original program was 120 bytes long. By using the subroutine, we have reduced our program size down to 103 bytes. This may not seem to be that great, but seeing that we only have 1024 bytes in total inside the PIC, every little bit helps.
In the next tutorial, we will look at reading from the ports.

PIC Tutorial (PIC Tutorial 4-Delay Loops)

Delay Loops



There is one slight drawback to our flashing LED program. Each instruction takes one clock cycle to complete. If we are using a 4MHz crystal, then each instruction will take 1/4MHz, or 1uS to complete. As we are using only 5 instructions, the LED will turn on then off in 5uS. This is far too fast for us to see, and it will appear that the LED is permanently on. What we need to do is cause a delay between turning the LED on and turning the LED off.
The principle of the delay is that we count down from a previously set number, and when it reaches zero, we stop counting. The zero value indicates the end of the delay, and we continue on our way through the program.
So, the first thing we need to do is to define a constant to use as our counter. We will call this constant COUNT. Next, we need to decide how big a number to start counting from. Well, the largest number we can have is 255, or FFh in hex. Now, as we mentioned in the last tutorial, the equ instruction assigns a word to a register location. This means that whatever number we assign our COUNT, it will equal the contents of a register.
If we try and assign the value FFh, we will get an error when we come to compile the program. This is because location FFh is reserved, and so we can’t access it. So, how do we assign an actual number? Well, it takes a little bit of lateral thinking. If we assign our COUNT to the address 08h, for example, this will point to a general purpose register location. By default, the unused locations are set to FFh. Therefore, if COUNT points to 08h, it will have the value of FFh when we first switch on.
But, We hear you cry, how do we set COUNT to a different number? Well, all we do is ‘move’ a value to this location first. For example, if we wanted COUNT to have a value of 85h, we can’t say COUNT equ 85h because that is the location of out Tri-State register for Port A. What we do is this:


movlw 85h ;First put the value of 85h in the W register
movwf 08h ;Now move it to our 08h register.

Now, when we say COUNT equ 08h, COUNT will equal the value 85h. Subtle, isn’t it!

So, first we define our constant:

COUNT equ 08h

Next we need to decrease this COUNT by 1 until it reaches zero. It just so happens that there is a single instruction that will do this for us, with the aid of a ‘goto’ and a label. The instruction we will use is:

DECFSZ COUNT,1
This instruction says ‘Decrement the register (in this case COUNT) by the number that follows the comma. If we reach zero, jump two places forward.’ A lot of words, for a single instruction. Let us see it in action first, before we put it into our program.

COUNT equ 08h
LABEL decfsz COUNT,1
goto LABEL

Carry on here.
:
:
:

What we have done is first set up our constant COUNT to 255. The next line puts a label, called LABEL next to our decfsz instruction. The decfsz COUNT,1 decreases the value of COUNT by 1, and stores the result back into COUNT. It also checks to see if COUNT has a value of zero. If it doesn’t, it then causes the program to move to the next line. Here we have a ‘goto’ statement which sends us back to our decfsz instruction. If the value of COUNT does equal zero, then the decfsz instruction causes our program to jump two places forward, and goes to where We have said ‘Carry on here’. So, as you can see, we have caused the program to stay in one place for a predetermined time before carrying on. This is called a delay loop. If we need a larger delay, we can follow one loop by another. The more loops, the longer the delay. We are going to need at least two, if we want to see the LED flash..
Let us put these delay loops into our program, and finish off by making it a real program by adding comments:


;*****Set up the Constants****


STATUS equ 03h ;Address of the STATUS register

TRISA equ 85h ;Address of the tristate register for port A

PORTA equ 05h ;Address of Port

ACOUNT1 equ 08h ;First counter for our delay loops

COUNT2 equ 09h ;Second counter for our delay loops


;****Set up the port****

bsf STATUS,5 ;Switch to Bank 1
movlw 00h ;Set the Port A pins
movwf TRISA ;to output.
bcf STATUS,5 ;Switch back to Bank 0


;****Turn the LED on****

Loop1 decfsz COUNT1,1 ;Subtract 1 from 255
goto Loop1 ;If COUNT is zero, carry on.
decfsz COUNT2,1 ;Subtract 1 from 255
goto Loop1 ;Go back to the start of our loop.
;This delay counts down from
;255 to zero, 255 times



;****Delay finished, now turn the LED off****


movlw 00h ;Turn the LED off by first putting
movwf PORTA ;it into the w register and then on
;the port


;****Add another delay****

Loop2 decfsz COUNT1,1 ;This second loop keeps the


goto Loop2 ;LED turned off long enough for


decfsz COUNT2,1 ;us to see it turned off


goto Loop2 ;



;****Now go back to the start of the program

goto Start ;go back to Start and turn LED


;on again




;****End of the program****

end ;Needed by some compilers,
;and also just in case we miss
;the goto instruction

You can compile this program and then program the PIC. Of course, you will want to try the circuit out to see if it really does work. Here is a circuit diagram for you to build once you have programmed your PIC.



Congratulations, you have just written your first PIC program, and built a circuit to flash an LED on and off. So far, if you have followed these tutorials, you have learnt a total of 7 instruction out of 35, and yet already you are controlling the I/O ports!
Why not try and alter the delay loops to make the LED flash faster – what is the minimum value of COUNT to actually see the LED flash? Or, why not add a third or even more delay loops after the first one to slow the LED down. You will need a different constant for each delay loop. You could then even adjust your delay loops to make the LED flash at a given rate, for example once a second.
In the next tutorial we will see how we can use a thing called a subroutine to help keep the program small and simple.

Friday, July 27, 2007

PIC Tutorial (PIC Tutorial 3- Writing To the Ports)

Writing To the Ports

In the last tutorial, we showed you how to set up the IO port pins on the PIC to be either input or output. In this tutorial, We are going to show you how to send data to the ports. In the next tutorial, we will finish off by flashing an LED on and off which will include a full program listing and a simple circuit diagram so that you can see the PIC doing exactly what we expect it to. Don’t try and compile and program your PIC with the listings here, as they are examples only.
First, let us set up Port A bit 2 as an output:

bsf 03h,5 ;Go to Bank 1
movlw 00h ;Put 00000 into W
movwf 85h ;Move 00000 onto TRISA – all pins set to output
bcf 03h,5 ;Come back to Bank 0

This should be familiar from the last tutorial. The only difference is that we have set all of the pins on Port A as output, by sending 0h to the tri-state register.
Now what he have to do is turn an LED on. We do this by making one of the pins (the one with the LED connected to it) high. In other words, we send a ‘1’ to the pin. This is how it’s done (note the comments for an explanation of each line):

movlw 02h ;Write 02h to the W register. In binary this is 00010, which ;puts a ‘1’ on bit 2 (pin 18) while keeping the other pins to ‘0’
movwf 05h ;Now move the contents of W (02h) onto the PortA, whose ;address is 05h


So, what we have done is turn the LED on then off once.
What we want is for the LED to turn on then off continuously. We do this by getting the program to go back to the beginning. We do this by first defining a label at the start of our program, and then telling the program to keep going back there.

Start movlw 02h ;Write 02h to the W register. In binary is this 00010, which puts a ;‘1’ on pin 2 while keeping the other pins to ‘0’
movwf 05h ;Now move the contents of W (02h) onto the ;PortA, whose address is 05h
movlw 00h ;Write 00h to the W register. This puts a ‘0’ on ;all pins.
movwf 05h ;Now move the contents of W (0h) onto the Port ;A, whose address is 05h
goto Start ;Goto where we say Start


As you can see, we first said the word ‘Start’ right at the beginning of the program. Then, right at the very end of the program we simply said ‘goto Start’. The ‘goto’ instruction does exactly what it says.
This program will continuously turn the LED on and off as soon as we power up the circuit, and will stop when we remove power.
We think we should look at our program again:

bsf 03h,5
movlw 00h
movwf 85h
bcf 03h,5
Start movlw 02h
movwf 05h
movlw 00h
movwf 05h
goto Start


OK, We know we have left the comments off. But, do you notice that all we can see are instructions and numbers? This can be a little confusing if you are trying to debug the program later, and also when you write the code you have to remember all of the addresses. Even with the comments in place, it can get a bit messy. What we need is to give these numbers names. This is accomplished by another instruction: ‘equ’.
The ‘equ’ instruction simply means something equals something else. It is not an instruction for the PIC, but for the assembler. With this instruction we can assign a name to a register address location, or in programming terms assign a constant. Let us set up some constants for our program, then you will see how much easier to read the program is.

STATUS equ 03h ;this assigns the word STATUS to the value of 03h, ;which is the address of the STATUS register.
TRISA equ 85h ;This assigns the word TRISA to the value of 85h, ;which is the address of the Tri-State register for PortA
PORTA equ 05h ;This assigns the word PORTA to 05h which is the ;address of Port A.

So, now we have set up our constant values, let us put these into our program. The constant values must be defined before we can use them, so to be sure always put them at the start of the program. We will re-write the program without comments again, so that you can compare the previous listing to the new one:

STATUS equ 03h
TRISA equ 85h
PORTA equ 05h
bsf STATUS,5
movlw 00h
movwf TRISA
bcf STATUS,5
Start movlw 02h

movwf PORTA
movlw 00h
movwf PORTA
goto Start

Hopefully, you can see that the constants make following the program a little easier, even though we still have not put the comments in. However, we are not quite finished.

PIC Tutorial (PIC Tutorial 2)

The Registers



A register is a place inside the PIC that can be written to, read from or both. Think of a register as a piece of paper where you can look at and write information on.
The figure below shows the register file map inside the PIC16F84. Don’t worry if you haven’t come across anything like this before, it is only to show where the different bits and pieces are inside the PIC, and will help explain a few of the commands.



First thing you will notice is that it is split into two - Bank 0 and Bank 1. Bank 1 is used to control the actual operation of the PIC, for example to tell the PIC which bits of Port A are input and which are output. Bank 0 is used to manipulate the data. An example is as follows: Let us say we want to make one bit on Port A high. First we need to go to Bank 1 to set the particular bit, or pin, on Port A as an output. We then come back to Bank 0 and send a logic 1 (bit 1) to that pin.
The most common registers in Bank 1 we are going to use are STATUS, TRISA and TRISB. The first allows us to come back to Bank 0, TRISA allows us to select which pins on Port A are output and which are input, TRISB allows us to select which pins on Port B are output and which are input. The SELECT register in Bank 0 allows us to switch to Bank 1.
Let us take a closer look at these three registers.
STATUS
To change from Bank 0 to Bank 1 we tell the STATUS register. We do this by setting bit 5 of the STATUS register to 1. To switch back to Bank 0, we set bit 5 of the STATUS register to 0. The STATUS register is located at address 03h (the ‘h’ means the number is in Hexadecimal).
TRISA and TRISB.
These are located at addresses 85h and 86h respectively. To program a pin to be an output or an input, we simply send a 0 or a 1 to the relevant bit in the register. Now, this can either be done in binary, or hex. We personally use both, as the binary does help visualize the port. If you are not conversant with converting from binary to hex and vice versa, then use a scientific calculator.
So, on Port A we have 5 pins, and hence 5 bits. If We wanted to set one of the pins to input, We send a ‘1’ to the relevant bit. If We wanted to set one of the pins to an output, We set the relevant bit to ‘0’. The bits are arranges in exactly the same way as the pins, in other words bit 0 is RA0, bit 1 is RA1, bit 2 is RA2 and so on. Let’s take an example. If We wanted to set RA0, RA3 and RA4 as outputs, and RA1 and RA2 as inputs, We send this: 00110 (06h). Note that bit zero is on the right, as shown:
Port A Pin RA4 RA3 RA2 RA1 RA0
Bit Number 4 3 2 1 0
Binary 0 0 1 1 0
The same goes for TRISB.
PORTA and PORTB
To send one of our output pins high, we simply send a ‘1’ to the corresponding bit in our PORTA or PORTB register. The same format follows as for the TRISA and TRISB registers. To read if a pin is high or low on our port pins, we can perform a check to see if the particular corresponding bit is set to high (1) or set to low (0)
Before We give an example code, We need to explain just two more register – w and f.
W
The W register is a general register in which you can put any value that you wish. Once you have assigned a value to W, you can add it to another value, or move it. If you assign another value to W, its contents are overwritten.

An Example Code.
We are going to give you some example code on what we have just learnt. Don’t try and compile this yet, we will do that when we come to our first program. We are just trying to show how the above is actually programmed and introduce a couple of instructions along the way. We are going to set up Port A as per the example above.
First, we need to switch from Bank 0 to Bank 1. We do this by setting the STATUS register, which is at address 03h, bit 5 to 1.
BSF 03h,5
The BSF Means Bit Set F. The letter F means that we are going to use a memory location, or register. We are using two numbers after this instruction – 03h, which is the STATUS register address, and the number 5 which corresponds to the bit number. So, what we are saying is “Set bit 5 in address 03h to 1”.
We are now in Bank 1.
MOVLW b'00110'
We are putting the binary value 00110 (the letter b means the number is in binary) into our general purpose register W. We could of course have done this in hex, in which case our instruction would be:
MOVLW 06h
Either works. The MOVLW means ‘Move Literal Value Into W’, which in English means put the value that follows directly into the W register.
Now we need to put this value onto our TRISA register to set up the port:


MOVWF 85h


This instruction means “Move The Contents Of W Into The Register Address That Follows”, in this case the address points to TRISA.
Our TRISA register now has the value 00110, or shown graphically:


Port A Pin RA4 RA3 RA2 RA1 RA0
Binary 0 0 1 1 0
Input/Output O O I I O



Now we have set up our Port A pins, we need to come back to Bank 0 to manipulate any data.
BCF 03h,5
This instruction does the opposite of BSF. It means “Bit Clear F”. The two numbers that follow are the address of the register, in this case the STATUS register, and the bit number, in this case bit 5. So what we have done now is set bit 5 on our STATUS register to 0
We are now back in Bank 0.
Here is the code in a single block:


BSF 03h,5 ;Go to Bank 1

MOVLW 06h ;Put 00110 into W

MOVWF 85h ;Move 00110 onto TRISA

BCF 03h,5 ;Come back to Bank 0


Read this through a couple of times, until it is you can follow it. So far we have looked at 4 instructions. Only 31 to go!

PIC Tutorial (PIC Tutorial 1)

Good Programming Techniques
Before we get to the nitty gritty of programming the PIC, I think now is a good time to explain some good programming techniques.
If you type a ; (semicolon) anywhere in your program, the compiler will ignore anything after it until the carriage return. This means we can add comments in our program to remind us of what on earth we were doing in the first place. This is good practice, even for the simplest programs. You may well fully understand how your program works now, but in a few months time, you may be scratching your head. So, use comments wherever you can – there is no limit.
Secondly, you can assign names to constants via registers (more about these later). It makes it far easier to read in English what you are writing to, or what the value is, rather than trying to think of what all these numbers mean. So, use real names, such as COUNT. Notice that we have put the name in capitals. This makes it stand out, and also means that (by convention) it is a constant value.
Thirdly, put some kind of header on your programs by using the semi-colons. An example is below:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Author : ;
; Date : ;
; Version: ;
; Title: ;
; ;
; Description: ;
; ;
; ;
; ;
; ;
; ; ; ; ; ; ; ; ; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Notice that We have made a kind of box by using the semi-colons. This just makes it look neat.
Finally, try and document the program on paper as well. You can either use flow charts or algorithms or anything else you want. This will help you in writing your program, step by step.
Right, that’s the lecture over with, lets move on to the real stuff.

PIC Tutorial (Connect to the PIC Microcontroller)



Connect to the PIC Microcontroller







A Simple Development Board
Ok, so you have now got your programmer, and you have a PIC or two. It is all very well knowing how to program the PIC in theory, but the real learning comes when you try your code on a PIC and see the results yourself in a circuit.
You could build a circuit each time and program the PIC to see if the program works, or you can make yourself a development board. A development board allows you to simulate the environment around the PIC. We have included a circuit diagram to show a very basic and cheap development board. You can, of course add LEDs and switches to this, but We have included the bare bones. You can monitor the Input/Output pins by connecting LEDs directly to the pins, and they will light up when the pins go high. Also, you can add switches to the pins, so that you can select which inputs are high, and which are low. Basically, what We are saying is if you start with this circuit, you can add whatever you feel necessary.


We will run through the circuit diagram, which We admit isn't much, but it will give you a feel of things to come.
The supply rail is set to +6V, which is the maximum voltage of the PIC. You can use any voltage below this right down to +2V. C3 is known as a 'Bypass' Capacitor. All C3 does is reduce any noise on the supply rail. X1 is a 4MHz crystal. You could use a parallel resistor and capacitor circuit, but the cost of the crystal is negligible, and it is more stable. C1 and C2 help reduce any stray oscillations across the crystal, and get rid of any unwanted noise etc before the signal goes into the PIC.

PIC Tutorial (Introduction to PIC)

Introduction to PIC



Introduction
Welcome to the start of the PIC Tutorial. These pages will take you form the basic structure of the device, right through to programming methods and techniques. Also, there will be suggestions on how to modify the code so that you can adapt the PIC to suit your applications within Cybot. We will not be including any internal architecture diagrams, as this may only lead to confusion. If you want to look at the datasheet, then this can be downloaded from Microchips' web site.
To start, let us take a look at the PIC.

Microchip PIC 16F84 Microcontroller
Microchip manufacture a series of microcontrollers called PIC. You can see the range of their microcontrollers here. There are many different flavours available, some basic low memory types, going right up through to ones that have Analogue - To- Digital converters and even PWM built in. We are going to concentrate on the 16F84 PIC. Once you have learnt how to program one type of PIC, learning the rest is easy.
There are several ways of programming the PIC - using BASIC, C, or Assembly Language. We are going to show you the Assembly Language. Don't be put off by this. There are only 35 instructions to learn, and it is the cheapest way to program the PICs, as you do not need any extra software other than the freebies.

The 16F84 Pins
Below is a diagram showing the pin-outs of the PIC 16F84. We will go through each pin, explaining what each is used for.


RA0 To RA4RA is a bidirectional port. That is, it can be configured as an input or an output. The number following RA is the bit number (0 to 4). So, we have one 5-bit directional port where each bit can be configured as Input or Output.
RB0 To RB7RB is a second bidirectional port. It behaves in exactly the same way as RA, except there are 8 - bits involved.
VSS And VDDThese are the power supply pins. VDD is the positive supply, and VSS is the negative supply, or 0V. The maximum supply voltage that you can use is 6V, and the minimum is 2V
OSC1/CLK IN And OSC2/CLKOUTThese pins is where we connect an external clock, so that the microcontroller has some kind of timing.
MCLRThis pin is used to erase the memory locations inside the PIC (i.e. when we want to re-program it). In normal use it is connected to the positive supply rail.
INTThis is an input pin which can be monitored. If the pin goes high, we can cause the program to restart, stop or any other single function we desire. We won't be using this one much.
T0CK1This is another clock input, which operates an internal timer. It operates in isolation to the main clock. Again, we won't be using this one much either.

How To Program The PIC
OK, so you haven't been put off so far. Now, you want to know how to program the PIC, but apart from learning the assembly code instructions, how do you go about actually programming the information in? Well, there are two ways - the easy way, and the DIY way. The easy way is to buy a PIC programmer (around £35), which will connect to your PC and you can program your PIC using the software provided.

The DIY way is to build your own programmer (cheapest is just under £20) and use free software from the Internet and program it that way.
If you want to go for a DIY method, then We thoroughly recommend this site, and click on 'Supported Programmers' for circuits. The cheapest is TAIT Classic Programmer. Software for programming the PIC can also be downloaded from this site, under Download
If you want to go down an easier route, then check out this site. Here you can either buy a kit of parts or a ready made unit.
Another good site for some FREE software is here This software allows you to use any programmer, as the software is fully configurable.
Either method will do, as they both result in the same thing - program a PIC.
The next thing you will need is an assembler. This converts the program that you write into a format that the PIC understands. The best one around is from Microchip themselves, called MPLAB. It is windows based, and includes an editor, simulator, and assembler. This is the de-facto software, as it is written by the manufacturers of the PIC, and above all it is FREE!
We also recommend using Breadboard to make your circuits up, while you are playing with the PIC. There are various sizes available, which come with their own costs. Check out the Maplin Electronics links on the home page for more details of prices etc.
Next, we will look at how to connect up a simple circuit for PIC development.

Thursday, July 26, 2007

A digital thermometer

With the easy availability of inexpensive digital multimeters, and integrated circuit temperature sensors, it is now very easy to build a sensitive and accurate digital thermometer that can be used for many experiments around the house or in the amateur laboratory.

There are two tenperature sensors that make this particulary easy -- the LM34 and the LM35. These are callibrated in Fahrenheit and Celsius respectively, and when read by the meter, they produce ten millivolts per degree in their respective scales, so the meter can be directly read in temperatures, down to a tenth of a degree.


The digital thermometer needs these parts:
1-A multimeter. We chose a digital multimeter for accuracy and easy reading.

2-An LM34 integrated circuit temperature sensor for Fahrenheit.

3-An LM35 integrated circuit temperature sensor for Celsius.

4-A 180,000 ohm resistor This resistor will have four colored bands on it. The colors will be brown, gray, yellow, and gold.

5-A nine volt battery A nine volt battery clip Two alligator test leads Three long wires (optional) Electrical tape or heat shrinkable tubing (optional)



Shown above is a multimeter, set to read 0 to 2,000 millivolts (zero to two volts). Note that the dial switch is set to "2000 m".
It is currently reading 791 millivolts, which corresponds to 79.1 degrees Fahrenheit (since it is connected to the LM34 sensor).


Above, we have placed an LM35 sensor on top of an ice cube, and the pool of water melted from the ice is reading 8.9 degrees Celsius. For this experiment we have simply connected alligator clips to two of the leads of the sensor, and wrapped the third lead with the red wire from the battery clip. No soldering, nothing fancy, and we have a digital thermometer in the time it takes to unwrap the meter and clip on the test leads.







For a more permanent thermometer, we solder three long wires (about 5 feet is nice) to the three leads of an LM34 Fahrenheit sensor. Use three different colors, and note which ones are attached to which leads. We put a little electrical tape around the middle lead so it won't touch the other two, and then wrap the whole thing in electrical tape, or in this case, put it into a short length of heat shrinkable tubing, and warm it up so the tubing shrinks tightly around the whole assembly.
We made the wires long so that we can measure things inside boxes or behind doors. Five feet makes it easy to place the sensor end in the refrigerator or freezer, and have the meter stay outside where it is easy to measure. This arrangement is great for incubators for eggs, and terrariums, or (with proper waterproofing) aquariums.



At the other end of the long wires, we connect the battery clip and the resistor. Note that the wire colors help ensure that the right connections are made. In our case, the red wire from the battery clip is soldered to the brown and white striped wire, and the black wire from the battery clip is soldered to the brown wire. The brown wire is wrapped around one end of the resistor, and the blue wire is wrapped around the other end of the resistor. We can solder them later if we wish.



In the photo above you can see how the heat shrinkable tubing makes a nice neat temperature probe, with only the top of the sensor peeking out of the shrunken tube.
The alligator test leads are attached to the resistor, and the other ends are clipped onto the meter probes, as shown in the photo below.



How does it do that?



The circuit diagram is shown above. Briefly, there are two transistors in the center of the drawing. One has ten times the emitter area of the other. This means it has one tenth of the current density, since the same current is going through both transistors. This causes a voltage across the resistor R1 that is proportional to the absolute temperature, and is almost linear across the range we care about. The "almost" part is taken care of by a special circuit that straightens out the slightly curved graph of voltage versus temperature.


The amplifier at the top ensures that the voltage at the base of the left transistor (Q1) is proportional to absolute temperature (PTAT) by comparing the output of the two transistors.
The amplifer at the right converts absolute temperature (measured in Kelvin) into either Fahrenheit or Celsius, depending on the part (LM34 or LM35). The little circle with the "i" in it is a constant current source circuit.


The two resistors are calibrated in the factory to produce a highly accurate temperature sensor.
The integrated circuit has many transistors in it -- two in the middle, some in each amplifier, some in the constant current source, and some in the curvature compensation circuit. All of that is fit into the tiny package with three leads.


Reference: scitoys.com

MintyBoost - Small battery-powered USB charger


This project details a small and simple, but very powerful USB charger for your mp3 player, camera, cell phone, and just about any other gadget you can plug into a USB port to charge! The charger circuitry and 2 AA batteries fit into an Altoids gum tin, and will run your iPod for hours: 2.5x more than you'd get from a 9V USB charger! You can use rechargable batteries too.
Some numbers...
iPod video (tested, using alkaline batteries): 3hrs more video (1 full recharge) iPod mini (tested w/rechargeables): 25 hours more (1.5 full recharges)iPod shuffle (unverified): 60 hours more (5 full recharges) Weight (with 2xAA): 3.5oz
This project is suitable for beginners, some soldering tools are necessary but even if you've never soldered before it should be pretty easy. You can etch a circuitboard and/or breadboard this up, or simply buy the kit from the adafruit webshop.
I've also documented the process of designing this kit, in case other people interested in designing and making kits are interested in learning how to start selling their own kits!
Authored by Ladyada

4 Tips to Extend Your Lithium Battery Life


Lithium batteries seem to be everywhere these days. We can find them in our cellphones, laptops, portable media players and etc. We all want to make our batteries last as long as possible, but some well intentioned advice from friends, could be harming your Lithium battery’s life span. 1. Battery Memory - When I first got my new cellphone, my friend recommended to fully drain the battery before recharging it. His reasoning was connected to the idea of battery memory. Allowing the battery to fully discharge then recharging to max, supposedly gives you the complete battery capacity. Otherwise, if you simply charged from the half way point to max battery capacity, the battery would treat the half way point as the empty point, thus cutting your battery capacity in half.
Problem is battery memory doesn’t apply to Lithium batteries, this advice was meant for Nickel based batteries. Fully discharging your Lithium battery frequently can actually be quite harmful to your battery’s health, possibly rendering it completely unusable if energy levels go too low.
The good news is today’s lithium batteries have a safety circuit in place to insure the battery doesn’t reach the point of no return. The safety circuit isn’t fool proof of course, if you leave your battery completely drained for a few days, even the circuit’s protective measures won’t save it.
2. Battery Calibrating - There is some benefits to fully discharging your lithium battery periodically, for laptops especially this can be important. If you start to notice your battery meter is becoming more and more inaccurate, it may be time for some battery calibration. By allowing your lithium battery to fully drain, this will help the battery recalibrate allowing for more accurate measurements of battery life. This should be done once every 30 charges or when you notice battery readings are off.
Authored by Iron Cook

Tuesday, July 24, 2007

More than 15 Free New Magazines (اكثر من 15 مجله مجانيه جديده)

PC World Magazine June 2007 22.26 MB
http://hykm.free.fr/rk/607PCW.rar
-----------------------------------------------
Computer Power User June 2007 8.86 MB
http://hykm.free.fr/rk/CPU_0706.rar
-------------------------------------------
PC Magazine May 2007 10.95 MB
http://hykm.free.fr/rk/PC_Magazine_May_08_2007.pdf
--------------------------------------------
Games for Windows July 2007 22.37 MB
http://hykm.free.fr/rk/GFWJULY2007.rar
----------------------------------------------
Games for Windows June 2007 20.78 MB http://hykm.free.fr/rk/Games_for_Windows_June_2007.rar
-------------------------------------------------
Circuit Cellar Magazine May 2007 12.8 MB
http://hykm.free.fr/rk/202-0705.rar
------------------------------------------------
Creative Idea May/June 2007 9.18 MB
http://hykm.free.fr/rk/CIMayJune07.pdf
----------------------------------------------
Macworld 2007 April 15.72 MB
http://hykm.free.fr/rk/2007.CMWS.04.rar
----------------------------------------------
Advanced Photoshop Issue 29
http://hykm.free.fr/rk/adv.photoshop.issue.29.ebook.BBB.r00 http://hykm.free.fr/rk/adv.photoshop.issue.29.ebook.BBB.r01 http://hykm.free.fr/rk/adv.photoshop.issue.29.ebook.BBB.rar
-------------------------------------------------
POPULAR SCIENCE MAY 2007 32.91 MB
http://hykm.free.fr/rk/pscim.rar
-------------------------------------------
MSDN Magazine May 2007 4 MB
http://hykm.free.fr/rk/MSDN_Magazine_2007-05.chm
--------------------------------------------
Popular Mechanics Magazine 32.76 MB http://hykm.free.fr/rk/1183421891_Popular.Mechanics.Magazine.July.2007.PDF.eBook-OXFORD.rar
------------------------------------------------
Smartphone and Pocket PC Magazine 32.56
http://hykm.free.fr/rk/sph.rar
---------------------------------------------------
PC Magazine: January 2007 16.79 MB
http://hykm.free.fr/rk/PCMAG_Jan2007.rar
-------------------------------------------------
PC WORLD Magazine March 2007 14.67 MB http://hykm.free.fr/rk/PCworld_march2k7_wo_Ad.rar
-------------------------------------------------
Alan Simpson's Windows Vista Bible 27.72 MB http://hykm.free.fr/rk/Wiley.Alan.Simpsons.Windows.Vista.Bible.Jan.2007.rar
-----------------------------------------------
PC Magazine June 26 2007 18.57 MB
http://hykm.free.fr/rk/pcmag_26062007.rar
------------------------------------------------
PC Magazine 2006 November 21 16.22 MB
http://hykm.free.fr/rk/pc_magazine_-_nov-21-06.pdf
-----------------------------------------------
PC World August 2007 22.3 MB
http://hykm.free.fr/rk/pcworld_082007.rar
--------------------------------------------
Games for Windows - May 2007 13.37 MB http://hykm.free.fr/rk/Games_for_Windows_May_2007.pdf
---------------------------------------------
Games For Windows Feb 2007 25.04 MB
http://hykm.free.fr/rk/gfw_feb_2007.pdf
--------------------------------------------
Makhloof وكتبه الاخ Adsl gate هذا الموضوع منقول من منتدى
اتمنى ان تنتفعوا بهذه المجلات
مع تحياتى
I hope this magazine will be useful for you
With My Best Wishes
The Lover1