54
A Ballistic Chronograph Brandon Atkinson Steven Turner May 4, 2001 University of Maine ECE 403 Final Report

A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

A Ballistic Chronograph

Brandon Atkinson

Steven Turner

May 4, 2001

University of Maine

ECE 403 Final Report

Page 2: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Abstract

The goal of the “Ballistic Chronograph” project was to create a device having the ability

to measure the speed of a paintball (or any similarly shaped projectile) and display this

information to a display for a human to read.

The design approach consisted of research, including Internet browsing, reading and

consultation with advisors. The first decision made in the design was selecting the proper

microprocessor. This decision was based on the minimum number of clock cycles

needed for the project’s accuracy specification, coupled with the need for a certain

number of input and output pins, along with the desire for a relatively simple and

inexpensive design.

The second stage of design was brainstorming a measurement system. The problems in

this stage were numerous. How do you detect the presence of a paintball without

impeding its motion? What type of sensor will work most consistently without failure?

These are just a few of the questions that were asked.

The third stage of design involved choosing and assembling the display and physical

prototype, followed by testing and verification. This stage went rather well, bringing

only a couple of problems to light. The testing consisted of velocity measurement

verification with an oscilloscope and real paintball projectiles. It is interesting to note

that the accuracy of this project’s velocity readings is comparable to the accuracy of some

commercial products, although the speeds paintballs travel at are considerably less than

the speeds of bullets.

2

Page 3: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Table of Contents

Abstract ...............................................................................................page 2

Table of Contents................................................................................page 3

List of Figures .....................................................................................page 4

Introduction.........................................................................................page 5

Breakdown ..........................................................................................page 7

Details .................................................................................................page 8

Results and Conclusions ...................................................................page 20

Directions For Use ............................................................................page 22

Appendix...........................................................................................page 23

3

Page 4: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

List of Figures Schematics

Schematic 1 – Infrared Emitter Schematic .......................................page 24

Schematic 2 – Infrared Detector Schematic......................................page 25

Schematic 3 – Power Supply Schematic...........................................page 26

Schematic 4 – Wired OR Schematic.................................................page 27

Schematic 5 – Full Circuit Schematic...............................................page 28

Flowcharts

Flowchart 1 - Project Overview..........................................................page 7

Flowchart 2 – Main Code .................................................................page 29

Flowchart 3 – LCD_INIT Routine....................................................page 30

Flowchart 4 – CALC_RES Routine..................................................page 31

Flowchart 5 – RES_OUT Routine ....................................................page 32

Flowchart 6 – Sq_Res Routine .........................................................page 33

Flowchart 7 – Acc Routine ...............................................................page 34

Flowchart 8 – ACC_OUT Routine ...................................................page 35

Flowchart 9 – Interrupt Service Routine...........................................page 36

Tables

Table 1 – Approximate Current Total...............................................page 54

4

Page 5: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Introduction

The ballistic chronograph measures and displays the velocity of a projectile passing

through it. The device interprets triggers of the internal sensors caused by the passing

projectile as time-stamped events. After all the sensors are triggered the processor does

some math with the time-stamps and displays the velocity measurement.

Chronographs are used to ‘calibrate’ firearms to a certain range of muzzle velocities (at

least with paintball guns). Paintball is usually played with muzzle velocities in the high

100’s to low 200’s feet-per-second (fps). Paintball is played with people shooting plastic

balls filled with paint at each other, so it is important that the weapons are shooting

paintballs fast enough to break the paintballs, but slow enough that people playing don’t

get hurt.

Under normal circumstances, a chronograph used for paintball would be useful before

any match was played. All guns that were to be used in a game would be tested, one by

one. A set speed would be decided for the game, and each gun would be adjusted until

the muzzle speed was the same as the target speed decided upon beforehand. In this type

of application, portability is not a big concern, because the adjusting happens before a

match, and can take place away from the game (usually played outdoors).

Accuracy is a big concern, however. Most chronographs operate on ambient light and the

‘shadow’ of the projectile. This dependence on ambient conditions creates a source of

error for measurements. The chronograph built for this project is not dependent on

ambient light conditions, so measurements are more repeatable.

There are several chronographs on the commercial market. Most of the chronographs for

sale seem to be marketed as rifle calibrating devices, so the velocity range specifications

are higher than for this project, but it is interesting to note some of them.

5

Page 6: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

One chronograph, from Oehler Research, uses ambient light sensors (uses light from the

sun or room to detect the projectile) that can be adjusted to different positions to attain

better accuracy. The adjustment range is from one foot between sensors to four feet

between sensors. The accuracy of this commercial grade chronograph at 1 ft. between

sensors (the same spacing as this project’s sensors) is published as within 5 feet/second

(fps) at 1000 fps. The accuracy recorded by this project is somewhere around 3 fps at

500 fps. So it seems that the chronograph built in this project is reasonably accurate.

The specifications for this project are as follows:

Operation range (actual velocity of projectile passing) ................ 100-500 fps

Accuracy ..................................................................................... within 10 fps

6

Page 7: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Breakdown Most simply the ballistic chronograph consists of inputs, a processor, and a display (see

Flowchart 1, below). The inputs are implemented with IR sensors detecting a passing

projectile and connected to a PIC microprocessor. When the IR sensors are triggered, the

PIC services an interrupt and determines which sensors have been triggered. The PIC

uses a timing interrupt to determine the amount of time in between sensor trips. When all

of the sensors have been triggered, the PIC has enough information (the time between

sensors and the known distance between sensors) to determine the velocity of the

projectile passing through the system. With the speed of the projectile determined, the

PIC can now pass the velocity to an LCD display module so that it can be viewed. The

sends the appropriate commands through one of its ports to the LCD module. The

module captures these commands and displays the appropriate text on the LCD display.

IR Sensors &Emitters

PICMicroprocessor LCD DisplayProjectile Speed of

Projectile

Flowchart 1 – Project Overview

7

Page 8: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Details

Hardware

Sensors

The sensor system consists of 3 sets of sensors. Each of the 3 sets of sensors consists of

an emitter circuit and a receiver circuit.

The Emitter

