The process of a/d is one where an analog signal is converted to a digital value. This is similar to a digital thermometer or digital speedometer. There are ICs that are made specifically to be an a/d but inside the 6811/12 there is an analog to digital converter. It uses successive approximation to determine the digital equivalent of the analog signal.
In addition to sending the analog signal to the 6811/12 it also needs to know the highest and lowest possible analog voltage called Vrh and Vrl respectively. You will need to set Vrh and Vrl on the 6812 board. Vrh cannot be more than 5v and Vrl cannot be less than 0v. So to make things easy we will choose Vrh=5 volts and Vrl=0 volts.
Specifics for the 6811
Connect the analog signal to pe0 of the 6811. To turn on the a/d clear bits 0,1,2,3 of atctl, while setting bits 4,5. For more information on pe1.. pe7 and adctl see the technical reference manual. One can easily test the a/d by using memory modify, mm.
adctl equ $1030 ;controls a/d converter, 00110000 adr1 equ $1031 ;results of a/d located here
Specifics for the 6812
The analog signal can be sent to one of the pins labeled: pad0 to pad7. The digital equivalent of this analog signal will be placed in registers: adr0h to adr7h respectively. For example if you connect the analog signal to pad0 the digital equivalent will be in adr0h which has the address of $70 (see program below). And if this analog signal comes in at a maximum of 5v then the digital value will also be a maximum of ff (hex). If 0 volts comes in then the output will be 0, and 2.5 volts will produce 7f (hex), etc.
Again you will need to connect the analog signal(s) to pad0 through pad7. Pad0 through pad7 is found on the headers of the 6812. Pad0 through pad7 in turn goes to registers adr0 to adr7 respectively.
Just when you thought this was going to be simple here is a few extra steps you must take. First turn on the a/d by setting bit 7 (adpu) of register atdctl2. Next connect the analog signal to pad0, pad1, ... or pad7. If you want to convert all signals (pad0 to pad7) just once then reset bit 5 (scan) of register atdctl5. If scan is set then the converter runs non stop. When a conversion is done the 6812 will set bit 7 (scf) of register atdstat (at memory location $66) to let you know it is finished. If you are reading just one value from the a/d you must wait for the a/d to finish otherwise you will get incorrect values. See program below.
Here is how to set the bits of atdctl5:
To read all 8 analog signals once: movb #%01010000,atdctl5
To read all 8 analog signals nonstop: movb #%01110000,atdctl5
For additional information refer to the Technical Summary for the 6812.
*******************************************************
*6812 Program to set up a/d and read forever.
*Assume analog signal is connected to pad0.
org $0800
movb #%10000000,$62 ;turn on a/d
movb #%01110000,$65 ;tell a/d to continuously read
top ldaa $70 ;read a/d into acca
jmp top
*******************************************************
*******************************************************
*io_ad.asm for 6812
*Program to set up a/d and read once.
*Assume analog signal is connected to pad0.
atdctl2 equ $62 ; a/d control
atdctl5 equ $65 ; a/d control
atdstat equ $66 ; a/d status
adr0h equ $70 ; pad0
org $0800
movb #%10000000,atdctl2 ;turn on a/d
movb #%01010000,atdctl5 ;tell a/d to read once
more ldaa atdstat ;loop until a/d finished
anda #%10000000
beq more
ldaa adr0h ;read a/d into acca
*******************************************************

The purpose of this lab is to design and build a computer controlled temperature system for a greenhouse. In addition to the 6811/12 we will use a LM35 temperature sensor, 120v light bulb heater, and a 12v fan. Obviously when the temperature gets too high the fan comes on and when too low the heater comes on. What is less obvious is the use of hysteresis as shown in the following temperature chart.
Record the 6811/12 number here ______________
Record the greenhouse number here ___________
The temperature sensor. Connect the LM35 to the 6811/12 as shown in the circuit diagram. Pick R2 and R1 to give a gain of about 10 or 11. Instead of the op amp going to pe0, connect it to a voltmeter and make note of the voltage. It must be within the range of [Vrh, Vrl]. If so then connect the op amp output to pe0. Next write the code that will read pe0 and display the value to your computer screen. Write down the pe0 value for when the green house has the following temperatures:
94 F, 34 C _______ 90 F, 32 C _______ 86 F, 30 C _______ 82 F, 28 C _______
The 6811 can use port a, pa, or port c, pc, for output. The 6812 can use pa or port b, pb.
*6811 pa equ $1000 ; ioooiiii pb equ $1004 ; always output pc equ $1003 ; defaults to input via ddrc ddrc equ $1007 ; defaults to 00 *6812 pa equ 0 ;set according to ddra pb equ 1 ddra equ 2 ;00 means input, ff means output ddrb equ 3

The heater. Connect the circuit for the heater using an output port like pb1. Test the port by simply using memory modify (mm) in the communications window of the PC. Make the port output, then send a 1 to pb1 and the light should turn on. A 0 to pb1 will turn it off.
The fan. Connect the circuit for the fan using an output port like pb0. Remove the wire going to pb0 and connect the base of the NPN to 5v. The fan should run. Remove the 5v and the fan should stop. If that works reconnect the base of the NPN to pb0. Test the port by simply using memory modify (mm) in the communications window of the PC. Make the port output, then send a 1 to pb0 and the light should turn on. A 0 to pb0 will turn it off.
Bring it all together. With the hardware connected and tested write the software to keep the temperature around 88 F. Your code will look something like:
initialize ports and a/d read a/d into acca display value of acca on PC screen if acca > 94 then turn on fan if acca < 90 then turn off fan if acca > 86 then turn off heater if acca < 82 then turn on heater repeat (from 2nd line)
Your program must use equates, be efficient and well written. Show all circuits in your report.