chronograph help

HAZELEB

Member
Hi all

A little help if possible I searched the forum for any thing to do with air gun chronograph and found this post by JoePage2008x2,
http://www.picaxeforum.co.uk/showthread.php?t=12263&highlight=chronograph

In post 14 Womai suggested a circuit and gave a schematic, which I have used with a 40x2, connecting every thing as he describes and with my wonderful skills of programming have managed to see a result,

I have wired the sensor connections to two switches the first switch gives a result of 000us and the second 2047900us depending on how quickly I can press the switches,

My questions are is my code in the right field and am I reading all the outputs correctly into the picaxe if not can someone put me right please also what setfreq should I be using to slow things down so the switch readings make more sense my code is below,

I would like to get this all working before I attempt to work out how I will get it to display on an LCD, any help will be gratefully received thanks in anticipation

Code:
#picaxe 40x2
#terminal 9600

symbol pwmoutput = C.1
symbol Dff_Clr_n = C.0`pull low then high
symbol Ctr_Clr   = C.2`pull high then low
symbol elapsedtime = w1
setfreq m8

Do
gosub configurepwmout
gosub configuredffclrn
gosub configurectrclr
gosub readinputs
gosub calculateanddisplayspeed
loop

configurepwmout:
	pwmout C.1, 199, 400
	return
	
configuredffclrn:
	low c.0
	pause 30
	high c.0
	pause 30
	return
	
configurectrclr:
	high c.2
	pause 30
	low c.2
	pause 30
	return
	
readinputs:
	 pulsin pinsD,1, elapsedtime
	 pulsin pinsB,1, elapsedtime
do
loop until pinD.0 = 1
	return

calculateanddisplayspeed:
	sertxd("elapsed time=",#elapsedtime,"00 us", CR,LF)
	return
 

Rickharris

Senior Member
Do you think the Picaxe will be fast enough to capture the signals? You should be looking at something in the range of 200 to 500 m/sec.

Wouldn't a video camera work better - You know the frame rate so comparing the distance travelled over 2 consecutive frames gives the speed.
 

HAZELEB

Member
Hi Rick.

The max speed for an air pistol pellet is 433ft/sec by law so the piaxe should be quit adequate according to the above-mentioned thread; this project is more for theory and to try and under stand the way the code works although I do have a air pistol and if I should get it to work will test it out.
 

papaof2

Senior Member
The max speed for an air pistol pellet is 433ft/sec by law
That depends on where you are; those rebellious former colonists in America have different standards for pellet pistols ;-)

Example:
http://www.crosman.com/airguns/pistols/1377C
Crosman 1377C
Power Source Pump
Caliber .177 pellet
Velocity Up to 600fps

I have one; it's excellent for controlling small varmints (up through squirrel size). This is a serious air-powered weapon - the barrel is engraved with a warning about its inherent danger.

The .22 caliber pellet pistols are even more powerful, being available up to at least 700 fps:
[ur]http://www.crosman.com/airguns/pistols/BP2220[/url]

The weapons for control of two-legged varmints are in the safe...

John
 

Dippy

Moderator
Blimey, I was under the impression it was to do with energy in those quaint old units of ft/lbs. i.e. 12 for a rifle and 6 for a pistol.
And therefore velocity/speed depends on the mass of the projectile. It must have changed since I were a lad.
http://www.airgunforum.co.uk/forums/view.php?pg=pelletvelocity

I made an airgun pellet velocity tester many years ago using IRLED+photo-D into a Tek 'scope (yup. old faithful TDS210 still going). Very good results.
Sadly, we then tried it with a 12 bore and blew the crap out of it. Lesson learnt. (Note: As we are not completely stupid the testing was done remotely in a bullet-proof enclosure and the signals brought outside - I do NOT recommend anyone copies this!!).
Apologies: I have digressed.
 
Last edited:

HAZELEB

Member
And there was I just hoping someone would set me right with my code reading the outputs and slowing things down.
 

hippy

Senior Member
I found it a bit hard to judge the code as I don't really understand how it's wired up, what hardware is being used, and how a pulse which signifies the bullet passing is created.

I don't understand why there are two PULSIN nor why you are using PWM then using PULSIN or what the purpose of configuredffclrn and configuredffclr is. It doesn't seem to match with what was described in the linked post.

In measuring a pulse with PULSIN, it will have a resolution of 10us at 4MHz; at 8MHz as used it will have a resolution of 5us. You'll need to adjust the pulse time read for display.

We really need a description of what you have, how it works, what signals are presented to the PICAXE and what the PICAXE controls to really comment on whether the code suits that or not.