The emitter circuit consists of two diodes and two biasing resistors, R1 and R2 (see

Schematic 1, page 24). The diodes are infrared emitter diodes (Lite-on manufactured

Digikey PN# 160-1031-ND), meaning that instead of lighting up the way a visible LED

does under bias, the diodes emit infrared radiation at a certain frequency. There is a

direct correlation between the bias current magnitude and the amount of radiation thrown

from the emitters. For this project’s purposes, a strong IR beam is desired, therefore

small 100-ohm resistors are used to maximize the current flow through the diodes. The

schematic shows that there are two parallel diodes used in each emitter. One of the

reasons for this is to maximize IR intensity as well. The other reason for having two

parallel diodes in the emitters is to ensure direct alignment with the series

phototransistors in the detector circuit.

8

Page 9: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

The Detector

The real work in designing the sensor system was in designing a reliable detector portion.

Originally, the design consisted of one IR-phototransistor, and a single resistor (see

Schematic 2, page 25). This circuit worked under test conditions in lab. When an object

passed through the IR beam from the emitter, the voltage Vout dropped from its default

state (near 5 volts) to its ‘triggered’ state (near zero volts). A square wave was then used

to power the IR-LED to simulate repeated switching. This revealed that slewing occurs

as the IR light is taken away from the base of the IR-phototransistor. This slewing was a

major concern in the beginning stages of design. The delay in changing states that this

slewing represents means there will be some finite speed the circuit is able to detect.

From the experiment using the 5v square wave powering the emitter, the maximum slew

rate was found to be 0.0617 V/microsecond. From this information it was possible to

make an estimate as to what maximum speed could be detected.

Assuming the paintball to be a 0.5 inch diameter sphere, approximating the emitter beam

as a plane, and knowing the resolution of the microprocessor (1/1e6 seconds) we found

that the minimum time needed to switch states was 81.04 microseconds, and the

maximum detectible velocity measurement at this time is 514 fps (feet per second).

It is evident that the maximum velocity the sensor is able to measure is very close to the

top end specification of 500 fps set for the project. In reality, the maximum measured

velocity is probably much more than 514 fps simply because the microprocessor is edge

triggered, rather than level sensitive, so full voltage deflection is not necessary, and the

slew measurement taken in lab includes the slew of the IR-LED switching as well.

9

Page 10: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Adding the Second IR-Phototransistor

Since the single transistor sensor seemed to work, why would adding the second

transistor be necessary? The reason for adding the second phototransistor is more of a

physical one than electrical. The tube the paintball is shot through is a 2” diameter tube,

and the paintball is about 0.5” in diameter. If the emitter and receiver are placed on the

centerline of either side of the tube, there is a good chance that the IR beam will not be

broken. Shifting the emitter and detector down, away from the center line of the tube,

while adding another set of sensors above the center line of the tube near the first set

increases the chance that the passing projectile will be detected. The two transistors are

wired in series so that if one of the phototransistors turns off, the output will go to the

‘triggered’ state near 0 volts.

10

Page 11: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

The Wired-OR

While designing the sensor system, it was important that the outputs of the system were

compatible with the PIC microprocessor we were using. Some potential designs included

ideas using the interrupt-on-change feature of the pins on PORTB, and another used the

RB0 pin on PORTB to trigger the interrupt, while the sensors were connected to pins on

PORTB and their states were checked in the interrupt service routine. The first instinct

could be to use the design that took up the least number of input pins.

However, on the PIC16F84 microprocessor, the RB0/INT pin has a Schmitt Trigger input

stage, giving us the ability to use positive feedback to speed up the transition between

low and high states. The built-in Schmitt Trigger also has a small amount of hysteresis,

meaning that there is no absolute switching threshold, rather there are different switching

thresholds depending on whether the voltage is making a low-to-high or high-to-low

transition. The appeal in having hysteresis on the external interrupt is the tendency to

reject noise and prevent false edges from triggering the Interrupt Service Routine. The

drawback of using RB0/INT pin is that there is only one, and there are 3 sensors that need

to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26)

comes in. The wired-OR consists of a pull-up resistor, and three PNP transistors. The

Vout from each detector is wired into the base of a corresponding PNP transistor. With

all of the sensors in the ‘un-triggered’ state, Vout_Sensor_1, Vout_Sensor_2,

Vout_Sensor_3, will be close to 4.5v (small voltage drop due to base-collector diode in

phototransistors). This means that each of the PNPs in the wired-OR will essentially be

off. Due to a voltage below 5v on the bases of the transistors, there will be some current

flow through the transistors. This is not important, as long as Vout_Wired_Or deflects

over a considerable range with a distinct edge. In fact, having the wired-OR BJT’s

biased at rest gives us a current gain, speeding up the transition from the rest state to

triggered state. Once one of the sensors is triggered, the voltage at the output node of the

wired-OR switches sharply to the triggered state near zero. This circuit, along with tying

all of the outputs of the sensors to input pins of the PIC allows us to use a single external

interrupt pin with three sensors. Resolving which pin triggered the interrupt is up to the

interrupt service routine on the PIC.

11

Page 12: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Internal Power supply

The power supply built for this project is pretty straight forward, so most of it is hardly

worth mentioning. What is worth mentioning, however, is the thought process that had to

be conformed to in choosing components for a power supply like this (see Schematic 4,

page 27).

Before the power supply was constructed, knowing the needs of the loading devices

(everything other than power supply) in terms of current was necessary. The approach

used in this project was to assume everything was ‘on’ and using it worst case (highest)

values of current draw (see Table 1, page 54).

As is evident from the table, the majority of the current drawn in the circuit is from the

sensor circuits. Tallying up all the remaining currents, a final estimated current draw was

found. In the analysis, some small currents were not counted (like the oscillator) and it

was decided that the maximum current should be rounded up considerably due to the

external power block. Although the estimated current draw of the circuit came to about

one quarter of an Ampere, it was decided that the power supply would be designed to

supply 1 Ampere or current. This left plenty of room for any devices that may be

connected to the power block, small uncounted currents and/or any current fluctuations

due to external temperatures.

All components used in the supply were rated at greater than one Ampere, and a one-

Ampere fuse was chosen. The fuse is included to prevent fire in the case of a short

circuit. (Note: wire used in the construction of the power supply is heavy gage, to

prevent an excessive amount of heat from being generated.)

12

Page 13: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

PIC16F84

The PIC16F84 is a RISC (reduced instruction set computing) based microprocessor. It

has 1k x 14 of program memory and 68 general-purpose registers (RAM). There are two

ports, Port A which is 5-bits, and Port B which is 8-bits. For our project, we used RA2-

RA0 for LCD control, RB7-RB4 for LCD data, RB3-RB1 for sensor input, and RB0 for

sensor interrupt. We also have the PIC clocked by a 4MHz oscillator in OSC1/CLKIN.

Hantronix LCD Module

The Hantronix LCD Module is an LCD driver & controller package with a 4x16

character dot matrix LCD screen. It can be interfaced with either 4-bit or 8-bit data; we

used the 4-bit data option.

