Find the Light 
Using 
Digital and Analog Signals

 

Here are images from the implementation by Miguel Bautista. Jeremy Lyons and Hashim Ahamed Ayyaril. The following schematic shows the connection of the TLC0834 Analog to Digital Converter and the servo motor to the parallel port. The parallel port pins are numbered 1 to 13, from left to right.

 

Implantation of the above schematic.
Sensors mounted on servo motor.

 

In this lab you will use an analog light sensor and a digitally controlled motor to find the direction of a light. The position of motor is controlled digitally from the parallel port while an analog light sensor mounted on the motor will be used to detect the light. By sweeping the motor back and forth and continuously reading from the sensor the light can be found. 

The servo motor is controlled with a digital signal because it has better immunity to noise. This is instep with the trend in the last twenty years to encode more and more data with digital rather than using analog signals. Vis-à-vis the demise of analog vinyl records with the ascendancy of digitally encoded music of CD's. Digital encoding is less susceptible to noise and gives more precise reproductions. 

Servo motors

Servo motors are motors that use feedback control to precisely control the position or speed of the motor. The servo motors we are using are made for hobbyist and are used in model cars, planes and boats. They are small, light weight and inexpensive.

  Our servo motors are model TS-53 S3K Standard Servo and come from Tower Hobbies. Their specifications are 
Torque 42 oz/in
Speed 0.22 sec/60°
Weight 1.5 oz
Length 1.59"
Width 0.77"
Height 1.41"

The TS-53 S3Kcan turn in a range of +/- 90°. The angle of rotation is controlled by a pulse that is sent to the motor every 20 milliseconds. By varying the width of the pulse the angle can be precisely controlled. This technique is called Pulse Width Modulated (PWM). The TS-53 S3K moves to its center position with a pulse width of about 1.5 milliseconds.

Inside the  TS-53 S3K is a small DC motor, gears, a rotation sensor and control electronics.

Links

Photo Sensors

The CdS photocell is an electronic circuit whose resistance falls when illuminated by bright light. When the photocell is completely darkened it's resistance is several mega ohms, whereas when it is illuminated by a standard flash light its resistance is only several kilo ohms. This change in resistance can be detected by using the photocell as one resistor in a voltage divider between ground and 5 Volts. The voltage from the center of the divider  changes as the resistance of the photo cell varies. See the page on voltage dividers and CdS photocells in W. D. Philips' online book on  Design Electronics  for more details.

Other Projects

Week 1 - Timer Interrupt and Analog To Digital Converter

1. Connect the Servo motor to the parallel port and control the servo motor using a "C" program and brute force busy waits. By trial and error move the motor smoothly from one side to the other.

2. Interface to the TLC0834 8-bit 20KSPS 4-channel, 5 Volt, serial Analog to Digital Converter to the parallel port. The TLC0834C has a serial interface. First you must clock in configuration data (input channel) and then you must clock out the 8-bit word. The clock pulse must not be longer than 0.1 milliseconds and must be high for the same amount of time that it is low. 

WARNING: we had a hard time getting this chip to work on all our computers.
 (It ran on 486 computers but not the Pentiums.)

 

Pins Name Connect to  Function
1 NC   Not Connected
2 CS Output from parallel port Active low Chip Select. Must go from high to low before data is shifted in on DI.
3 CH0 Sensor 1 Channel 0 analog input
4 CH1 Sensor 2 if used Channel 1 analog input
5 CH2 Sensor 3 if used Channel 2 analog input
6 CH3   Channel 3 analog input
7 DGTL GND Ground Digital Ground
8 ANLG GND Ground Analog Ground - kept separate from digital ground in more precise systems.
9 REF 5 Volts DC Reference
10 D0 Input into parallel port Data Out - voltage level at analog input is shifted out as an 8-bit word 
11 SARS ? Indicates that a conversion is in progress. 
12 CLK Output from parallel port Clock must be between 10 and 600 kHz and should have between a 40% and 60% percent duty cycle when data is being read (the time the clock is high should roughly be the same as it is low)
13 DI Output from parallel port Data In - used to select input channel
14 Vcc 5 Volts DC Power

Taken from the Data Sheet:

A conversion is initiated by setting CS low, which enables all logic circuits. CS must be held low for the complete conversion process. A clock input is then received from the processor. On each low-to-high transition of the clock input, the data on DI is clocked into the multiplexer-address shift register. The first logic high on the input is the start bit. A 3- to 4-bit assignment word follows the start bit. On each successive low-to-high transition of the clock input, the start bit and assignment word are shifted through the shift register. When the start bit is shifted into the start location of the multiplexer register, the input channel is selected and conversion starts. The SAR status output (SARS) goes high to indicate that a conversion is in progress, and DI to the multiplexer shift register is disabled for the duration of the conversion.

An interval of one clock period is automatically inserted to allow the selected multiplexed channel to settle. DO comes out of the high-impedance state and provides a leading low for one clock period of multiplexer settling time. The SAR comparator compares successive outputs from the resistive ladder with the incoming analog signal. The comparator output indicates whether the analog input is greater than or less than the resistive-ladder output. As the conversion proceeds, conversion data is simultaneously output from DO, with the most significant bit (MSB) first. After eight clock periods, the conversion is complete and SARS goes low.

