Air rifle chronograph

JoePage2008x2

New Member
Basically what i am doing is making a chronograph for an air rifle, it needs to measure time between a distance to work out the velocity of a projectile. I want the chronograph being able to measure speeds up to 300m/s or 900f/s or more.

The distance between the gates is 20cm, i need to be able to measure the time between the gates and then convert it to speed. say 0.001 seconds = 200m/s. Im having trouble with the timing, any ideas how to accurately measure timing from 1 to 10 micro seconds, i know you can do 1us with the pauseus command running at 40mhz but i cannot do this accurately.

Is there a chance anyone could give me a program that can can do this, im doing this on a picaxe 28x1. pin0 is first light gate, pin1 is second light gate, i need the speed to be saved as a variable. I can do the maths bit, just need a very accurate timer.

Help would be appreciated, thanks
 

jglenn

Senior Member
You need a "gated oscillator". 1 MHz clock, or 10 MHz would be better. TTL most likely. You gate the clock into a counter between the on and off points.

I would use logic to do the actual measurement, then send it to the PICAXE for post processing. If you really want high speed, use ECL logic (emitter coupled).
 

womai

Senior Member
My suggestion would be to use a few fast logic gates that produce a short pulse, starting when the bullet activates the first sensor, and stopping when it activates the second sensor. You could then use the Picaxe's pulsin command to measure the length of this pulse.

One possibility:

First sensor signal triggers a resettable D-flip-flop (DFF) which latches a "1" (high) through. Connect the DFF's input to 5V. Connect the clock input to your sensor. Connect the DFF's reset input to the Picaxe. Have a look at the sample logic of my Picaxe oscilloscope, especially the trigger part (DFF1):

http://www.pdamusician.com/lcscope/files/lcs1m_schematic_3_of_7.png

Similar setup for the second sensor and a second DFF. A 74HC74 should be suitable and as an added bonus already contains two DFFs in a single package.

Feed the outputs of these two DFFs into an XOR gate, e.g. a 74HC86.

To operate the circuit, have the Picaxe reset both DFFs. Their outputs become low, and hence the XOR's output becomes low as well (0 xor 0 = 0). Once the first sensor fires, the first DFF's output goes high, and the XOR output becomes high as well (1 xor 0 = 1). Once the sensor fires and the second DFF changes state, the XOR will go low again (1 xor 1 = 0).

In total, you get a pulse with a width equal to the bullets time of travel between the two sensors.

The beauty of the proposed circuit is that you can first test it out at a very slow speed (over seconds or minutes), replacing the sensors with pulled-down switches, so it's possible to put it together without an oscilloscope.

As long as the sensors' output pulses are longer than the minimum pulse width for the DFFs clock input, the logic gates don't need to be super-fast, and you can stick with fast CMOS logic (74HCxx series). Unless you have some experience, ECL logic is much more tricky to work with than CMOS logic.

A gated counter as mentioned above is another option, but you will need something that can run at several MHz. Actually you could use my circuit to gate the clock to a standard ripple counter, so this solution would be a superset of my proposal; although as long as the Picaxe has enough resolution with its pulsin command, why complicate your life?

Yet another option is to have the pulse drive a linear voltage ramp and measure the final voltage, which will be proportional to the pulse width. That's a method often emplyed to measure ultra-short pulses (1ns and below). But again, more complicated to design.

Wolfgang
 
Last edited:

hippy

Technical Support
Staff member
The key requirement is having a pulse which represents the time the projectile is between the first gate and second as suggested.

Then it's a matter of how to determine the length of that pulse. The PULSIN command is the best choice but its resolution mey be too low for some applications. At 300m/s, over 20cm, the shortest pulse will be 600us so 5us accuracy at 8MHz ( 2.5us at 16MHz ) may well be suitable here.

A gated oscillator as also suggested would probably be the second easiest scheme to implement; a counter increments while that pulse is present, the count read at the end proportional to the length of pulse.