Two issues with PULSIN are that the pulse it measures has to occur while it's executing before timeout and if 'pulling the trigger' under PICAXE control then executing PULSIN the bullet is likely to be 'well gone' before you even reach the PULSIN command.

This is why a gated counter / timer is best; you zero the counter, pull the trigger then see how many counts have been counted while the bullet passed between the sensors ( with a pulse while it does ) and from that determine the time and speed.
 

Janne

Senior Member
Dippy,

I'd be interested to hear more about your sensor setup... How were the photodiodes and IR-leds laid out in the machine. And how critical was the trajectory of the bullet through the sensors?
 

Dippy

Moderator
This is a big digression, so I'll keep it brief.

Here's a quick sketch. Lucky I have a ten year memory ;)

It was made of extruded aluminium stuff from the scrap bin rivetted together.
Distance between sensor-pairs was 100.0mm.
Mounting holes done on a CNC mill so pretty accurate.

IRLEDs output continuous at 50mA for duration of test.
Sensors were photo-diodes , cant remember make. Much , much faster than phototransistors.
There was a bit of ciruit to bias them but can't remember details - it would have been simple.

The alignment was pretty crucial.
However, even if the pellet only obscured half the 'beam' you could still see it OK on the 'scope screen - as it simply affected amplitude and trigger threshold.

(Jeez, isn't "recaptcha" anti-spam thing awful.
I had to type in two stupid long non-words. Some bloke is making a fortune with such rubbish. Clever devil. Have you heard the audio? Sounds like Donald Duck on the crapper.)

 

HAZELEB

Member
Hi Hippy
Thanks for you reply
I found it a bit hard to judge the code as I don't really understand how it's wired up, what hardware is being used, and how a pulse which signifies the bullet passing is created.
It ‘s wired up for the gated counter as described by Wolfgang in post 14 of that thread using the component he suggested, the pulses which signifies the bullet are two switches
I don't understand why there are two pulsin nor why you are using PWM then using pulsin or what the purpose of configuredffclrn and configuredffclr is. It doesn't seem to match with what was described in the linked post.
The pwm determines the count frequency configuredffclrn and configuredffclr this resets the counter output to zero so the counter is armed, portb and portd are connected to the counter outputs, this was the question I asked I used pulsin in my ignorance as I hadn’t a clue how to read the outputs, my other question was as I’m using switches to simulate the bullet passing the gates how do I slow things down.

This is why a gated counter / timer is best; you zero the counter, pull the trigger then see how many counts have been counted while the bullet passed between the sensors ( with a pulse while it does ) and from that determine the time and speed.
This is the bit I can’t understand how to read the counter in to the picaxe.
 

hippy

Senior Member
Okay I understand. A circuit diagram of what you have will probably help but it is clearer now.

To slow things down in testing the easiest thing would be to slow the PWM down, reduce its frequency. Therefore there will be few count pulses during a real-world time period.
 

womai

Senior Member
Select "Reply". On top of the Rich edit window press on the paper clip symbol, that will open up a small popup window which lets you browse for the file you want to upload (maybe you need to allow popups for the forum site to make this work). Select the file, press "Upload", once that has finished scroll to the bottom of the popup page and select "Close this window". Note that only certain file types are allowed and there are size restrictions for each type (jpg is fine up to ~1MB; there is a list showing the allowed types and the size limits).

Wolfgang

PS: Great to see my little counter circuit is useful to someone!
 

HAZELEB

Member
Ok the circuit shows how it’s all connected on my test board there are caps connected to the power supplies of all the 74CH Ics and the unused pins of the XOR1 andAND1 ics are tied low.

@Wolfgang
Than you for your help with the image upload and the circuit.
 

Attachments

womai

Senior Member
One mistake I can see, the Q3 output of U4.A (first half of second counter chip) is not routed to the Picaxe.

Wolfgang
 

HAZELEB

Member
Well-spotted sir in my hast to draw the circuit then the hassle I had trying to upload I mist that one but the connection is made in my hardware, the circuit works fine my problem is trying to understand how to read the outputs in to the picaxe with my code.
 

hippy

Senior Member
Ecellent thanks. It should just be a case of reading the two ports B.x as LSB, D.x as MSB. You don't even need to use dirsB=$00 or dirsD=$00 as they will be inputs at reset -