13

Page 14: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Hardware Design Summary

There were a number of considerations made in the design of this project. Since the use

of a chronograph in the game of ‘paintball’ would most likely happen long before play,

portability was not a major concern. If portability were a major concern, battery

operation would be necessary. This would most likely require redesigning the entire

project for low power consumption, since diodes and ‘always on’ transistors are major

sources of current drain and hence consume large quantities of power. The decision to

make the unit non-portable allowed for a simpler design loosening the design constraints,

while not sacrificing functionality.

The sensor options were mainly between ambient light detecting sensors or an

emitter/receiver pair. With the ambient light detecting sensors, the functioning of the

chronograph depends on an adequate amount of light being available (bright conditions).

Most commercial grade chronographs use ambient light sensors, as most chronographs

are for use with ‘real’ guns that normally require outdoor use. While using this sensor

arrangement allows for more room for error in firing (since there is no ‘beam’ to be

broken), errors in measurement can occur if ambient light conditions are changing or just

inadequate. Furthermore, since this project is designed for use with paintballs rather than

bullets, there is no worry about hitting the chronograph with the projectile. The paintball

will simply break, leaving the chronograph unharmed. For these reasons, we chose to use

an IR emitter/receiver arrangement. This method of sensing uses an infrared emitter on

one side of the firing path, and a receiver on the other side of the firing path. A passing

paintball creates an infrared ‘shadow’ to trip the sensor. This arrangement is very

insensitive to ambient light conditions since ambient light has relatively small IR

component compared to the emitter intensity. This also allows for a more constant

environment than would be possible depending on ambient conditions.

14

Page 15: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Software The software for the ballistic chronograph handles inputs from three IR sensors and

outputs to a Hantronix 4X16 LCD display. The sensors are configured in a wired-or, so

that when one of them is brought low, RB0/INT is brought low and interrupts on the

falling edge. The status of Port B(RB3-RB1) is taken so that the sensor causing the

interrupt can be determined. For the output to the LCD, the upper nibble of Port B(RB7-

RB4) is used for data, and Port A (RA2-RA0) is used for control lines. The software is

interrupt driven with the only interrupts being the timer overflow, which is used for

timing, and RB0/INT which is used for sensor inputs. Error checking is done within the

ISR to account for bogus sensor inputs. Below is a description of the code used in the

project:

LCD_INIT

Description: Initializes the LCD for 4-bit communication. (see Flowchart 3, page 30)

Initializes the Hantronix 4X16 LCD as described in the manufacturer’s notes.

SEND_CMD

Description: Sends the command in register W to the LCD

Uses code modified from Microchip Application Note AN587 to send a command split in

upper and lower nibbles to the LCD. The wait delays are long enough so that the busy bit

does not need to be checked.

SEND_CHAR

Description: Sends the character in register W to the LCD

Uses code modified from Microchip Application Note AN587 to send a character split in

upper and lower nibbles to the LCD. The wait delays are long enough so that the busy bit

does not need to be checked.

15

Page 16: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

INTRO_SCREEN

Description: Sends an introduction screen to the LCD.

Sends the text “Ballistic Chronograph Atkinson&&Turner (c)2000” to the LCD. Formats

the text to approximately center each line.

TOG_E

Description: Toggles E line.

Toggles the E line (the clock for the LCD) with a wait in between the up and down

switches.

WAIT_19

Description: Delays about 18.4ms.

Uses an inner and outer loop to busy wait for about 18.4ms. This delay is more than long

enough for the LCD functions.

CALC_RES

Description: Takes 3 byte number of cycles from XA, XB, and XC and returns 2 byte

speed in ResA and ResB. (see Flowchart 4, page 31)

The speed can be determined by dividing 1e6 (fosc/4) by the number of cycles. The

division is handled by subtracting the number of cycles X from a count initialized to 1e6

until a negative result is yielded. The number of subtractions is the result. Since the

arguments are 3 bytes each, the subtraction is handled in parts, high byte to low byte,

borrowing from a higher byte if needed, and incrementing a counter after all 3 bytes are

handled. If the result is negative, the function returns, and the result is given.

16

Page 17: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

RES_OUT

Description: Takes result in ResA and ResB and prints it on the LCD. (see Flowchart 5,

page 32)

This function divides by 100 to get the 100’s place, and subtracts the 100’s, divides by 10

to get the 10’s place, and subtracts the 10’s and is left with the 1’s place. The division is

handled by counting the number of subtractions until a negative result is yielded. The

subtractions take place in the ResB because 100 and 10 are 1 byte numbers.

Sq_Res

Description: Squares a number. (see Flowchart 6, page 33)

A result from a velocity calculation is determined and stored with this routine. It

calculates the square, by adding the velocity v to itself v times.

Acc

Description: Calculates the acceleration. (see Flowchart 7, page 34)

This routine assumes that the two speeds are instantaneous velocities one foot apart.

Using this assumption, the formula is a = (v12 – v2

2)/2. The Sq_Res routine is used to

square the two velocities, then this routine subtracts them and uses bit rotation to divide

by 2. The sign (positive or negative) of the acceleration is also returned in NEGACC.

ACC_OUT

Description: Outputs the acceleration. (see Flowchart 8, page 35)

This routine continually subtracts 10 from the acceleration given by Acc. This allows the

digits to be built up for the output display much like a car odometer. Once the digits are

determined, they are converted to ASCII and output along with the proper sign from

NEGACC.

Interrupt Service Routine (ISR)

Description: Interrupt service routine. (see Flowchart 9, page 36)

17

Page 18: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Handles the interrupts from the 3 sensors and from the timer overflow. Checks which

interrupt occurred, then services it. Uses a flag, SENFLAG, to determine which sensors

have been triggered in order to prevent invalid inputs.

TIMER

Checks to see if SENFLAG is set, if not, it drops out. Otherwise, it increments the

counter. If the count is larger than a maximum count, it turns the timer interrupt off.

This prevents bad inputs from either making the chip hang or giving bad outputs.

SEN1

First sensor. Clears counters and sets S1 flag on SENFLAG.

SEN2

Second sensor. Checks for the S1 flag on SENFLAG, if not set, it drops out. Otherwise,

it clears SENFLAG, then sets the S2 flag on SENFLAG. It stores the counts for the

sensor 1 to sensor 2, and clears the counters.

SEN3

Third sensor. Checks for the S2 flag on SENFLAG, if not set, it drops out. Otherwise, it

calculates and out puts the two speeds and the acceleration.

Main code

Description: The main routine for the program. (see Flowchart 2, page 29)

