control a stopwatch via a picaxe

crazynight

Senior Member
Well my timing system had its first outing today and things did not go well seems to be an issue displaying a time below 1/2 a second.

I am looking at options and I think the easiest might be to just use stopwatches rather than the picaxe and a RTC.

My question is how can you control a stopwatch from a picaxe. its only 3 buttons so should be straight forward.

Would I use a ULN2003A to interface between the picaxe and the stopwatch? suggestions welcomed.

Thanks in advance.
 

Rick100

Senior Member
My question is how can you control a stopwatch from a picaxe. its only 3 buttons so should be straight forward.

Would I use a ULN2003A to interface between the picaxe and the stopwatch? suggestions welcomed.

Thanks in advance.
You might look into the 4066 quad bilateral switch. Here is a link about using it to press buttons.
http://little-scale.blogspot.com/2013/05/circuit-bending-basics-3-emulating.html

You could also describe your project in more detail and maybe it could be done without the stopwatch.

Good luck,
Rick
 
Last edited:

SAborn

Senior Member
I have used the cheap digital kitchen timers for this exact purpose, 90% of them have the push buttons to Gnd, so a simple npn transistor across the button has always worked for me with Picaxe control.

I often use one for testing timing loops in a picaxe program, picaxe starts timer, then goes into timing loop, then stops timer, presto ..you have the time recorded.
Chancing picaxe clock speeds can really mess with timing loops, so its a easy way to check and adjust as required.
 

crazynight

Senior Member
Thanks guys will wait for the stopwatches to arrive and then crack them open, in the mean time will review my code; might a simple error so frustrating as the system worked well but just never displayed a time less than 1/2 second which meant there where too many 00.00 starts; they might be a good team but not that god :eek:
 

flyingnunrt

Senior Member
@crazynight
A couple of shots of our new flyball box & timer unit during construction.
Box just needed rubber padding and triggers adjusting.
DSC00565.JPGIMG_2845.JPG
 

MikeM100

Member
Don't forget that the saturation voltage of a ULN2003 Darlington driver is quite high due to the compound transistor . (See Wikipedia)

You may be better off just using a simple NPN transistor with, say a 4k7 base resistor.

Stopwatch devices often use just a single silver oxide cell so are only operating at 1.5V
 

crazynight

Senior Member
@Rick100

this is my original project thread http://www.picaxeforum.co.uk/showthread.php?24348-1st-Project-amp-post-so-please-be-gentle

Basically timing two lanes of dogs running up a track and back monitoring to make sure they are not false starting and that the change overs are not too early.

I have just looked at http://www.picaxeforum.co.uk/showthread.php?14517-High-Accuracy-Timer but will need 2 20x2 and 2 lcd screens. Having looked through my code I believe my issue might be coming from the fact I am running several processes thereby reducing the speed of the picaxe, if I out source the timing it should reduce the code by 50% as all the i2c communication will not be needed (reading the RTC and updating the clock) I have discovered one of the other systems is built on VIOM controller not sure if that helps mind.
 

erco

Senior Member
How long an interval are you timing? Up to several minutes, you can forego a clock/RTC and just use a hand-calibrated PicAxe program with a few nested loops for better accuracy than a half second.
 

crazynight

Senior Member
things are looking up turns out I have two of these http://www.quasarelectronics.co.uk/kit-files/electronic-kit/3148t2.pdf in the old system I am trying to upgrade, not sure how I can safely interface with the picaxe, the voltage for the board is 9-12v with a 9v battery the contacts for the start/stop/reset read 5v and with a 12v battery they also read 5v.

On there suppliers website it just says "Start / Stop / Reset (Active low - see documentation)"

http://www.circuitspecialists.com/pdf/k148.pdf this is also the same product but with a full schematic

Any advice would be much appreciated.
 
Last edited:

vttom