Most PICAXE's include timer peripherals and some of those ( through poking SFR control registers ) can be used as counters and even gated counters which can count input pulses at up to 16MHz ( check the datasheets for specific devices ). That may be a suitable solution allowing measurement to ~60ns accuracy and should only require a 16MHz clock source plus gating flip-flop for the sensors. Because timing accuracy is dependant on external hardware alone, any PICAXE with the right hardware support can be used, at any clock speed and even using an internal oscillator.

You can select a counter clock rate which matches the distance between gates ( 10MHz for 20cm ) or adjust gate distance to match the crystal ( 16cm for 16MHz ) to make the count directly proportional to distance to simplify the PICAXE maths.
 

Janne

Senior Member
I've also been thinking about building a chronigraph.

What kind of sensors are you going to use in the device? For my device I'd like to measure speeds upto 900m/s, and I was thinking I could achieve this with the picaxe pulsin-command. For the pulsin to work, i suppose the distance between the sensor would need to be longer than in this air rifle case.
 

Rickharris

Senior Member
I've also been thinking about building a chronigraph.

What kind of sensors are you going to use in the device? For my device I'd like to measure speeds upto 900m/s, and I was thinking I could achieve this with the picaxe pulsin-command. For the pulsin to work, i suppose the distance between the sensor would need to be longer than in this air rifle case.

I have no idea if this works but a card target with a piezo sounder stuck to it would give a sharp pule as the slug penetrated the card - of course some velocity would be lost - But I suspect - without trying it - that the size of the pulse would be proportional to the speed the slug hits the target.

Alternative ballistic jelly.
 

JoePage2008x2

New Member
Im using photo diodes, i will be using a seperate chip to detect the change. I have been trying the pulsout and the pulsin commands but not having much luck.
Below is the code for the first chip

Code:
label_1: if pin4 = 1 then goto start ` first gate
         goto label_1
start:pulsout 2,1
      if pin1 = 1 then goto label_2 `second gate
      goto start
label_2: pause 2000
         goto label_1
Below is the code for the second chip

Code:
setfreq em16
starta:  let pinsc = %10000000
label_6: if pin3 = 1 then goto label_5 ` triggers when first gate activates
         goto label_6
         
label_5: pulsin 5,1,w0 `receiving pulse length from fist chip     
Start: let dirsc = %10000000
       let pinsc = %10000000

label_2: 
         b2 = w0 DIG 4  ` The whole of the next bit is to display 
         b3 = w0 DIG 3  ` the value of w0 by using a BCD driver and
         b4 = w0 DIG 2  ` a single 7-segment display.
         b5 = w0 DIG 1 
         b6 = w0 DIG 0 
         
        
         let pinsc = %10000000 `turn display off.   This is so there is a space 
         pause 50                     ` between digits
         let pinsc = %00000000 `turn display on
         let pins = b2
         pause 1000
         let pinsc = %10000000
         pause 50
         let pinsc = %00000000
         let pins = b3
         pause 1000
         let pinsc = %10000000
         pause 50
         let pinsc = %00000000
         let pins = b4
         pause 1000
         let pinsc = %10000000
         pause 50
         let pinsc = %00000000
         let pins = b5
         pause 1000
         let pinsc = %10000000
         pause 50
         let pinsc = %00000000
         let pins = b6
label_3:  if pin6 = 1 then goto starta
         goto label_3
My problem is that the second chip does not pick up the length of the pulses and therefore the display always says 0
I may get a high speed counter chip but dont have one + PIC chip would be a lot more handy.
 

hippy

Technical Support
Staff member
It's not clear how you are using the "first chip". If using "If pin4=1" to detect when the projectile passes the gate you will have problems, the bullet being in the target before the PICAXE has even finished noticing the pin has gone high. An exaggeration but not much.

You need high-speed hardware which will produce a pulse while the projectile is between the two gates. The PICAXE is just too slow for this task.

In your "second chip", you have similar problems on trying to spot the first gate firing. The easiest solution is just to read a PULSIN, which will start to arrive as the first gate is passed.