The following bit pattern should be used to control the TLC0384

Order Value Name Function
1 1 Start Bit Starts conversion
2 1 SGL/DIF  selects between single ended and differential input
3 depends on channel ODD/EVEN bit 0 of channel address
4 depends on channel SELECT BIT 1 bit 1 of channel address

 

Channel Number SELECT 
BIT 1
ODD/EVEN
0 0 0
1 0 1
2 1 0
3 1 1

 

3. Chain an interrupt handler to DOS's 55 millisecond interrupt and interface it to another Terminal and Stay Resident (TSR) interrupt at INT 0A0h. 

old_INT_1C	label dword	; might require different syntax in NASM
old_offset  	dw ?
old_segment 	dw ?

       	; Get interrupt vector
	; Output:
        ; 	ES = Interrupt Handler Segment
        ;	BX = Interrupt Handler Offset
	;	ES:BX
	;------------------------------------
	mov 	AH, 35h    		; get interrupt vector info
        mov 	AL, 01Ch   		; AL = the interrupt number
        int 	21h        		; do it.
	% install your interrupt handler
	%-------------------------------
 	lea 	dx, TSR_PROC		; point to new ISR procedure
	mov 	ax, segment TSR_PROC
	mov 	ds, ax			; segment of ISR
	mov 	ah, 25h			; function to install an interrupt
	mov 	al, 1Ch			; interrupt to install
	int 	21h			; set interrupt vector
 
	; main loop or call 
TSR_PROC:
	pusha                    	; Save all the registers
	push	ds
	; set the data segment (DS) to be the same as
	; the code segment (CS) so the ISR can access the local
	; variables
	;---------------------------------------------- 
	mov	ax, cs
	mov	ds, as
        cli                      	; disable interrupts
  
	; in your ISR
	; call old interrupt handler
	;------------------------------------
	pushf
	cli
	call old_INT_1C
       	sti                      	; enable the interrupts
        pop	ds
	popa                     	; restore registers
	iret

          

An interface which shall be done through INT A0h.  Add the interrupt as above.
Terminate and stay resident by

	; calculate size of program in 16 byte paragraphs
	;------------------------------------------------
	mov	DX, (END_LABEL - START_LABEL)/16
	; Set ExitCode;  can just be zero
	%---------------------------------
	mov 	AL, ExitCode 	 
	mov	AH, 31h  		
	int 	21h 		; terminate and stay resident		 

Calculate the size by declaring a label at the beginning and the end of your code. Take the difference between the two labels and then divide by 16. Place result in DX before calling INT 21h. 

Both interrupt handles shall be assemble into one program so they can share data. Each interrupt handler shall be in a separate file. Extra credit for not doing it with an include and have one main file and then two more files for the interrupt handler.

INT 0A0h

function: INT A0h, AL = 0

  • input: AL - 0 disable control of servo motors 

  • function: disable the PWM  used to control the servo motors

function: INT A0h, AL = 1

  • input: AL - 1 get count 

  • output: DX:AX - 32 bit count

  • function: returns the number of times the interrupt has run

function: INT A0h, AL = 0FFh

  • function: Remove TSR program, and unchain the ISR.

Links 

Programmable Interval Timer

Week 2 Finding a bright light

1. Add blinders to the photo diode(s) so that they can only see out a small angle.

2. Convert the timer routine to use Channel 2 of the 8254. No longer use brute forces to control the servo motor, but uses pulses controlled by the time interrupt

INT 0A0h

function: INT A0h, AL = 0

  • input: AL - 0 disable control of servo motors 

  • function: disable the PWM  used to control the servo motors

function: INT A0h, AL = 1

  • input: BX -  pulse width count

  • input: CX - time between pulse count 

  • function: set the pulse width sent to the parallel port. Will start sending pulses if PWM is disabled.

function: INT A0h, AL = 2

  • output: AL - data from ADC 

  • function: read from the ADC. 

function: INT A0h, AL = 0FFh

  • function: Remove TSR program, and unchain the ISR.

Links 

Interrupt Chaining and Terminal and Stay Resident (TSR)

 

Week 3 - Integration and Final Presentation

  1. No busy waits, instead either use interrupt service routines or periodic polling.

  2. A C-program will provide the interface to the assemble code. Enable the following commands:

  3. By controlling the servo motor find the light:

  4. Track the light

  5. Give an audio indication of light intensity. Choose from the following:

 


Final group presentations are due by 8:00 PM on May 15th. 

Include 

Projects are grade on

Metric

Points

effectiveness of presentation: including explanation of code and circuit and making small changes to code. 50 
originality, correctness and efficiency 50 
clarity, which includes good, accurate variable names and functions, and simple program structure with  loops less than 25 lines long and functions less than a page long. 30
clear concise  comments with a header on each file and function 30
Effective team work 20
  180