Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to make a speed trap for a bullet ?

Status
Not open for further replies.

stelikas

Newbie level 4
Joined
Nov 20, 2008
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,324
I want to make a speed trap for a bullet, do you have any ideas how to do it?
I want to use pic microcontroller with ccs compiler!
 

Re: Speed Trap

i want to measure the speed of a bullet
 

Re: Speed Trap

To calculate the speed of a bullet either calculate the time taken & distance traveled & then compute the speed by the formula,
Speed = Distance/Time.
Regards,
Jerin.
 

Re: Speed Trap

How to measure this time is the problem, i know how to calculate!
I am thinking of two sensors, they will be in a standar distance, how i measure the time of traveling of the bullet between the sensor???
 

Re: Speed Trap

Use a high speed camera and analyze the footage know how many frames / second were shot, and measure the distance traveled between frames. That would be the best method to find the time.
Regards,
Jerin. :)
 

Re: Speed Trap

some kind of a light sensor would work but you have to predict the exact path of the bullet so the sensors shouldn't be too far apart.
 

Re: Speed Trap

my proplem is the code for the PIC!i dont know if i have to use 2 interrupts and measure the program cycles to find the time that the bullet needs to go from the first second to the second!i dont know how to do it
 

Re: Speed Trap

use a timer. a gated timer will be more accurate.

1) set up the timer.
2) wait for the first sensor.
3) turn on the timer / and set up the gate to start counting.
4) once the bullet passes the 2nd timer, it stop's the gate.
5) read off the timer and you got your time.
6) you already know the distance between the two sensors -> you got the speed.
 

Re: Speed Trap

You can assume between Mach 1 and Mach 3, in other words, 3 downto 1 ms time-of-flight for 1 m distance. That can be easily measured with standard photoelectric barriers and CCP inputs.
 

Re: Speed Trap

An alternative idea - if you're looking to measure only one bullet size, use 1 optical trap and use the LENGTH of the pulse generated and the length of the muzzle to calculate it's speed :)

(For comparison sake, the fastest bullet is supposedly the Winchester .223 Super Short Magnum and it's speed is 1220 meters per second. It's length is somewhere around 2 centimeters - which gives an approximate 1600 uS - microsecond pulse length).
 

Re: Speed Trap

I did a quick test to see if it works.

the thought process basically goes along what I outlined earlier, except that I didn't gate the timer.

Code:
//the code measures time elapsed between two active high signals (IN1 and IN2)
//the elapsed time is shown on OUT_PORT.

#include <regx51.h>
#include "gpio.h"

#define OUT_PORT		P3
#define OUT_DDR			P3
#define OUT_PINs		0xff			//output pins on p2

#define IN_PORT			P2
#define IN_DDR			P2
#define IN1				(1<<0)			//first sensor, active high
#define IN2				(1<<1)			//2nd sensor, active high

void tmr0_init(void) {					//set up tmr0
	TMOD &= 0xf0;						//clear tmod's lower four bits
	TMOD |= 0x01;						//tmr0 as 16-bit timer, not gated
	TR0=0;								//stop the timer
}

void char_display(unsigned char val_char) {				//display tmr0's readings
	OUT_PORT = val_char;						//display tl0 only
}

void mcu_init(void) {					//reset mcu and set-up the pins
	IO_CLR(OUT_PORT, OUT_PINs);			//drive out_pins low
	IO_OUT(OUT_DDR, OUT_PINs);			//out_pins as output

	IO_IN(IN_DDR, IN1 | IN2);			//in1 and in2 as input
}

int main(void) {
	mcu_init();							//reset the mcu / pins
	tmr0_init();						//initialize the tmr

	while (1) {
		TH0=0, TL0=0;					//reset tmr counters
		while (!IO_GET(IN_PORT, IN1))
			continue;					//wait for IN1 to go high
		TR0=1;							//start tmr0
		while (!IO_GET(IN_PORT, IN2))
			continue;					//wait for IN2 to go high
		TR0=0;							//stop tmr0
		
		char_display(TH0);				//display th0
		char_display(TL0);				//display tl0
	}
}

the first input signal comes in on IN1, at 1second. the 2nd input signal comes in on IN2, 1000us (0x03e8) later.

the code is running on a 89C51 with a 12Mhz xtal so the timer tick is 1us each.

as you can see in the attached chart, the code reads the high byte to be 0x03, and the low byte to be 0xec, or the combined time of 0x03ec -> 1004us, about 4us off the real time.

not bad.
 

Attachments

  • C51 Speed Trap.PNG
    C51 Speed Trap.PNG
    33.4 KB · Views: 92

Re: Speed Trap

Yes, it's a straightforward solution considering the limited hardware capabilities of the basic 8051. Assuming IO_GET evaluates to a simple bit addressing macro, it achieves a timing uncertainty of 2x2 cycles (= 4 µs for a standard 12 MHz clocked 8051), which seems acceptable to measure 1 ms. Without external gating hardware, a 8051 can't perform better.

Those PIC processors, that expose a two channels CCP (capture and compare unit) can easily achieve sub µs accuracy. But you have to understand the details of PIC timer and CCP programming.
 

Re: Speed Trap

the beauty of the code I posted earlier is that it works with pretty much any mcu with a timer. the downside is that it has larger timing errors.

the use of a gated timer will greatly help reduce the timing errors.

here is the same code, modified to allow the use of a gated timer - in this case, the gate is active high.

Code:
//the code measures time elapsed between two active high signals (IN1 and IN2)
//the elapsed time is shown on OUT_PORT.

#include <regx51.h>
#include "gpio.h"

#define OUT_PORT		P2
#define OUT_DDR			P2
#define OUT_PINs		0xff			//output pins on p2

#define IN_PORT			P3
#define IN_DDR			P3
#define IN1				(1<<0)			//first sensor, active high
#define IN2				(1<<2)			//2nd sensor, active high, on int0

void tmr0_init(void) {					//set up tmr0
	TMOD &= 0xf0;						//clear tmod's lower four bits
	TMOD |= 0x01 | 0x08;				//tmr0 as 16-bit timer and gated
	TR0=0;								//stop the timer
}

void char_display(unsigned char val_char) {				//display tmr0's readings
	OUT_PORT = val_char;						//display tl0 only
}

void mcu_init(void) {					//reset mcu and set-up the pins
	IO_CLR(OUT_PORT, OUT_PINs);			//drive out_pins low
	IO_OUT(OUT_DDR, OUT_PINs);			//out_pins as output

	IO_IN(IN_DDR, IN1 | IN2);			//in1 and in2 as input
}

int main(void) {
	mcu_init();							//reset the mcu / pins
	tmr0_init();						//initialize the tmr

	while (1) {
		TH0=0, TL0=0;					//reset tmr counters
		while (!IO_GET(IN_PORT, IN1))
			continue;					//wait for IN1 to go high
		TR0=1;							//start tmr0
		while (IO_GET(IN_PORT, IN2))
			continue;					//wait for IN2 to go low
		TR0=0;							//stop tmr0
		
		char_display(TH0);				//display th0
		char_display(TL0);				//display tl0
	}
}
 

Attachments

  • C51 Speed Trap Gated Tmr.PNG
    C51 Speed Trap Gated Tmr.PNG
    35.6 KB · Views: 85
Last edited:

Re: Speed Trap

in this case, we are underestimating the timing by 4us, because we started the timer late, after the first pulse has arrived.

---------- Post added at 00:10 ---------- Previous post was at 00:07 ----------

one way to eliminate that underestimation is to introduce a hardware trigger that goes high after the first pulse has arrived and goes low after the 2nd pulse has arrived - a flip-flop.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top