This experiment shows 0-256 parts of a 10k potentiometer on the 8 LEDs. It is not accurate, but shows the concept of A to D conversion. Many microcontrollers have an input that can read any value of voltage from 0v to 5v (and higher by using a voltage divider network). Normally there are 256 steps in this range to produce a resolution of approx 20mV for 0-5v scale. This is called an A to D input (A to D converter - analogue input) and is ideal for measuring voltages and other values that are classified as ANALOGUE. A very simple external circuit can be added to measure different parameters such as the change in resistance of a temperature probe and other analogue devices. The PIC16F84 does not have an internal A to D converter, however we can create an A to D feature by using two lines and a sub-routine. To create an analogue input, a capacitor "C" is connected in series with an unknown resistor (R) and charged via one of the lines of the microcontroller. The diagram below shows how this is done.
The first diagram shows a resistor and capacitor connected in series. This is called a TIME DELAY circuit. The capacitor is initially uncharged and the resistor charges the capacitor to a specified value. The time taken to reach this value is called the Time Delay. The mid-point of the two components is called the "detection point." It does not matter if the resistor is above the capacitor or below. The same Delay Time (or a similar time) will be produced.
In the second diagram the capacitor is above the resistor and if the top line is taken HIGH, the voltage at the detection point will fall to a specified value after a Delay Time. If the value of the resistor is changed, the time taken for the voltage at the detection point to reach a specified value will alter. That's exactly what happens in the third circuit above. The micro monitors the voltage on the detection point and when it reaches the lower threshold for the input line, the program displays the "count-value" on the 8 LEDs.
The other feature that has to be worked out is the time taken for the capacitor to charge. In our circuit, the capacitor has charged before 255 loops have been executed (when the pot is at maximum resistance) and we cannot same at a faster rate, so the maximum display-value is "DF." To obtain a full reading, the capacitor will need to be increased in value.
In the second diagram the capacitor is above the resistor and if the top line is taken HIGH, the voltage at the detection point will fall to a specified value after a Delay Time. If the value of the resistor is changed, the time taken for the voltage at the detection point to reach a specified value will alter. That's exactly what happens in the third circuit above. The micro monitors the voltage on the detection point and when it reaches the lower threshold for the input line, the program displays the "count-value" on the 8 LEDs.
The other feature that has to be worked out is the time taken for the capacitor to charge. In our circuit, the capacitor has charged before 255 loops have been executed (when the pot is at maximum resistance) and we cannot same at a faster rate, so the maximum display-value is "DF." To obtain a full reading, the capacitor will need to be increased in value.
Thank for the code! its really helpful. i am going to download it
ReplyDelete