Code:
Gate 1  )======(----.  .------------.               .----------.
                    `--|  Physical  |               |          |
                       |  Hardware  |---> pulse --->|  PICAXE  |
                    .--|  Circuit   |               |          |
Gate 2  )======(----'  `------------'               `----------'
 

JoePage2008x2

New Member
I thought that the picaxe may be too slow. i have managed to find a circuit in one of my electronic book (Horowitz and Hil The Art Of Electronics, page 360). This basically shows a counter chip that runs at 10mhz and has two inputs. It can count frequencies and stuff like that but mainly can count the pulses between when input A goes high and input b goes high, it also has an 8 didit display.
The chip id is ICM 7216B you may be able to find this circuit on the internet.
I know picaxe is quite good for basic, but im going to be starting college soon and they use the older type of basic, does anyone know any good books.
 

SilentScreamer

Senior Member
Is page 360 a typo? I have the book in front of me, page 360 is about switching regulators or (I've just realised) do you have the first edition?

EDIT: Just found it, page 526 if anyone is interested. I'm not surprised the IC is obsolete though, my copy is from 1989 (older than me :p) if its in the first edition that means the IC was around in 1980.
 
Last edited:

MartinM57

Moderator
The chip id is ICM7216B you may be able to find this circuit on the internet.
I can't - apart from the Intersil data sheet at http://www.intersil.com/cda/deviceinfo/0,1477,ICM7216B,0.html. Maybe it's gone end-of-line i.e. unavailable. How old is your book? Maybe you could use some of the ideas from the circuit in the book for your circuit (for which the requirements are quite tough - do you have the basic experience of flashing LEDs, displaying stuff on seven segment displays etc?)

I know picaxe is quite good for basic, but im going to be starting college soon and they use the older type of basic, does anyone know any good books.
PICAXE basic is targetted at supporting what a PICAXE does i.e. it's a microcontroller that (in normal uses) connects to other electronic components to control something by sensing inputs, creating outputs, starting and stopping timers, responding to interrupts, outputting PWM signals etc etc. As such, it's BASIC language is aligned at most of those things and it lacks some of the features available in the more mainstream BASIC compilers used on desktop/server computers - such as arrays, strings variables, functions, parameter passing etc....but a good grounding in PICAXE BASIC is a great introduction to college BASIC. Good luck!
 

womai

Senior Member
Here is a simple concept for a gated counter that can run up to maybe 50 MHz and uses just five cheap and easy-to-get 74HCxx series logic chips. It's basically what I outlined in words in my previous post. Much easier than trying to build the counter from Horowitz which is vast overkill for your needs.

Counter_CLK is supplied from the Picaxe's PWM output and determines the count frequency. A Picaxe 28X1 at 16 MHz can produce a 2 MHz clock so you can count 0.5 us interval. A 28X2 running at 40 MHz can do PWM up to 5 MHz so you could count 0.2 us intervals. More than fast enough for you.

DFF_CLR_N and CTR_CLR are connected to two Picaxe outputs. Pull DFF_CLK_N low and then high again to reset the flip-flops (DFF1). Pull CTR_CLR high and then low again (note the different polarity compared to DFF_CLR_N!) to reset the counter output to zero. After that, the gated counter is armed and ready.

The upper DFF will produce a 1 the moment the signal from sensor 1 transitions from low to high.

The lower DFF will produce a 1 the moment the signal from sensor 2 transitions from low to high.

The outputs go to the XOR1 gate which will produce a high pulse for the time between the two transitions. The AND1 gate acts as the clock gate which will let the clock signal to the counter only while the pulse from XOR is high.

The counter consists of four daisy-chained 4-bit counters (2 per 74HC393 chip, so that's just 2 chips, CTR1 and CTR2) and thus can count up to 65535; after that it will wrap around to zero, so e.g. with a 5 MHz PWM signal you can measure intervals up to 13.1 msecs with a resolution of 0.2 usecs. If you use a Picaxe 40X2 you can connect counter output 0 to 8 to Picaxe input 0 to 8 and counter output 9 to 15 to Picaxe portD input 0 to 8. Reading the two-byte counter result is then trivial.

Note that for reliable operation each logic chip should have a 0.1uF ceramic capacitor between power and ground close to the chip in order to buffer supply current surges when the logic circuit switches (capacitors were left out in the concept schematic).

Also make sure to connect all unused inputs of the logic chips (XOR1, AND1) to ground; leaving them floating can result in excess current draw and/or oscillations.

By using a slower PWM frequency (or generate the clock using slow toggle commands and pauses) you can easily test the circuit's operation in slow motion if you don't have an oscilloscope and a fast signal source.

As an improvement, you could connect the output of the second DFF to another input on the Picaxe. The moment this line goes high indicates that the measurement is complete and the Picaxe can read back the counter value.

Hope that helps.

Wolfgang
 

Attachments

Last edited:

lbenson

Senior Member
Nice circuit, Wolfgang. With a much slower speed, this would do for an early posting of Wrenow's, December 21, 2006 -- http://www.picaxeforum.co.uk/showthread.php?t=5794&highlight=speed -- "Speed Trap," and my own very first posting regarding only the picaxe side of things. Overkill, though, I guess, for that use.

A proofreading note: I think your second use of "The upper DFF" is supposed to be "The lower DFF".
 
Last edited:

womai

Senior Member
Thanks for the proofreading - corrected now. Yes, the pifalls of copy & paste :)

The beauty of the counter is that everything but the actual count process is still controlled from the Picaxe. So if e.g. you want a longer interval, just lower the PWM frequency.

Another option for longer count intervals is to simply daisy-chain additional counter ICs, and take only the necessary number of higher-valued outputs, disregarding the lower-value outputs.

Also, by keeping the DFF's reset lines low you can disable the sensor inputs.

Wolfgang
 
Last edited:

JoePage2008x2

New Member
The link that MartinM57 has included contains the circuit diagram that i mean, click on the click and close to the bottom click on the datasheet, you should find it. I have asked for quotes on the internet and got 14 replies ranging from 8USD to 30USD per chip, i dont think that £5 is too much to pay for a chip but i will still keep trying with the picaxe.

Thanks everyone that is helping me and replying to comments.
 

womai

Senior Member
The gated counter circuit that I posted can be built for around US$2 and does not contain any hard-to-get parts. IMHO a better solution than trying to source some obscure obsolete device.
 

JoePage2008x2

New Member
I just looked at the datasheet for 74hc393 and it can have a clock input of up to 99mhz, i will be having up to an 8 digit seven segment display, the reson i like the older chip is because i only need two chips and i can make it compact. The problem with using the 393 is that i will have to have loads of driver chips for the 7 segment displays. If i cannot get old of the 7216B then i will definatley do it your way.
 

womai

Senior Member
If you want it as compact as possible, you could use a CPLD (nonvolatile programmable logic chip). Xilinx XC9572 is a good choice because it can run at 5V supply and you can get the PLCC packaged version that mounts into a 0.1 inch pitch socket (super-easy to solder). Such a chip could hold the full sample logic in a single chip, plus an SPI-type interface (serial shift register) so you can read out the the counter result using just two pins (clock and data) on your Picaxe with the spiin command.

If you multiplex your LED display you can easily drive the whole display from the Picaxe without further chips (maybe apart from Darlington drivers).

I have these CPLD chips (and the necessary programming software and hardware) available from an earlier project (the first version of my Picaxe scope), and love doing that sort of stuff, so I'd be willing to develop the circuit and program such a device for free if you like. Let me know.

Wolfgang
 

womai

Senior Member
Here's the counter and shift register implemented in a Xilinx CPLD (XC9572). The chip is still half empty (35 out of 72 macrocells used), so there is room for additional features. Pre-layout simulation says it can run up to ~66 MHz. I added a "Stopped" output that can tell the Picaxe when acquisition is completed (i.e. both sensors have fired). Data is read by pulling the "Read" input high (which latches the data fron the counter into the shift register) and then shifting out the data, so that uses a total of 3 pins on the Picaxe.

Wolfgang
 

Attachments

Last edited:

JoePage2008x2

New Member
I think that i may consider doing something like this, they were wanting postage of 40USD to the UK, that chip is now out of the question, i havnt really tried to multiplex leds yet, so im going to have to learn - cant be too hard. Could you give me a sample bit of code to show me, i do have some idea.
 

cdngunner

Senior Member
So three years latter. Technology should have taken quite a jump. With the Picaxes running at 32 mhz now, would you be able to do this with just the picaxe?
 
Top