Senior Member
Having looked through my code I believe my issue might be coming from the fact I am running several processes thereby reducing the speed of the picaxe, if I out source the timing it should reduce the code by 50% as all the i2c communication will not be needed (reading the RTC and updating the clock) I have discovered one of the other systems is built on VIOM controller not sure if that helps mind.
Perhaps if you shared your code with the forum we could look it over and help you to optimize it. Seems to me that would beat the effort required to re-do the project with stand-alone stopwatches.
 

crazynight

Senior Member
Perhaps if you shared your code with the forum we could look it over and help you to optimize it. Seems to me that would beat the effort required to re-do the project with stand-alone stopwatches.
this is my code not exactly clean was not expecting to share it just yet!! there are a few comments in which should explain whats going on to a degree.

I believe the issue is redstartfault: and writered: are just not happening quick enough by the time the picaxe has done the read the reset is happening. so getting a 00:00 time

Code:
#picaxe 20m2
start0: ;this task sets everything up ready and flashes an LED while waiting for the start button
suspend 3

;symbol ADCPIN = 4
symbol slvAddrWR = $A0  ' I2C write address
symbol slvAddrRD = $A1	' I2C Read address
symbol ADCPIN = 4
symbol REDDISPLAY = 0x62 ;RED 4 DIGIT 7 SEG DISPLAY
SYMBOL bluedisplay = 0x64 ;BLUE 4 DIGIT 7 SEG DISPLAY
symbol CLEARDISPLAY = 2	;2 = THE COMMAND TO CLEAR THE SCREEN
symbol NUMTODIGIT = 4	;4 = THE COMMAND TO WRITE TO THE LCD
symbol DECIMALPOINT = 5	;DECIMAL VERIABLE
symbol Y1 = C.0	;FIRST YELLOW LIGHT
SYMBOL Y2 = C.3	;SECOND YELLOW  LIGHT
SYMBOL Y3 = C.2	;3RD YELLOW LIGHT
SYMBOL G1 = c.4	;GREEN LIGHT
SYMBOL R1 = C.4	;BLUE START FAULT LIGHT
SYMBOL R2 = C.1	;RED START FAULT LIGHT
SYMBOL R3 = C.4	;BLUE PASS FAULT LIGHT CURRENTLY THE SAME AS THE START FAULT BUT REFERENCED SEPORATLY FOR FUTURE
SYMBOL R4 = C.1	;RED PASS FAULT LIGHT CURRENTLY THE SAME AS THE START FAULT BUT REFERENCED SEPORATLY FOR FUTURE
SYMBOL REDPASS = B.2	;RED START SENSOR
SYMBOL REDSTART = B.3	;RED PASS SENSOR
SYMBOL BLUESTART = B.4	;BLUE START SENSOR
SYMBOL BLUEPASS = B.6	;BLUE PASS SENSOR
SYMBOL READYLED = C.7	;READY LED 
SYMBOL RESETBUTTON = C.5
symbol start_sw = pinb.1 ; define a input switch
symbol red_sec = 0
symbol blue_sec = 0
symbol timeincentiseconds =  w3
symbol timeearly = w4      ; need Word if > 255 centi-secs
symbol fault = w10
symbol pass_red = w11
symbol pass_blue = w12
symbol start_ed = w13

PAUSE 200

  	i2cslave slvAddrWR, i2cslow, i2cbyte		'Initialize RTC
  	
  	writei2c 0,(%00000100)					;timer function to 99 seconds
									;to enable %xx0xx1xx
  	writei2c 8,(%00000100)					; alarm control registers and clock mode
									;bit7 	enable alarm interrupt
									;bit6		timer alarm
									;bit5/4	clock alarm 00= no clock alarm
									;bit3		timer interrupt enable
									;bit2/1/0  	timer function  001= hundredths of a second							
	pause 500
						
	writei2c 2,(%00000000)					;reset minutes
	
	writei2c 1,(%00000000)					;reset seconds
	
	writei2c 3,(%00000000)					;reset milliseconds												

	HI2CSETUP I2CMASTER, blueDISPLAY, i2cfast, i2cbyte   ; Initiaize BLUE 4x7 segment display