Sets up data direction for Ports A and B (RA3-RA0 outputs, RB7-RB4 outputs, RB3-

RB0 inputs). Calls LCD_INIT to initialize LCD, and INTRO_SCREEN to print intro.

The code is interrupt driven, so main enables the interrupts then drops into an infinite

loop.

18

Page 19: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Software Design Summary

Since the PIC is interrupt driven, the bulk of the ‘real’ work is done in the ISR. Proper

design methods were used to make the code readable, editable, and possibly portable.

Thus, as much of the code as is possible and prudent is done in subroutines to add

abstraction to the main parts of the code. In fact, all of the code involving the LCD

display could easily be transferred to another program and implemented with little effort.

The code is commented thoroughly to allow future editing and readability.

19

Page 20: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Results and Conclusions

Testing Methods

Our testing method assumed that the sensor provide an accurate representation of the

paintball passing through. By hooking the sensors up to an oscilloscope and setting it on

the ‘Roll’ mode, we were able to capture the signals generated when the sensors were

triggered. By dividing 1 foot (the distance between sensors) by the time we obtain this

way, we were able to measure the actual speed of the projectile. Conveniently, the

oscilloscope provides the frequency of the pulses, or 1 divided by the time. Because of

this, we didn’t even need to take out a calculator to determine the time. This method

works very well for firing a paintball.

It is not practical to always test the chronograph by firing a paintball, and it is not

possible to fire paintballs at the extremes or our specs with our paintball equipment. In

order to solve this problem, we created a paintball simulator using another PIC chip.

This simulator pulses the sensor inputs on the chronograph to simulate a paintball passing

through the sensors. When using this, we disconnect the sensors and hook up the test PIC

chip in their place. We then proceed with the above method.

The software for the testing PIC chip is very simple. It consists of loops that busy wait in

between pulses on the sensor input pins. The testing program is set up to test through

range of the specs to show that the chronograph is working properly.

20

Page 21: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Results

In our testing, we found that our chronograph can measure speeds beyond both extremes

of our spec. Below our 100 fps spec, we were able to measure around 80 fps within 1 fps

of accuracy. Above our 500 fps spec, we were able to measure around 600 fps within 3

fps of accuracy. This is clearly beyond or specifications for both range of 100 fps to 500

fps and for accuracy of +/- 10 fps.

Conclusion & Future Improvements

The ballistic chronograph proved to be an interesting and worthwhile project. We were

able to learn much about IR sensors, the PIC microprocessor, and interfacing to LCD

modules. We were happy to not only get our project working, but to also beat our specs

and put in an attractive enclosure. There are some things we could improve upon,

however. One thing we could try would be to do our project with a faster microprocessor

to obtain better accuracy. Another interesting addition would be to measure two speeds

and determine the deceleration. Finally, it would be interesting to determine the energy

of the paintball coming out of the barrel.

21

Page 22: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Directions For Use

Indoor Use

For indoor use, screw end-stop in the threaded end of the chronograph. Make sure the

end-stop is securely fastened. Place the chronograph on a fairly level, flat surface. Plug

chronograph into 120VAC-60Hz outlet (U.S. Standard). When the start-up text finishes

coming up on the display, fire your loaded paintball gun in the open end of the

chronograph. When firing, take care to keep the gun level and away from the sides of the

chronograph, paintballs may break on the sides of chronograph otherwise. Measurement

will appear on display.

Outdoor Use

The end-stop is not absolutely necessary for outdoor use. If end-stop is not used, care

should be taken so that exiting paintballs will not harm people or property.

Cleaning the Chronograph

Paintballs will sometimes break inside the chronograph. For clean-up, simply remove the

end-stop, stuff paper towels or rags into non-threaded end of chronograph, and push

rags/paper towels through chronograph with a short stick. Repeat until chronograph is

sufficiently clean.

22

Page 23: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Appendix

Schematics .......................................................................................page 24

Flow Charts......................................................................................page 29

Data Sheets ......................................................................................page 37

Project Proposal ..............................................................................page 39

Source Code .....................................................................................page 40

Parts List ..........................................................................................page 53

Tables...............................................................................................page 54

23

Page 24: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Schematics

Schematic 1 – IR Emitter Circuit

24

Page 25: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Schematic 2 – IR Detector Circuit

25

Page 26: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Schematic 3 – Wired OR Schematic

26

Page 27: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Schematic 4 – Power Schematic

27

Page 28: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Schematic 5 – Entire Circuit Schematic

28

Page 29: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Flowcharts

Initialize Ports

Initialize LCD(LCD_INIT)

Print Intro Screen(INTRO_SCREEN)

Set upInterrupts

Loop ∞

Main Code

Flowchart 2 – Main Code

29

Page 30: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

LCD_INIT

Put LCD inControl Mode

Send 0x303 Times

Send 4 BitControl

Send FunctionSet

Send DisplayOff

Clear Display

Entry Mode

Send Cursor

Return

Flowchart 3 – LCD_INIT Routine

30

Page 31: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

CALC_RES

Set Up1 Million

Clear Result

MilA-XA

Neg?

MilB-XB

Return

No

Yes

Neg? MilA=0? ReturnYes Yes

MilA-1

No

MilC-XC

No

Neg? MilB==0? MilA==0? Return

MilA-1MilB-1

Yes Yes Yes

No No No

Result+1

Flowchart 4 – CALC_RES Routine

31

Page 32: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

RES_OUT

Clear Digits

Neg?

ResB-100

DigA+1

ResA=0?

ResB+100

Yes

No

ResA-1No

Yes

ResB-10

Neg? DigB+1No

Yes

ResB+10

DigC=ResB

Add ASCII '0'to Digits

Send Digitsto LCD

Return

Flowchart 5 – RES_OUT Routine

32

Page 33: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Sq_Res

Store RES inCounter

Yes

No

Sq_Res =Sq_Res + Res

Clear Sq_Res

DecrementCounter

Counter= 0?

Return

Flowchart 6 – Sq_Res Routine

33

Page 34: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Yes

No

Acc

Clear NEGACCFlag

Acc = V2 -V1

Acc <0?

Acc = V1 -V2

NEGACC = 1

Acc = Acc / 2

Return

Flowchart 7 – Acc Routine

34

Page 35: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Yes

No

ACC_OUT

Clear Digits

Acc = Acc -10

Acc >=0 ?

DigD + 1

DigD =10?

DigD = 0

DigC + 1

DigC =10?

DigC = 0

DigB + 1

DigB =10?

DigB = 0

DigA + 1

DigE = Acc+10

Convert Digitsto ASCII