wordVar = pinsD << 8 | pinsB
SerTxd( "Counter is ", #wordVar, CR, LF )
 

Janne

Senior Member
Dippy,

Thanks for the picture and explanation. It looks like for that to work, the bullet needs to fly straight through the gates, so the need for a (wooden) rest seems mandatory in that design. Though this arrangement would provide a working machine with the simplest possible hardware.

That nuts and volts article also looks interesting, very professional device in there.

Looks like another great project for the winter :)
 

HAZELEB

Member
Hi all,

A little more help please,

I’ve have my chronograph working with freq set to m8 displaying the microseconds between the sensors and the pellet speed in ft/sec on an LCD by running a card through the sensors,

However when I change the freq to em40 and the pwmout to 4mhz and fire a pellet through the sensors I just get a load of rubbish displaying, I have a 10mhz resonator attached to the 40x2, have read the setfreq in the manuals but not sure if I’m doing things right.

Code is below and a picture of my setup.
Code:
#picaxe 40x2
#terminal 9600

symbol pwmoutput = C.1
symbol Dff_Clr_n = C.0		`pull low then high
symbol Ctr_Clr   = C.2		`pull high then low
symbol elapsedtime = w1
setfreq m8

main:

configurepwmout:			`pwmout sets the counter freq
	pwmout C.1,99,200	
	
	
configuredffclrn:
	low c.0
	pause 50
	high c.0
	pause 50
	`
	
configurectrclr:			`configuredffclrn and ctrclr resets the counter to zero
	high c.2
	pause 50
	low c.2
	pause 50
	
readinputs:				`do loop waits for the first sensor to triger
	do
	loop until pinc.3 = 1
	 elapsedtime = pinsD << 8 | pinsB		`pinsD & B reads pulses into word elapsedtime
	 
	 do
	 loop until pinc.4 = 1	`do loop waits for the second sensor to triger

	 