pause 200

hi2cout (NUMTODIGIT, 0, 0) ;set 1st digit to 0
hi2cout (NUMTODIGIT, 1, 0) ;set 2nd digit to 0
hi2cout (NUMTODIGIT, 2, 0) ;set 3rd digit to 0
hi2cout (NUMTODIGIT, 3, 0) ;set 4th digit to 0
hi2cout (DECIMALPOINT, 1, 1)

	HI2CSETUP I2CMASTER, redDISPLAY, i2cfast, i2cbyte	; Initiaize RED 4x7 segment display
	
pause 200

hi2cout (NUMTODIGIT, 0, 0) ;set 1st digit to 0
hi2cout (NUMTODIGIT, 1, 0) ;set 2nd digit to 0
hi2cout (NUMTODIGIT, 2, 0) ;set 3rd digit to 0
hi2cout (NUMTODIGIT, 3, 0) ;set 4th digit to 0
hi2cout (DECIMALPOINT, 1, 1)

;TURN ALL START LIGHTS OFF
low Y1
low Y2
low Y3
low G1
low R1
low R2
low R3
low R4
suspend 2
suspend 4
suspend 6
suspend 7

;monitors the rest switch if pressed on boot it does a little test
IF PINC.5=1 THEN gosub test
resume 3

FLASHLED:   ; FLASH READY LED
high READYLED ;turn the ready LED on

waitforpress:;monitors the start button and runs sequence when pressed

if start_sw = 1 then startlights ;jump when start switch is pressed
goto waitforpress ;else loop back around waiting for the start button to be pressed

STARTLIGHTS:
restart 2
RESTART 6
low READYLED 	;TURNS READY LED OFF TO BE SAFE AS IT MIGHT BE IN THE ON STATE WHEN THE START SWITCH IS PRESSED.
;reser the RTC to Zero
	i2cslave slvAddrWR, i2cslow, i2cbyte		;Initialize RTC
	writei2c 2,(%00000000)					;reset minutes
	writei2c 1,(%00000000)					;reset seconds
	writei2c 3,(%00000000)					;reset milliseconds
pause 1000		;wait 1 second
high Y1		;1stamber on
pause 1000		;wait 1 second
low Y1		;1st	amber off
high Y2		;2nd amber on
pause 1000		;wait 1 second
low Y2		;2nd amber of
high Y3		;3rd amber on
pause 1000		;wait 1 second
low Y3		;3rd amber off
high G1		;green on
suspend 2	;suspend task2 red start fault monitor as no longer needed
SUSPEND 6
	i2cslave slvAddrWR, i2cslow, i2cbyte		;Initialize RTC
	writei2c 2,(%00000000)					;reset minutes
	writei2c 1,(%00000000)					;reset seconds
	writei2c 3,(%00000000)					;reset milliseconds
pause 500   ;wait 0.5 second
low G1	;turn green light off
if fault  > 0 then goSUB FLASHGREEN ; if there has been a fault during the start this jumps and flashes green
restart 4
restart 7
pause 2000 ; give 2 seconds before monitoring for early releases
;restart 6

hehre:   ;puts fault ligt on if red pass sensor has not been activated
if pass_red = 0 AND pinb.3 = 1 THEN
high R2
PAUSE 2000
low r2
ENDIF
goto hehre

start2:	;this task monitors for red start faults
IF PinB.3 = 1 then gosub redstartfault
GOTO START2

start3:  ;monitor for reset button
if PINC.5 = 1 THEN reset
endif
goto start3

start4:	;this task writes the time to the red display 
if pinB.3 = 1 then gosub writered ;jump if the input is on red start
goto START4 ;else loop back around