NEGACC= 1? Print "-"

Print Digits

Return

Yes

Yes

Yes

No

No

No

No

Yes

Flowchart 8 – ACC_OUT Routine

35

Page 36: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

ISR

Get PortB

TimerOverflow? ReturnSensor

1?Sensor

2?Sensor

3?

Clear InterruptFlag

IncrementCounter

CounterOverflow?

Counter= Max?

ClearSENFLAG

Return

ReturnNo

Yes

Yes

No

Yes

No No No No

ClearSENFLAG

Clear Counters

Clear InterruptFlag

Return

IsSENFLAG

= S1?

SetSENFLAG=S2

Store TempCounters for V1

IsSENFLAG

= S2?

ClearSENFLAG

Calculate Result(CALC_RES)

of V2

Square V2(Sq_Res)

Store V2

Return

Yes Yes Yes

Yes Yes

Return Return

No No

Clear InterruptFlag

Return

Calculate Result(CALC_RES)

of V1

Square V1(Sq_Res)

Print V1(RES_OUT)

Get V2

Print V2(RES_OUT)

CalculateAcceleration

(Acc)

PrintAcceleration(ACC_OUT)

Clear InterruptFlag

Flowchart 9 – Interrupt Service Routine

36

Page 37: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Data Sheets

Data Sheet 1 – Character Module Initialization

37

Page 38: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Data Sheet 2 – Commands for Character Modules

38

Page 39: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Project Proposal

Ballistic Chronograph

Short Description The ballistic chronograph will measure and numerically display the speed of a projectile. In order to determine the speed, microprocessor will measure the time the projectile takes to travel between two fixed points. Inputs Projectile

Two sensors Outputs Speed of projectile

At least 3-digit display Specifications Measures speeds from 100-500 fps

Will be accurate within 10 fps

39

Page 40: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Source Code ;************************************************************************** ;* Ballistic Chronograph Code ;* Steven Turner & Brandon Atkinson ;* 2000-2001 ;************************************************************************** ;************************************************************************** ;* CONSTANTS ;************************************************************************** W EQU 0 ; destination bits F EQU 1 C EQU 0 ; status bits Z EQU 2 TMR0 EQU 0x01 ; PIC built-in registers OPT EQU TMR0 PCL EQU 0x02 STATUS EQU 0x03 FSR EQU 0x04 PORTA EQU 0x05 TRISA EQU PORTA PORTB EQU 0x06 TRISB EQU PORTB INTCON EQU 0x0B INTMSK EQU 0x90 ; mask for interrupts TOIF EQU 2 ; timer overflow interrupt flag INTF EQU 1 ; RB0 interrupt flag RBIE EQU 3 ; RB0 interrupt enable TOIE EQU 5 ; timer interrupt enable RP0 EQU 5 ; bank selects RP1 EQU 6 S1 EQU 1 ; sensor flags S2 EQU 2 S3 EQU 3 TRISAMSK EQU 0x00 ; tristate port masks TRISBMSK EQU 0x07 LCD_DATA EQU PORTB ; LCD control LCD_DATA_TRIS EQU TRISB LCD_CNTL EQU PORTA E EQU 0 ; LCD Enable control line RW EQU 1 ; LCD Read/Write control line RS EQU 2 ; LCD Register Select control line DELOUT EQU D'23' ; values for WAIT_19 DELIN EQU D'200' XAMAX EQU 0x01 ; largest XA can get

40

Page 41: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

;**************************************************************************** ;* VARIABLES ;**************************************************************************** TEMP EQU 0x10 ; temp value CNTOUT EQU 0x11 ; count loops for WAIT_19 CNTIN EQU 0x12 CHAR EQU 0x13 ; character for LCD routines MilA EQU 0x14 ; bytes for 1 million in CALC_RES MilB EQU 0x15 MilC EQU 0x16 XA EQU 0x17 ; ISR counters XB EQU 0x18 XC EQU 0x19 ResA EQU 0x1A ; results for CALC_RES ResB EQU 0x1B DigA EQU 0x1C ; digits for RES_OUT & ACC_OUT DigB EQU 0x1D DigC EQU 0x1E DigD EQU 0x1F DigE EQU 0x20 BIN EQU 0x21 ; Port B capture in ISR XA1 EQU 0x22 ; temp values for ISR counters XB1 EQU 0x23 XC1 EQU 0x24 Sq1 EQU 0x25 ; temp values for Sq_Res Sq2 EQU 0x26 Sq3 EQU 0x27 CountA EQU 0x28 CountB EQU 0x29 V1Sq1 EQU 0x2A ; vars for v1 & v2 squared V1Sq2 EQU 0x2B V1Sq3 EQU 0x2C V2Sq1 EQU 0x2D V2Sq2 EQU 0x2E V2Sq3 EQU 0x2F Acc1 EQU 0x30 ; output of acceleration from Acc Acc2 EQU 0x31 Acc3 EQU 0x32 ResTEMPA EQU 0x33 ; temp values for ISR ResTEMPB EQU 0x34 NEGACC EQU 0x35 ; flag for negative acc values SENFLAG EQU 0x36 ; flag of sensor triggers for ISR ; ****** END EQUATES ************************************************************

41

Page 42: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

; ****** PIC SETUP CODE ************************************************************* ORG 0x000 ; setup code for PIC GOTO START ORG 0x004 GOTO ISR ; ****** MAIN CODE ************************************************************** START ; POWER_ON Reset (in HW) CLRF STATUS ; Do initialization (Bank 0) CLRF INTCON CLRF PORTA ; ALL PORT output should output Low. CLRF PORTB BSF STATUS, RP0 ; Select Bank 1 CLRF TRISA ; RA3 - RA0 outputs MOVLW 0x0F MOVWF TRISB ; RB7 - 4outputs, RB3 - 0 inputs MOVLW 0x0F ; strong pullups, falling edge RB0 MOVWF OPT BCF STATUS, RP0 ; Select Bank 0 CALL LCD_INIT ; initialize LCD CALL INTRO_SCREEN ; print out intro screen CLRF SENFLAG ; clear out sensor flag MOVLW INTMSK ; setup interrupt MOVWF INTCON BSF INTCON, TOIE ; enable Timer LOOP GOTO LOOP ; loop forever ;************************************************************************************* ;* ISR ;************************************************************************************* ISR MOVF PORTB, W ; get portB MOVWF BIN BTFSC INTCON, TOIF ; check timer overflow CALL TIMER BTFSS BIN, S1 ; check S1 CALL SEN1 BTFSS BIN, S2 ; check s2 CALL SEN2 BTFSS BIN, S3 ; check s3 CALL SEN3 RETFIE TIMER ; timer overflow handling BCF INTCON, TOIF ; clear int flag MOVF SENFLAG, F ; if no sensors set, drop out BTFSC STATUS, Z RETURN INCF XB, F ; increment counter BTFSS STATUS, Z RETURN INCF XA, F MOVLW XAMAX ; check if too large SUBWF XA, W BTFSS STATUS, C RETURN CLRF SENFLAG ; if too big reset sensors

