Laboration: AD-conversion and the Thevenin theorem.

advertisement
Laboration: AD-conversion and the
Thevenin theorem.
Embedded Electronics IE1206
Attention! To access the laboratory experiment you must have:



completed your personal knowledge control on the Web (Web-quiz).
done all preparation tasks mentioned in the lab booklet.
booked a lab time in the reservation system (Daisy).
During the lab you work in groups of two, but both students are responsible
individually for their preparation and implementation.
Booth students should bring their lab booklets. This frontpage is used as your
receipt that the lab is completed. Save the receipt until you have received the full
course registered in the database (Ladok).
1
Introduction
AD-converter
Our world is analog, and it is very common with analog sensors when "taking in"
readings to an embedded system. Many embedded processors are provided with an
AD converter.
Equivalent Circuits - (Thevenin)
For the electronics the Thévenin's theorem is essential. It says that for every,
complex linear circuit, one can find an equivalent simple circuit consisting of a
voltage source with an internal resistance.
In practice this means that we have the same simple model, an emf in series with a
resistor, for all analog sensors, we may have to use. Only the manufacturer needs to
know all the details of the sensor’s complete circuit diagram.
In this lab we exemplify Thévenin's theorem with a loaded voltage divider, and we
measure the current and voltage from it with the PIC processor inbuilt AD
converter.
We also link up an equivalent two-port circuit, and make the same measurements
on it. If the measured results from the two measurements are equal, then it seems as
Thévenin's theorem is "probable".
At the same time we get the opportunity to practice with the AD converter.
The goal of the lab






Orient you on how to configure an AD-converter.
Practicing how to measure voltage and current with an AD-converter.
Show how to measure bipolar voltages.
Practicing how to use internal or external reference voltage for the ADconverter.
Show how to design programs to present the measurements.
Learn how to calculate two-terminal equivalents.
Attention! Your lab time may be prior all course elements that may be needed for
the lab has been lectured. You would then have to read the course material for
yourself in advance - there are links to all slides for the lectures and exercises.
2
The PIC-processor internal AD-converter
Read in Microchip
PIC16F690-manual about how the AD converter is
configured. The rail splitter virtual ground chip
TLE2426
ADvolt.c

AD2pol.c
Preparation task 1 (done before the lab)
AD-converter as Volt-meter
The program ADvolt.c performs a measurement of voltage at AN2/RA2, pin
17, each time one presses the button.
For small one chip processors one avoids working with floating point numbers as
floating point operations take much space.
When measuring the supply voltage 5V the variable advalue get a 10-bit
integer with the full scale value 1023. If you multiply advalue with a constant
called SCALE_FACTOR so that the resulting figure will be 50000, the reading
will be more comprehensible to the user. (The result of the multiplication may be a
maximum of 65535 to fit in a 16 bit unsigned long). If you then additionally insert
a decimal point inside the printout as "5.0000" then we are done with a userfriendly presentation of the measured value.
• Which integer constant, SCALE_FACTOR in the program, should you multiply
the 10-bit AD value with, for the decimal digits to be correct (within 2%)?
Study the function
void longDecimal_out(long number, char decimalPlaces,
bit un_signed);
It divides the variable number into five ASCII digits, and then prints them with a
decimal point before the number of decimal places specified by the variable
decimalPlaces. With bit variable un_signed one specify whether it is a
positive number "+" or if it is a number with sign "+", "-" which is printed.
• How many of the five digits are to be decimals? Choose value of the constant
DECIMALS.
3
Bipolar measurement
On the breadboard there is a rail splitter virtual ground chip. If you measure the
voltage in relation to this chip output (2.5V), then the measured voltages can be
both positive or negative in relation to this (virtual ground). Now we can measure a
Bipolar signal.
ADC value must then be reduced by a constant OFFSET which shifts the 0 point.
The print function now should print the AD value with the sign. So we change to
#define UN_SIGNED 0
(false)
• What value should the constant OFFSET have when bipolar measurements?
You must study this program so that you are prepared to explain it at the lab.