start6: ;puts fault ligt on if red pass sensor has not been activated
IF PINB.4 = 1 THEN GOSUB bluestartfault
GOTO START6


;if pass_red = 0 AND pinb.3 = 1 THEN
;high R2
;high y2
;PAUSE 2000
;low r2
;low y2
;ENDIF

start7: 
if pinb.2 = 1 then 
pass_red = 1
pause 2000
pass_red = 0
end if
goto start7




;##############ALL GOSUBS BELOW HERE #########################

;START6:	;monitors the rest switch and resets the picaxe if pressed.
;IF PINC.5=1 THEN RESET
;ENDIF
;GOTO START6

redstartfault:
HIGH R2 ;TURN ON RED START FAULT LIGHT
fault = 1
i2cslave slvAddrWR, i2cslow, i2cbyte
  	readi2c $0, (b1,b2,b3,b4,b5) ;get time from the RTC
  			;b1=control/status
  			;b2=hundredths
  			;b3=seconds
  			;b4=minutes
  			;b5=hours

b22 = b2
;b3 = 2			; Test value 2.53 seconds
;symbol timeincentiseconds =  w3
;symbol timeearly = w4      ; need Word if > 255 centi-secs
b10 = b22 / 16
b11 = b22 // 16
b12 = b3 / 16
b13 = b3 // 16
timeincentiseconds = b13 * 10 + b10 * 10 + b11
timeearly = 400 - timeincentiseconds
b1 = timeearly / 100		; Seconds
b0 = timeearly // 100	; Centi-seconds
;sertxd(#b1,".",#b0)		; Beware missing zero if b0 < 10
b3 = b0 / 10
b0 = b0 // 10

  	HI2CSETUP I2CMASTER, redDISPLAY, i2cfast, i2cbyte
	hi2cout (NUMTODIGIT, 0, 16) ;set 1st digit to 0
	
	hi2cout (NUMTODIGIT, 1, b1) ;set 2nd digit to 0
	hi2cout (NUMTODIGIT, 2, b3) ;set 3rd digit to 0
	hi2cout (NUMTODIGIT, 3, b0) ;set 4th digit to 0
hi2cout (DECIMALPOINT, 1, 1)
suspend 2
return

nosec:
;b3 = 0 ; set seconds to 0
b21 = 0
return

bluestartfault:
fault = 1
RETURN

bluepassfault:
HIGH R1 ;jump if the input is on
pause 2000
low r1
return

redpassfault:
HIGH R2 ;jump if the input is on
pause 2000
low r2
return

	
  	writered:
  	
  	i2cslave slvAddrWR, i2cslow, i2cbyte

  	readi2c $0, (b1,b2,b3,b4,b5)
  	BCDTOASCII b2,b10,b11
  	b10 =b10 - $30
  	b11 = b11 - $30
  	
	BCDTOASCII b3,b12,b13
	b12 =b12 - $30
  	b13 = b13 - $30
	
	
	HI2CSETUP I2CMASTER, redDISPLAY, i2cfast, i2cbyte
	hi2cout (NUMTODIGIT, 0, b12) ;set 1st digit to 0
	hi2cout (NUMTODIGIT, 1, b13) ;set 2nd digit to 0
	hi2cout (NUMTODIGIT, 2, b10) ;set 3rd digit to 0
	hi2cout (NUMTODIGIT, 3, b11) ;set 4th digit to 0
	if pinB.6 = 0 THEN
	GOTO ENDNOW
	ENDIF
	pause 2000
	return
	
	
	writeblue:
  	i2cslave slvAddrWR, i2cslow, i2cbyte
  	readi2c $0, (b1,b2,b3,b4,b5)
  	BCDTOASCII b2,b10,b11
  	b10 =b10 - $30
  	b11 = b11 - $30
  	
	BCDTOASCII b3,b12,b13
	b12 =b12 - $30
  	b13 = b13 - $30
	HI2CSETUP I2CMASTER, blueDISPLAY, i2cfast, i2cbyte
	hi2cout (NUMTODIGIT, 0, b12) ;set 1st digit to 0
	hi2cout (NUMTODIGIT, 1, b13) ;set 2nd digit to 0
	hi2cout (NUMTODIGIT, 2, b10) ;set 3rd digit to 0
	hi2cout (NUMTODIGIT, 3, b11) ;set 4th digit to 0
	pause 2000
	return
	
FLASHGREEN:
;DO
;LOW G1
;PAUSE 500
;HIGH G1
;PAUSE 500
;LOW G1
;LOOP
PAUSE 2000
LOW R2
RETURN 

test:
suspend 3
LET B2=1
DO
HIGH Y1
HIGH Y2
HIGH Y3
HIGH G1
HIGH R1
HIGH R2
HIGH R3
HIGH R4
HIGH READYLED
PAUSE 1000
LOW Y1
LOW Y2
LOW Y3
LOW G1
LOW R1
LOW R2
LOW R3
LOW R4
LOW READYLED
PAUSE 1000
inc b2
loop while b2 <5

RETURN

ENDNOW: ;THIS IS A FAILSAFE LOCATION ADDED TO THE END OF EVERY TASK 
SUSPEND 0
SUSPEND 2
SUSPEND 3
SUSPEND 6
SUSPEND 7

OPS:  ;monitor for reset button
if PINC.5 = 1 THEN reset
endif
goto OPS
 

vttom

Senior Member
I see you have quite a few tight loops which are simply polling pins:

Code:
start2:	;this task monitors for red start faults
IF PinB.3 = 1 then gosub redstartfault
GOTO START2

start3:  ;monitor for reset button
if PINC.5 = 1 THEN reset
endif
goto start3

start4:	;this task writes the time to the red display 
if pinB.3 = 1 then gosub writered ;jump if the input is on red start
goto START4 ;else loop back around

start6: ;puts fault ligt on if red pass sensor has not been activated
IF PINB.4 = 1 THEN GOSUB bluestartfault
GOTO START6

<snip>

OPS:  ;monitor for reset button
if PINC.5 = 1 THEN reset
endif
goto OPS
Seems to me these could be implemented as interrupts, which I would think would be a lot more efficient for the PICAXE to implement than what you have.
 

crazynight

Senior Member
I see you have quite a few tight loops which are simply polling pins:

Code:
start2:	;this task monitors for red start faults
IF PinB.3 = 1 then gosub redstartfault
GOTO START2

start3:  ;monitor for reset button
if PINC.5 = 1 THEN reset
endif
goto start3

start4:	;this task writes the time to the red display 
if pinB.3 = 1 then gosub writered ;jump if the input is on red start
goto START4 ;else loop back around

start6: ;puts fault ligt on if red pass sensor has not been activated
IF PINB.4 = 1 THEN GOSUB bluestartfault
GOTO START6

<snip>

OPS:  ;monitor for reset button
if PINC.5 = 1 THEN reset
endif
goto OPS
Seems to me these could be implemented as interrupts, which I would think would be a lot more efficient for the PICAXE to implement than what you have.
I tried interrupts at the beginning and they stopped the rest of the code from running and you could not return to that point. the interrupt needs to happen several times during the race.
 

oracacle

Senior Member
why dont you use some opto isolator to keep the circiuts sperate. a simple pulsout of the picaxe pin would be equal to a button press, some careful soldering of some fly leads from the stop watch.

and yes providing you have a comon ground it really is that simple, however comon ground is not needed for opto or the 4066 suggested earlier
 

vttom

Senior Member
I tried interrupts at the beginning and they stopped the rest of the code from running and you could not return to that point. the interrupt needs to happen several times during the race.
Interrupts work like a "gosub". Put a "return" as the last command in the interrupt subroutine and execution returns to wherever it was before the interrupt happened.
 
Top