Troubleshooting Advice Needed - Electronic Dart Scorer

MCsleeman

New Member
Hi,

I have designed and made an electronic dart scorer which keeps track of two players' scores from 501 to 0 and indicates how many throws a player has left in their turn using three PICAXE-40X2 microcontrollers. Two of them are used to control multiplexed 7-segment displays and work fine. The third is used to respond to the input which is from a matrixed 3x4 keypad and a push button "enter" switch, carry out all the relevant calculations and output information regarding which player's turn it is, how many throws they have left and what their current score is. If an invalid score is entered, it will light up an indicator LED for a short time. However, this PICAXE is not working at all reliably. Sometimes the displays are adjusted correctly but sometimes the score changes by the wrong amount and more often, the indicator LED lights up when it shouldn't.

I have tried changing the breadboard and swapping the PICAXE for a new one. I have written an alternative programme so that it takes the input from an array of twelve (non-matrixed) push buttons. None of this has made a difference. I have contacted PICAXE to check whether this could be down to a limitation of the chip, which it isn't. The programme works perfectly on the PICAXE Programming Editor simulation and I am somewhat stumped.

I have attached the full code for the PICAXE that isn't working along with a typed synopsis. If anyone has any ideas that could help, I would be most grateful.

Many thanks

View attachment Input Programme.basView attachment Input Code Synopsis.doc
 

Goeytex

Senior Member
Hi and Welcome,

Troubleshooting these kinds of problems can be a challenge.

Unfortunately, you have not provided any kind of schematic diagram that might help us help you. The code is completely un-commented and the code uses no symbols whatsoever. This makes it very difficult for folks to help you.

For example, without a schematic and or symbols /code comments how can anyone know, for example, where the the LED indicator is connected?

May I kindly suggest that you go back and comment the code and use symbols where relevant. If you have a schematic please post it, If you do not have a schematic, then take the time to draw one up. A synopsis is good, but it is no substitute for well commented code.

My guess is it is might be a hardware related problem, but without an accurate schematic and /or a clear close up photo a guess is the best anyone can do.

We do not know what kind of power supply you are using. We do not know if you have bypass or bulk capacitors correctly placed, and so on.
 

hippy

Technical Support
Staff member
Sometimes the displays are adjusted correctly but sometimes the score changes by the wrong amount and more often, the indicator LED lights up when it shouldn't.
Is there any pattern to how the score changes by the wrong amount ? This may give some clue as to what is happening.

I suspect the problem may be that the pin A.0 'update score' interrupt may be being entered with the main program left somewhere unknown inside the keypad scanning routine and thus once the score is updated the next number isn't necessarily stored correctly.

There should be no actual need to use an interrupt to handle the 'update score' button.

The code is quite monolithic and becomes difficult to follow and it could well benefit from being restructured to use subroutines.
 

BESQUEUT

Senior Member
Code:
displaychange:	let w6 = w5/100
		if w6 = $0005 then gosub digitone5
		if w6 = $0004 then gosub digitone4
		if w6 = $0003 then gosub digitone3
		if w6 = $0002 then gosub digitone2
		if w6 = $0001 then gosub digitone1
		if w6 = $0000 then gosub digitone0

		let w6 = w6*100
		let w7 = w5-w6
		let w7 = w7/10
		if w7 = $0009 then gosub digittwo9
		if w7 = $0008 then gosub digittwo8
		if w7 = $0007 then gosub digittwo7
		if w7 = $0006 then gosub digittwo6
		if w7 = $0005 then gosub digittwo5
		if w7 = $0004 then gosub digittwo4
		if w7 = $0003 then gosub digittwo3
		if w7 = $0002 then gosub digittwo2
		if w7 = $0001 then gosub digittwo1
		if w7 = $0000 then gosub digittwo0

		let w7 = w7*10
		let w8 = w5-w6-w7
		if w8 = $0009 then gosub digitthree9
		if w8 = $0008 then gosub digitthree8
		if w8 = $0007 then gosub digitthree7
		if w8 = $0006 then gosub digitthree6
		if w8 = $0005 then gosub digitthree5
		if w8 = $0004 then gosub digitthree4
		if w8 = $0003 then gosub digitthree3
		if w8 = $0002 then gosub digitthree2
		if w8 = $0001 then gosub digitthree1
		if w8 = $0000 then gosub digitthree0