Laboratory task 1
• Compile and download the program ( ADvolt.c ) with the constants from
preparation task 1 for unipolar measurements. Measure the voltage on the output of
the virtual ground chip, the printed number should be close to 2.5 V. Measure the
supply voltage (≈ + 5V) and the ground (≈ 0 V).
• Change the program ( ADvolt.c ) to the constants used for bipolar
measurements from your preparation task 1. Measure the voltage on the output of
the virtual ground chip, the printed number should now be close to 0 V. Measure
the supply voltage ( ≈ +2,5 V ) and ground ( ≈ -2,5 V ).
4
• Connect a cable to the virtual ground output, and measure the voltage of a 1.5V
battery between this cable and the AD-converter AN2. Change polarity of the
battery voltage - will the digits be the same ( but the sign different )? If not, adjust
the constant OFFSET in the program in order to correct this ( How should this be
done? ).

Preparation task 2 (done before the lab)
Measure with multiple AD-converter-channels
The program AD2pol.c will perform measurements with two AD-channels AN2
and AN3. The AD-converter channel selection must be reconfigured between the
measurements in the program. The channel is selected with the register ADCON0.
Read about the AD-converter in Microchip PIC 16F690 Data Sheet.
• Insert the correct values of the constants AN2_SELECT and AN3_SELECT, the
compiler Cc5x will allow us to use binary constants if introduced by 0b ( this is
not ANSII-standard - but it's convienient ).
• You must also insert values on the constants SCALE_FACTOR and
DECIMALS_I and DECIMALS_U.
You must study this program so that you are prepared to explain it at the lab.

Laboratory task 2
• Compile and test run your version of AD2pol.c with changed constants from
preparation task 2.
Measure with AN3 and AN2 connected to +5V, then 2,5V (virtual ground chip
output) and last 0V. The readings should be about (50mA, 5V), (25mA, 2.5V) and
(0mA, 0V) if you done it correct.
5
Calculations and measurements on a two terminal circuit
At the lab we are going to check the Thevenin theorem. A voltage divider with two
1 kΩ resistors and the supply voltage 5 V as its emf, is loaded by an adjustable
resistor with the range 1100Ω ... 100Ω.
This will be compared to the Thevenin equivalent circuit, with half the supply
voltage (from the rail splitter circuit) and with the half resistance value in series,
(from the two resistor in parallell).

Preparation task 3 (done before the lab)
• Calculate voltage U and current I from the two-port with the voltage divider
when it is connected to a load resistor RL. RL have the values 100Ω, 500Ω, 1000Ω.
Pinpoint the three points in the IU chart. Are they located on the same line?
Be prepared to present your calculations facing the other participants at the lab.
• Calculate voltage U and current I from the two-terminal equivalent when its
connected with a load resistor RL. RL has the values 100Ω, 500Ω, 1000Ω. Pinpoint
the three points in the IU chart. Are they located on the same line??
Be prepared to present your calculations facing the other participants at the lab.
6
IU-chart
• Study the points in the charts. They are the same. Give the equation for the
straight line, I = f (U ) with units mA and V.
External reference - better measurement accuracy
The calculations above should state that the output voltage from the voltage
divider, or its Thevenin equivalent, will never exceed 2.5V. The AD converter then
uses an unnecessarily large measuring range 0 ... 5V.
If we connect the rail split circuit as a 2.5V external reference to the AD converter
we will double the measurement accuracy! This becomes especially important for
the current measurement that will always have the lowest measured value.
• To use external reference at pin RA1/AN1/Vref one must reconfigure ADCON0
in program AD2pol.c Find out how, and write down, the values of the constants
AN2_SELECT and AN3_SELECT to obtain this.
7
• As the measuring range is divided by two also the scale must change. Do this at
lab by uncommenting these lines at two places in the program:
//advalue /= 2; /* uncomment when using 2,5V reference */
• Read tutorial Save measurements on file, about how to save the measured values
in a text file, so you are prepared to do this at lab.
You must study this program so that you are prepared to explain it at the lab.

Laboratory task 3
The voltage divider, and then the equivalent two port, are loaded by a variable
resistor. The voltage U at output A is directly measured with AN2, while the
current I is indirectly measurered as the voltage drop over a 100 Ω measurement
resistor with AN3. The external reference voltage from the output of the rail split
circuit is to be connected to AN1/RA1/REF/PGC - NOTE! This same pin is also
used when programming the chip!!
It is not possible to use both the function external reference and chipprogramminig simultaneously!!
• Check at lab if your version of Excel uses decimal point or decimal comma? If it's
decimal point you have to change your program AD2pol.c to also use point
when printing the values.
8
• Build up the voltage divider circuit on the breadboard, connect the variable
resistor and the measurement cables to AN2 and AN3. NOTE! The measurement
cable to AN1/REF/PGC from the external reference (the rail split circuit) must not
be plugged in during chip programming!
• Insert changes from preparation task 3 to program AD2pol.c so that it uses the
external 2,5V reference. Compile and download the code to the chip. NOTE! You
can not have the external reference connected while downloading the code.
• When the chip programming is done, you carefully pull out the pin with the red
PGC-cable from the breadboard (and the PIC), and connects the cable from the
external reference instead. Should You need to reprogram the chipthen the cables
must change places again. Both must not be connected simultaneously.
• Do the measurements. Save the values to a textfile. See "Save measurements on
file". Press the button to get a value pairs, and change the variable resistor between
measurements.
(You can quickly redo the measurements, if you “missed” something).
• Upload the text file to an Excel-document. Is the curve in the excel figure
consistent with the curve in your preparation task 3? Will it be the same equation I
= f (U ) ? Show lab assistant!
( in addition to excel - online tools on the web can be used eg: Online scatter plot )
9
• Reconnect the circuit to the thevenin equivalent circuit. The half voltage one gets
from the rail split chip, and a resistor with the half resistance one gets by
connecting the two resistors in parallell.
• Again save the measurements in a (another) textfile and upload it to Excel. Is the
curve in the excel figure consistent with the curve in your preparation task 3? Will
it be the same equation I = f (U ) ? Show lab assistant!
Do you have time to spare?
If you are well prepared for the lab, then you probably now have time for a "voluntary" task.
• The two terminal circuit you have made calculations and measurements on can also be
simulated with LT-spice.
Simulate with LT-Spice
• Ready drawn schematic IU.asc. Simulate the circuit. You can then easily change it to a
diagram of the two pole equivalent to investigate whether both simulations give the same
result.
Do you have time to spare?
If you are well prepared for the lab, then you probably now have time for a "voluntary" task.
Ask the lab-assistant for a caliper with a linear motion potentiometer glued to it. The task is
now to use this potentiometer instead of the rotary potentiometer and measure the voltage
from it. Use the program ADvolt.c and find a propriate scale factor so the reading will
match the caliper millimeter scale. ADvolt.c
10
Now measure the diameter of a Table Tennis Ball - does the size conform with the
international rules?
The_Ball international rules.
Good luck!
When you are finished. Restore the equipment as it was at the start of the lab. Be careful
when you put back the pin for the red PGC cable so as not to damage it. Clean the lab
location.
Bill of materials
The "bill of material" for the lab equipment, could be helpful if you ever would
need to use some of these components again.
breadboard GL-12F ELFA 48-427-04
Microcontroller 8 Bit DIL-20, PIC16F690-I/P ELFA 73-793-58
Virtual groundreference TO-92, TLE2426CLP ELFA 73-242-62
Trimpot cermet 1 kO Lin 500 mW, 72PTR1KLF ELFA 64-634-42
Resistor 2st 10k.
Resistors 2 st 1k, 1 st 100 ohm.
1 st Led with internal resistor 5V red ELFA 75-012-59
Button 24 VDC 50 mA, 3CTL9 ELFA 35-680-78
Jumpers: 8 orange, 4 yellow, 5 green, 1 red.
11
Download