Bug in software, please input :)

Basrad

Member
Hi all,

I've made a little stepper motor controller, to turn a stepper 1 way with button A, and the other with button B...

I also have included a battery tester so i can check my 12v battery level by press button C (turns a green, amber or red LED on for 1 second to display health)


It all works, but when I press button C, and hold it, the LED goes out and wont relight for a few seconds... I really wantted it to stay on while the button is held down... Also after the battery level has displayed.. I cant hear my stepper motor clicking, when it should be off!

How do I attach code on here correctly?

Thanks - You Legends!
 

Basrad

Member
Thank you :)

Its been done in flow, so the Basic is a bit of a mess :eek:S

Code:
 main:
label_265:
		low 0
		low 1
		low 2
		low 3
		if pinC.0 = 0 and pinC.1 = 0 and pinC.7 = 1 then label_252	'Decision command
		if pinC.0 = 1 and pinC.1 = 0 then label_231	'Decision command
		if pinC.0 = 0 and pinC.1 = 1 then label_213	'Decision command
		goto label_265

label_213:
		high 0
		low 1
		low 2
		high 3
		pause 2	'Wait command
		low 0
		low 1
		low 2
		high 3
		pause 2	'Wait command
		low 0
		low 1
		high 2
		high 3
		pause 2	'Wait command
		low 0
		low 1
		high 2
		low 3
		pause 2	'Wait command
		low 0
		high 1
		high 2
		low 3
		pause 2	'Wait command
		low 0
		high 1
		low 2
		low 3
		pause 2	'Wait command
		high 0
		high 1
		low 2
		low 3
		pause 2	'Wait command
		high 0
		low 1
		low 2
		low 3
		pause 2	'Wait command
		goto label_265

label_231:
		high 0
		low 1
		low 2
		low 3
		pause 2	'Wait command
		high 0
		high 1
		low 2
		low 3
		pause 2	'Wait command
		low 0
		high 1
		low 2
		low 3
		pause 2	'Wait command
		low 0
		high 1
		high 2
		low 3
		pause 2	'Wait command
		low 0
		low 1
		high 2
		low 3
		pause 2	'Wait command
		low 0
		low 1
		high 2
		high 3
		pause 2	'Wait command
		low 0
		low 1
		low 2
		high 3
		pause 2	'Wait command
		high 0
		low 1
		low 2
		high 3
		pause 2	'Wait command
		goto label_265

label_252:
		readadc 2,b10		'read A2 into b10
		if b10 >= 0 AND b10 <= 101 then label_256	'Analogue command
		low 5
		low 6
		high 7
		pause 1000	'Wait command
		low 5
		low 6
		low 7
label_264:	return		'Return 

label_256:
		readadc 2,b10		'read A2 into b10
		if b10 >= 95 AND b10 <= 100 then label_257	'Analogue command
		readadc 2,b10		'read A2 into b10
		if b10 >= 0 AND b10 <= 94 then label_261	'Analogue command
		goto label_264

label_261:
		high 5
		low 6
		low 7
		pause 1000	'Wait command
		low 5
		low 6
		low 7
		goto label_264

label_257:
		low 5
		high 6
		low 7
		pause 1000	'Wait command
		low 5
		low 6
		low 7
		goto label_264
 

Buzby

Senior Member
It is a bit of a mess !!!.

There is a 'Return' with no 'gosub', and it crashes the simulator with stack error.

I've never used flowchart programming, but return without gosub does not seem right at all.

Can you post a picture of the flowchart ?
 

hippy

Ex-Staff (retired)
The first "pinC.0 = 0 and pinC.1 = 0 and pinC.7 = 1" decision seems to GOTO to a subroutine which then returns. It's this RETURN without a previous procedure call which is likely the problem.
 

Basrad

Member
Maybe this Return without a procedure is a left over from a previous attempt.. Unfortunately i don't have time tonight, but i will have a go at a fix tomorrow afternoon.

Strange it gives an error.. that code is running okay on the hardware at the moment, just with the glitch in giving a constant battery level check...

thanks for the input, (unfortunately I don't always work with circuit diagrams.. (Evil I know) I'll try and get one up tomorrow though
 

Buzby

Senior Member
... Strange it gives an error.. that code is running okay on the hardware at the moment, just with the glitch in giving a constant battery level check...
The code runs fine - until you press the battery test button (C.7).
That's when the unexpected 'return' gets executed.

Circuit diagram not likely to help fix your software problem, but it may show some other issue, such as missing decoupling caps :)
 

westaust55

Moderator
The fix can be done in one of two ways:
1. Chug the RETURN near the bottom of the code listing to
GOTO Label_265
2. at the end of the IF.... THEN test for C.7=1 change
THEN Label_252 to read
THEN GOSUB Label_252

While I note the original code was done in flow charts, (and well done for getting as far a you did), many/most folks here use the text based BASIC language which gives access to many more programming commands/features.
If you look in PiCAXE manual 3 there is example code to operate a stepper motor in both direction which uses a loop and just a few lines of code. You can do something similar and monitor for button release within the loop.

A second commend - there is no need to use the READADC command just before each IF...THEN test or comparison.
The value in the variable b10 is retained unless your program deliberately modifies it.
 
Top