can be updated by something like :
Code:
displaychange:	
                BinToASCII w5,b14,b13,b12
                b12=b12-48
                b13=b13-48
                b14=b14-48
                on b12 gosub digitone0,digitone1,digitone2,digitone3,digitone4,digitone5
                on b13 gosub digittwo0,digittwo1,digittwo2,digittwo3,digittwo4,digittwo5,digittwo6,digittwo7,digittwo8,digittwo9
                on b14 gosub digitthree0,digitthree1,digitthree2,digitthree3,digitthree4,digitthree5,digitthree6,digitthree7,digitthree8,digitthree9
Same thing for DisplayChange2

There should be no actual need to use an interrupt to handle the 'update score' button.
Interrupt is the big problem !

Never do anything in the Interrupt routine but set a flag !

Suppose you are in the ReadFirst routine, just after
high C.3

And now : Interrupt ==> low C.3
... some LED update...
and go back to ReadFirst...
if pinA.5 = 1 then goto keyone1
 
Last edited:

SAborn

Senior Member
The use of some symbols for the variables would help with understanding the code, as spagetti code do my head in, and i give up on trying to help.

You look to use W3 a lot as a working variable and i can not tell if it is intended to carry the previous w3 value forward in the code in all cases, if not then you might need to add some w3=0 once you have finished using it and before you reuse it elsewhere.

also in this bracket of code

awaitenter: if b1 = 1 then goto readfirst
low C.0, C.1, C.2, C.3
goto awaitenter
what changes "b1" otherwise it just gets stuck in an endless loop of "goto awaitenter'
 

BESQUEUT

Senior Member
what changes "b1" otherwise it just gets stuck in an endless loop of "goto awaitenter'
The answer is : Interrupt
with a gosub to
errorled:
update1:
update2:
They all have the command :
let b1 = 1

and then : goto readfirst

The problem is that the key may be switching few times... and Interrupt fired anywhere...
 

MCsleeman

New Member
Thanks everyone for your suggestions. I have had a go at rewriting the code in a more compact way and without the interrupt but I'm still having the same difficulty as before: it works perfectly on the simulation but not on the breadboard. This time I have tried to annotate the code as fully as possible and have also attached a schematic diagram to help.

Dart Scorer Schematic.jpgView attachment Input Programme2.bas
 

Goeytex

Senior Member
One big problem is the LED circuit.

There needs to be a series resistor between the transistor collector and the LED. This can be from 330 ohms to 2.2K ohms. There also needs to be a series resistor from the Picxaxe I/O pin and the base of the transistor. A 4.7K or 10K resistor should work fine.

With no current limiting here, the Picaxe can behave erratically, and could even blow the I/O circuit or the Picaxe itself.
 

SAborn

Senior Member
I had a quick look at the code and its much better to follow with symbols.

One thought that may cause problems is switch bounce, and at 32 meg the program might loop back faster than you expect, and record several switch presses due to switch bounce.

Try adding some pause 500 to each key

key0:

if keypad_column2 = 1 then goto key0
let entered_score = entered_score * 10 + 0 max 255
Pause 500
return

This will allow time for the switch bounce to be gone before the program returns.

Its only a guess, but as you quote it works in the simulator (that has no switch bounce) but not in the real circuit, could imply its a mechanical fault and not a code fault.
 

BESQUEUT

Senior Member
One thought that may cause problems is switch bounce,
I agree
..., could imply its a mechanical fault and not a code fault.
Mechanical is what it is...
To my mind, a program that do not deal with swtch bounce is a faulty program...
Never mind : pauses(s) will help... but not soluce problem in any cases.

For example : you can have bounces when the key is pressed down,
but also when it is released...

An idea may be to count loops in the "wait for key to be released"
 
Last edited:
Top