42

Page 43: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

RETURN SEN1 CLRF SENFLAG BSF SENFLAG, S1 ; mark 1st sensor CLRF TMR0 CLRF XA ; clear counters CLRF XB CLRF XC BCF INTCON, INTF ; clear int flag RETURN SEN2 MOVF TMR0, W ; grab time MOVWF XC1 BTFSS SENFLAG, S1 ; check for 1st sensor RETURN ; drop out if not set CLRF SENFLAG BSF SENFLAG, S2 ; set only S2 CLRF TMR0 MOVF XA, W MOVWF XA1 MOVF XB, W MOVWF XB1 CLRF XA CLRF XB BCF INTCON, INTF RETURN SEN3 MOVF TMR0, W ; grab time MOVWF XC BTFSS SENFLAG, S2 ; check for 2nd sensor RETURN ; drop out if not set CLRF SENFLAG CALL CALC_RES ; calculate result CALL Sq_Res ; square result MOVF Sq1, W ; store result MOVWF V2Sq1 MOVF Sq2, W MOVWF V2Sq2 MOVF Sq3, W MOVWF V2Sq3 MOVF ResA, W ; store result MOVWF ResTEMPA MOVF ResB, W MOVWF ResTEMPB MOVF XA1, W ; move temps back MOVWF XA MOVF XB1, W MOVWF XB MOVF XC1, W MOVWF XC CALL CALC_RES ; put out 2nd speed CALL Sq_Res ; square result MOVF Sq1, W ; store result MOVWF V1Sq1 MOVF Sq2, W MOVWF V1Sq2 MOVF Sq3, W MOVWF V1Sq3 MOVLW 0x01 ; clear LCD CALL SEND_CMD MOVLW 0x80 ; goto line 1 CALL SEND_CMD MOVLW 'v' ; output result 1 CALL SEND_CHAR

43

Page 44: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

MOVLW '1' CALL SEND_CHAR MOVLW '=' CALL SEND_CHAR MOVLW ' ' CALL SEND_CHAR CALL RES_OUT MOVF ResTEMPA, W MOVWF ResA MOVF ResTEMPB, W MOVWF ResB MOVLW 0xC0 CALL SEND_CMD MOVLW 'v' ; output result 2 CALL SEND_CHAR MOVLW '2' CALL SEND_CHAR MOVLW '=' CALL SEND_CHAR MOVLW ' ' CALL SEND_CHAR CALL RES_OUT CALL Acc ; calculate acceleration MOVLW 0xD0 CALL SEND_CMD CALL ACC_OUT BCF INTCON, INTF ; clear int flag RETURN ;************************************************************************************ ;* SUBROUTINES ;************************************************************************************ ;************************************************************************************ ;* LCD_INIT Subroutine ;* ;* Initializes LCD for 4 bit communication ;* Initialize LCD by sending: ;* RS RW D7 D6 D5 D4 ;* 0 0 0 0 1 1 ;* wait > 4.5 ms ;* 0 0 0 0 1 1 ;* wait > 100us ;* 0 0 0 0 1 1 ;* 0 0 0 0 1 0 for 4 bit control ;* send command 001010xx (function set) (0x28) ;* send command 00001000 (display off) (0x08) ;* send command 00000101 (display clear) (0x01) ;* send command 00000110 (entry mode) (0x06) ;************************************************************************************ LCD_INIT CALL WAIT_19 CALL WAIT_19 CALL WAIT_19 BCF LCD_CNTL, RS ; put in control mode BCF LCD_CNTL, RW MOVLW 0x30 ; send 0011 3 times MOVWF LCD_DATA CALL TOG_E CALL WAIT_19 CALL TOG_E CALL WAIT_19 CALL TOG_E CALL WAIT_19 MOVLW 0x20 ; send 0010 for MOVWF LCD_DATA ; 4 bit control CALL TOG_E CALL WAIT_19

44

Page 45: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

MOVLW 0x28 ; send funtion set CALL SEND_CMD MOVLW 0x08 ; send display off CALL SEND_CMD MOVLW 0x01 ; clear display CALL SEND_CMD MOVLW 0x06 ; entry mode CALL SEND_CMD MOVLW 0x0E ; send cursor CALL SEND_CMD CALL WAIT_19 CALL WAIT_19 RETURN ;************************************************************************************ ;* TOG_E Subroutine ;* ;* Toggles E line ;************************************************************************************ TOG_E BSF LCD_CNTL, E ; toggle E for LCD CALL WAIT_19 BCF LCD_CNTL, E RETURN ;************************************************************************************ ;* WAIT_19 Subroutine ;* ;* Uses a double loop to eat up CPU time and give >18.4ms delay ;* DELOUT=23, DELIN=200, gives about 18.4ms of delay ;************************************************************************************ WAIT_19 MOVLW DELOUT ; get outer level count MOVWF CNTOUT BKOUT MOVLW DELIN ; get inner delay MOVWF CNTIN BKIN NOP DECFSZ CNTIN, F ; dec, skip next if 0 GOTO BKIN DECFSZ CNTOUT, F ; dec outer count, skip next if 0 GOTO BKOUT RETURN ;************************************************************************************ ;* SEND_CMD Subroutine ;* ;* Modified from Microchip code ;* Sends the command to the LCD in upper and lower nibbles ;************************************************************************************ SEND_CMD MOVWF CHAR ; Character to be sent is in W MOVF CHAR, W ANDLW 0xF0 ; Get upper nibble MOVWF LCD_DATA ; Send data to LCD CALL TOG_E SWAPF CHAR, W ANDLW 0xF0 ; Get lower nibble MOVWF LCD_DATA ; Send data to LCD CALL TOG_E CALL WAIT_19 RETURN

45

Page 46: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