do_sum:				`do_sum calculates the counter result into ft/sec
	w0 = 62500
	w2 = w1 * 2
	w3 = w0 / w1
	w4 = w3 * 16
	
pause 500
	serout c.7,n2400,(254,1)
	serout C.7,N2400,(254,128)
	serout C.7,N2400,("Pellet Volosity")		`sends result to LCD
	serout c.7,n2400,(254,192)
	serout c.7,n2400,(#w1,"us ",  #w4,"ft/s")	

calculateanddisplayspeed:
	SerTxd( "Counter is ", #w1,"00 us", CR, LF )		`display's elapsedtime in terminal window
	pause 1000	
	goto main
 

Attachments

womai

Senior Member
My guess is you did not adjust the serial output rate to the LCD? When you go from 8 MHz to 40 MHz then N2400 results in an actual data rate of 12000 baud (2400*40/8). The easiest solution would be to issue a setfreq m8 just before the output to the LCD screen, and then a setfreq em40 right after the LCD output is complete.

Wolfgang

PS: There's a spelling mistake in your printout - it's "velocity", not "volosity".
 

HAZELEB

Member
Thank you for the fast reply and you were spot on and I am so chuffed to have got this working,

And I apologise for my poor spelling,

again many thanks,

Ted.
 

Attachments

womai

Senior Member
If you feel you want to share your achievement - complete circuit diagram, component list (especially for the sensors), Picaxe program listing, and a few pictures will make this a great project to show off into the "Finished user projects" section. Even more because there have already been a few threads by people wanting to do similar things (time air pistol pellets and the like) - that way it will be easy to just point them to a proven, working design.

Wolfgang
 

HAZELEB

Member
Ok a little more help please, I have the chronograph working quit consistently reading around 308 ft/sec, I’ve had the gun checked with a commercial chronograph and that came back at 382 ft/sec so not to far out I know pellet weight will make a difference,

Just a check that I’m doing my sums right I’m using an external 10mhz resonator and have it set to em40 and the pmw set to 5mhz, which I believe, should read 0.2usec intervals,

w0 = 62500 `1 second is divided by 16 giving 62500 to fit a word variable
w2 = w1 * 10 `the sensor reading is * by 10
w3 = w0 / w2 `62500 is divided by the new sensor reading
w4 = w3 * 16 `and the answer is * by 16

Am I doing this right please?

Ted.
 

hippy

Senior Member
In your code in Post #3 you have, for 'readinputs' ...

Wait for first trigger
Read elapsed time
Wait for second trigger

Shouldn't you be reading the elapsed time after the second trigger, the elapsed time until the bullet has passed through the second gate ?

On the conversion algorithm; it's impossible to say without knowing how far apart the two gates are, how far was travelled in the the time returned. That may be elsewhere in the thread but best to restate it.
 

HAZELEB

Member
Sorry Hippy I had updated my code to reflect reading after the 2nd sensor had triggered,

Code:
#picaxe 40x2
#terminal 9600

symbol pwmoutput = C.1
symbol Dff_Clr_n = C.0		`pull low then high
symbol Ctr_Clr   = C.2		`pull high then low
symbol counter_1 = w0		`holds 1 16th of 1 second
symbol counter_2 = w2		`
symbol microseconds = w1
pause 500
serout c.7,n2400,(254,1)
serout c.7,n2400,(254,128)
serout c.7,n2400,("chronograph v1.0")
serout c.7,n2400,(254,192)
serout c.7,n2400,("  By  Hazeleb   ")
pause 2000
serout c.7,n2400,(254,1)
serout c.7,n2400,(254,128)
serout c.7,n2400,("Pellet  Velosciy")
serout c.7,n2400,(254,192)
serout c.7,n2400,(" feet/second")
setfreq em40

main:

configurepwmout:			`pwmout sets the counter freq
	pwmout C.1,1,4	
	
	
configuredffclrn:
	low c.0
	pause 100
	high c.0
	pause 100
	`
	
configurectrclr:			`configuredffclrn and ctrclr resets the counter to zero
	high c.2
	pause 100
	low c.2
	pause 100
	
readinputs:			
	do
	loop until pinc.3 = 1			`do loop waits for the first sensor to triger
	
	do
	 loop until pinc.4 = 1		`do loop waits for the second sensor to triger
	 
	 
	 microseconds = pinsD << 8 | pinsB		`pinsD & B reads pulses into word elapsedtime
	 
	 	

	 
do_sum:				`do_sum calculates the counter result into ft/sec
	w0 = 62500			`devide one second by 16
	w2 = w1 * 10 	   		`multiply the pellet speed 
	w3 = w0 / w2			`divide the one second division by the pellet speed
	w4 = w3 * 16		`multiply by 16 to give ft/sec 
	
pause 1000
	setfreq m8			`setfreq to read to lcd
	serout c.7,n2400,(254,1)
	serout C.7,N2400,(254,128)
	serout C.7,N2400,("Pellet Velocity")		`sends result to LCD
	serout c.7,n2400,(254,193)
	serout c.7,n2400,(  #w4," feet/second")
	
	

calculateanddisplayspeed:
	SerTxd( "Counter is ", #w2," us", CR, LF )		`display's elapsedtime in terminal window
	pause 1000
	setfreq em40		`reset freq to em40	
	goto main
 

hippy

Senior Member
Thanks, so we have a reading, each unit of 'microseconds' ( very bad choice of variable naming there ) represents 0.2us of elapsed time ... so how far apart are the two sensors ?
 

HAZELEB

Member
Thanks Wolfgang I will have a read; I was hoping Hippy would come back with the answer to my question.

Ted.
 

hippy

Senior Member
Sorry Ted, I missed the updated post. As I see it ...

s = d / t

with d in feet, t in seconds

s = 0.5 / n * 2E-7

where n is the count of 0.2us units and sensors 6 inch apart

s = 2500000 / n

s = (2500000/39) / ( n/39)

s ~= 64103 / (n/39)

So for a bullet which travels at say 250 feet per second, that's 500 half-feet per second, time to travel one half-feet is 1/500 seconds, 2ms, n = 10000 units of 0.2us.

s = 64103 / (n/39)

s = 64103 / ( 10000/39 )

s = 64103 / ~256

s = 250

Bingo!
 

hippy

Senior Member
And why divide by 39 ? That's because M/K must be less than or equal to 65535 to make PICAXE 16-bit maths work easily, and M=2500000, K=39 as the largest K which fits that.

Ideally, not having any rounding error in the top M/K with smallest value of K, is what's best to aim for. so adjust the actual distance between sensors to give such a situation.
 
Last edited:

HAZELEB

Member
Thanks Hippy I’m challenged in lots of way needles to say that I am most grateful for your help with this calculation.

Ted.
 

hippy

Senior Member
You're welcome and I can now see where your 62500 came from ... divide by 40 ....

s = (2500000/40) / ( n/40)

s = 62500 / (n/40)

So, yes, leave at 6 inches and use divide by 40!

You cannot get the resolution up to one decimal place as that means multiply the top by 10 (overflow) or dividing the bottom by 10 which will actually lose resolution. Unless I'm missing some trick.

You can do some rounding though ...

n = <reading>
s = n % 40 / 20 + n
s = s / 40
s = 62500 / s

Added: That trick may be to subtract or add something from or to 'n' and then later adjust 's'.
 
Last edited:
Top