;************************************************************************************ ;* SEND_CHAR Subroutine ;* ;* Modified from Microchip code ;* Sends a character to the LCD in upper and lower nibbles ;************************************************************************************ SEND_CHAR MOVWF CHAR ; Character to be sent is in W MOVF CHAR, W ANDLW 0xF0 ; Get upper nibble MOVWF LCD_DATA ; Send data to LCD BSF LCD_CNTL, RS ; Set LCD to data mode CALL TOG_E SWAPF CHAR, W ANDLW 0xF0 ; Get lower nibble MOVWF LCD_DATA ; Send data to LCD CALL TOG_E BCF LCD_CNTL, RS RETURN ;************************************************************************************ ;* CALC_RES Subroutine ;* ;* Determines the speed, given the number of cycles taken. ;* Speed = 1e6/X where X is the number of cycles. ;* Result is stored as ResA*FF+ResB ;********************************************************************************** CALC_RES MOVLW 0x0F ; set up 1M MOVWF MilA MOVLW 0x42 MOVWF MilB MOVLW 0x40 MOVWF MilC CLRF ResA ; clear out result CLRF ResB LOOP_RES MOVF XA, W ; MilA-XA SUBWF MilA, F BTFSS STATUS, C ; if neg, then done RETURN ; A= neg (done) MOVF XB, W ; MilB-XB SUBWF MilB, F BTFSC STATUS, C ; if not neg, go to next op GOTO OPC MOVF MilA, F ; check if A is zero BTFSC STATUS, Z RETURN ; A=0, B=neg (done) DECF MilA, F ; subtract 1 from A OPC MOVF XC, W ; MilC-XC SUBWF MilC, F BTFSC STATUS, C ; if not neg, next part GOTO FINISH MOVF MilB, F ; check if B is zero BTFSC STATUS, Z ; if B is zero goto next GOTO CHKA DECF MilB, F ; B is not zero GOTO FINISH CHKA MOVF MilA, F ; if A=0 then done BTFSC STATUS, Z RETURN ; A=0 B=0 C=neg (done) DECF MilA, F DECF MilB, F ; MilB=FF FINISH INCF ResB, F ; increment result BTFSC STATUS, Z INCF ResA, F ; add carry if needed

46

Page 47: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

GOTO LOOP_RES ; next iteration ;********************************************************************************** ;* RES_OUT Subroutine ;* ;* Takes result given by CALC_RES & outputs to LCD ;********************************************************************************** RES_OUT CLRF DigA ; clear out counters CLRF DigB CLRF DigC DIG_100 MOVLW 0x64 ; 100's SUBWF ResB, F BTFSC STATUS, C ; if neg GOTO INC100 MOVF ResA, F BTFSC STATUS, Z GOTO DIG_10A ; done 100's DECF ResA, F ; take 1 from ResA INC100 INCF DigA, F GOTO DIG_100 DIG_10A MOVLW 0x64 ; put 100 back on negative # ADDWF ResB,F DIG_10 MOVLW 0x0A ; 10's SUBWF ResB, F BTFSS STATUS, C ; if neg GOTO DIG_1A INCF DigB, F GOTO DIG_10 DIG_1A MOVLW 0x0a ; put 10 back on negative # ADDWF ResB, F DIG_1 MOVF ResB, W MOVWF DigC MOVLW '0' ; covert digits to ASCII ADDWF DigA, F ADDWF DigB, F ADDWF DigC, F MOVF DigA, W ; output result CALL SEND_CHAR MOVF DigB, W CALL SEND_CHAR MOVF DigC, W CALL SEND_CHAR MOVLW ' ' ; print “ ft/s” CALL SEND_CHAR MOVLW 'f' CALL SEND_CHAR MOVLW 't' CALL SEND_CHAR MOVLW '/' CALL SEND_CHAR MOVLW 's' CALL SEND_CHAR RETURN

47

Page 48: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

;********************************************************************************** ;* INTRO_SCREEN ;* ;* Prints out the introduction screen for the project ;* More readable and about the same amount of code as using a table ;********************************************************************************** INTRO_SCREEN MOVLW 0x02 ; home CALL SEND_CMD CALL WAIT_19 CALL WAIT_19 MOVLW ' ' ; print "Ballistic" CALL SEND_CHAR MOVLW ' ' CALL SEND_CHAR MOVLW ' ' CALL SEND_CHAR MOVLW 'B' CALL SEND_CHAR MOVLW 'a' CALL SEND_CHAR MOVLW 'l' CALL SEND_CHAR MOVLW 'l' CALL SEND_CHAR MOVLW 'i' CALL SEND_CHAR MOVLW 's' CALL SEND_CHAR MOVLW 't' CALL SEND_CHAR MOVLW 'i' CALL SEND_CHAR MOVLW 'c' CALL SEND_CHAR MOVLW 0xC2 ; line 2, col 2 CALL SEND_CMD MOVLW 'C' ; print "Chrongraph" CALL SEND_CHAR MOVLW 'h' CALL SEND_CHAR MOVLW 'r' CALL SEND_CHAR MOVLW 'o' CALL SEND_CHAR MOVLW 'n' CALL SEND_CHAR MOVLW 'o' CALL SEND_CHAR MOVLW 'g' CALL SEND_CHAR MOVLW 'r' CALL SEND_CHAR MOVLW 'a' CALL SEND_CHAR MOVLW 'p' CALL SEND_CHAR MOVLW 'h' CALL SEND_CHAR MOVLW 0x90 ; line 3 CALL SEND_CMD MOVLW 'A' ; print "Atkinson&&Turner" CALL SEND_CHAR MOVLW 't'

48

Page 49: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

CALL SEND_CHAR MOVLW 'k' CALL SEND_CHAR MOVLW 'i' CALL SEND_CHAR MOVLW 'n' CALL SEND_CHAR MOVLW 's' CALL SEND_CHAR MOVLW 'o' CALL SEND_CHAR MOVLW 'n' CALL SEND_CHAR MOVLW '&' CALL SEND_CHAR MOVLW '&' CALL SEND_CHAR MOVLW 'T' CALL SEND_CHAR MOVLW 'u' CALL SEND_CHAR MOVLW 'r' CALL SEND_CHAR MOVLW 'n' CALL SEND_CHAR MOVLW 'e' CALL SEND_CHAR MOVLW 'r' CALL SEND_CHAR MOVLW 0xD4 ; line 4, col 4 CALL SEND_CMD MOVLW '(' ; print "(c) 2000" CALL SEND_CHAR MOVLW 'c' CALL SEND_CHAR MOVLW ')' CALL SEND_CHAR MOVLW ' ' CALL SEND_CHAR MOVLW '2' CALL SEND_CHAR MOVLW '0' CALL SEND_CHAR MOVLW '0' CALL SEND_CHAR MOVLW '0' CALL SEND_CHAR RETURN ;****************************************************************************** ;* Sq_Res Subroutine ;* ;* Squares result (ResA|ResB), returns ;* to Sq1|Sq2|Sq3 ;****************************************************************************** Sq_Res CLRF Sq1 ; clear out result CLRF Sq2 CLRF Sq3 MOVF ResA, W ; copy counters MOVWF CountA INCF CountA, F MOVF ResB, W MOVWF CountB Sq_Res1 MOVF ResB, W ADDWF Sq3, F

49

Page 50: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

BTFSC STATUS, C ; if carry inc next INCFSZ Sq2, F GOTO Sq_Res2 INCF Sq1, F Sq_Res2 MOVF ResA, W ADDWF Sq2, F BTFSS STATUS, C ; if carry, inc next INCF Sq1, F DECFSZ CountB, F GOTO Sq_Res1 DECFSZ CountA, F GOTO Sq_Res1 RETURN ;******************************************************************************* ;* Acc subroutine ;* ;* Calculates the acceleration given two squared ;* speeds V1Sq1|V1Sq2|V1Sq3, V2Sq1|V2Sq2|V2Sq3 ;* Stored to Acc1|Acc2|Acc3 ;******************************************************************************* Acc CLRF NEGACC MOVF V2Sq1, W ; put V2 in result MOVWF Acc1 MOVF V2Sq2, W MOVWF Acc2 MOVF V2Sq3, W MOVWF Acc3 MOVF V1Sq1, W ; sub high byte SUBWF Acc1, F MOVF V1Sq2, W ; sub mid byte SUBWF Acc2, F BTFSS STATUS, C DECF Acc1, F MOVF V1Sq3, W ; sub low byte SUBWF Acc3, F BTFSC STATUS, C GOTO Acc_1 MOVLW 0x01 SUBWF Acc2, F BTFSS STATUS, C DECF Acc1, F Acc_1 BTFSS Acc1, 7 ; if negative do opposite GOTO Acc_2 INCF NEGACC, F MOVF V1Sq1, W ; put V2 in result MOVWF Acc1 MOVF V1Sq2, W MOVWF Acc2 MOVF V1Sq3, W MOVWF Acc3 MOVF V2Sq1, W ; sub high byte SUBWF Acc1, F MOVF V2Sq2, W ; sub mid byte SUBWF Acc2, F BTFSS STATUS, C DECF Acc1, F MOVF V2Sq3, W ; sub low byte SUBWF Acc3, F

50

Page 51: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

BTFSC STATUS, C GOTO Acc_1 MOVLW 0x01 SUBWF Acc2, F BTFSS STATUS, C DECF Acc1, F Acc_2 BCF Acc3, 0 ; clear out odds RLF Acc1, W ; get high bit in C RRF Acc1, F RRF Acc2, F RRF Acc3, F RETURN ;********************************************************************************* ;* ACC_OUT Subroutine ;* ;* Takes result given by Acc & outputs to LCD ;********************************************************************************* ACC_OUT CLRF DigA ; clear out counters CLRF DigB CLRF DigC CLRF DigD CLRF DigE MOVLW 'a' ; output “a= “ CALL SEND_CHAR MOVLW '=' CALL SEND_CHAR MOVLW ' ' CALL SEND_CHAR MOVF NEGACC, F ; check for negative BTFSC STATUS, Z GOTO ACCO_10 MOVLW '-' ; output negative sign CALL SEND_CHAR ACCO_10 MOVLW 0x0A SUBWF Acc3, F BTFSS STATUS, C ; if negative GOTO ACCO_CARRY ACCO_10A INCF DigD, F MOVLW 0x0A SUBWF DigD, W BTFSS STATUS, Z GOTO ACCO_10 CLRF DigD INCF DigC, F MOVLW 0x0A SUBWF DigC, W BTFSS STATUS, Z GOTO ACCO_10 CLRF DigC INCF DigB, F MOVLW 0x0A SUBWF DigB, W BTFSS STATUS, Z GOTO ACCO_10 CLRF DigB INCF DigA, F GOTO ACCO_10 ACCO_CARRY MOVF Acc2, F ; carry from Acc2 BTFSC STATUS, Z GOTO ACCO_1 DECF Acc2, F GOTO ACCO_10A

51

Page 52: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

ACCO_1 MOVLW 0x0A ADDWF Acc3, W ; put the remainder in 1's place MOVWF DigE MOVLW '0' ; covert digits to ASCII ADDWF DigA, F ADDWF DigB, F ADDWF DigC, F ADDWF DigD, F ADDWF DigE, F MOVF DigA, W ; print digits CALL SEND_CHAR MOVF DigB, W CALL SEND_CHAR MOVF DigC, W CALL SEND_CHAR MOVF DigD, W CALL SEND_CHAR MOVF DigE, W CALL SEND_CHAR MOVLW ' ' ; print “ ft/s^2” CALL SEND_CHAR MOVLW 'f' CALL SEND_CHAR MOVLW 't' CALL SEND_CHAR MOVLW '/' CALL SEND_CHAR MOVLW 's' CALL SEND_CHAR MOVLW '^' CALL SEND_CHAR MOVLW '2' CALL SEND_CHAR RETURN end

52

Page 53: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Parts List

Quantity Part Description Comment 6 IR Phototransistor Digikey Part #

160-1062-ND 6 IR Photodiode Digikey Part #

160-1031-ND 13 16 pin chip carrier 2 Perf. Board Sheets 3 Wire wrap wire spools

Many Various Resistors 1 470uF Electrolytic Cap. 1 0.1uF Ceramic Cap 2 Archer ‘Copper Clad’

board

1 LM7805 Voltage Reg. 1 1 Ampere Fuse 1 120v-14.4v transformer (1.2

Ampere)

1 Power LED with resistor 1 Hantronix LCD Module 1 RadioShack Project Box 1 RadioShack QR Power B. (Speaker-like power

terms) 1 RadioShack Isolation

Block

3 PNP Transistors (2N3906) (Wired-OR) 1 PIC16F84 10MHz rated 1 TTL Crystal Clock

Oscillator 4MHz

Jameco Part # 27967

53

Page 54: A Ballistic Chronograph · 2010. 6. 17. · to trigger interrupts. This is where the wired-OR circuit (see Schematic 3, page 26) comes in. The wired-OR consists of a pull-up resistor,

Tables

Circuit Component Current Draw

3 ‘ON’ Detectors 0.234 A Max Current from 3 ‘ON’ Wired OR transistors

0.0034 A

Maximum Current from PIC 4.5 mA Maximum Current from Display 0.3 mA LM7805 max current 8.0 mA

TOTAL 250.2 mA

Table 1 – Approximate Current Total

54