Picaxe-test

Pekari

Senior Member
My test are made with PICAXE 18X:
I run this code on the test-board without any devices to control.
My test board get a reset 3 times today with this program.
Haven't get any error with this circuit and program yet.

Circuit:
Potentometer 1 kohm...10 kohm:
1 = +
2 = input 0
3 = -

AXE033 LCD-display:
+ to +
- to -
LCD in = output 1

Code:
'	PICAXE-test
'	Made By Pekari 14.10.2008.
pause 1000
w0=0 w1=0 w2=0 w3=0
readadc 0,b1
goto show
reset:
b0=0
low 0
pause 1
low 2
pause 1
main:
w2=w2+1
if w2=65535 then counter
if bit0=0 and bit2=0 then part1
if bit0=0 and bit2=1 then part2
if bit0=1 and bit2=1 then part3
if bit0=1 and bit2=0 then error1
if outpin0=1 and outpin2=0 then error2
pause 10
goto main
part1:
bit0=0
bit2=1
low 2
pause 1
low 0
pause 1
high 2
pause 1
goto main
part2:
bit0=1
bit2=1
low 2
pause 1
low 0
pause 1
high 2
pause 1
high 0
pause 1
goto main
part3:
bit0=0
bit2=0
low 2
pause 1
low 0
pause 1
goto main
error1:
b2=b2+1
goto show
error2:
b3=b3+1
goto show
counter:
w3=w3+1
show:
serout 1,N2400,(254,1)
pause 50
serout 1,N2400,(254,128,"SV=",#b1," Cou=",#w3)
pause 1000
serout 1,N2400,(254,192,"E1=",#b2,", E2=",#b3)
pause 1000
if b2<255 and b3<255 and w3<65535 then reset
end
1. Set a potentiometer a middle.
2. Run a program.
3. Look a SV number (Start value) and write it up.
4. Set a potentiometer to - side.
5. Keep program running as long as you like.

Notes:
SV: should NOT change, otherwise Picaxe is have done a reset. When Picaxe get reset, value will be read from input 0 (pot).
E1: Variable value error.
E2: Output error.
 
Last edited:

BeanieBots

Moderator
I have no idea what your code is meant to be doing.
Some comments with it would be nice.
There is a big mix of words and bytes. Are you doing something clever to the word values with all those individual byte changes?
 

marky26uk

New Member
Code problem

Hi, as above comment no idea what your code is meant to be doing.
If you could post your code again but then maybe after each line of your code put a rem after each line, the symbol for a rem is ' , this is on the @ key on my keyboard.
This then you can add comments after each line of commands to state what this line of code is actually doing, this would make it easier for you in the future to understand what each line of code is doing when you're debugging, but more so importantly more easier for us in the forum to see what your code is actually doing.
This doesn't take up any program memory space of your picaxe by the way just incase you're wondering.
So please post again with either the above tip or more of a description of what your program is for or what it is doing, then we can help you more.

Yours,
Mark
 

Pekari

Senior Member
New version and explain.

Program change a values to bit 0 and bit 1 and if they get a value which are not programmed, it count a number to E1.
Bit 0 describe a output 0 state and bit 2 output 2 state, and if those states get a wrong values it count a E2.

This versio imitation better a motor controlling.
Upper program will work as it should but it have a couple extra lines.

Code:
'	PICAXE-test
'	Made By Pekari 15.10.2008.
pause 1000
w0=0 w1=0 w2=0 w3=0
readadc 0,b1
goto show
reset: '	Halt a motor.
b0=0
low 2
pause 1
low 0
pause 1
main: '	Check a states.
w2=w2+1
if w2=65535 then counter
if bit0=0 and bit2=0 then part1
if bit0=0 and bit2=1 then part2
if bit0=1 and bit2=1 then part3
if bit0=1 and bit2=0 then error1
if outpin0=1 and outpin2=0 then error2
pause 10
goto main
part1: '	Motor off (2), course backwards (0), motor on.
bit0=0
bit2=1
low 2
pause 1
low 0
pause 1
high 2
pause 1
goto main
part2: '	Motor off, course forwards, motor on.
bit0=1
bit2=1
low 2
pause 1
high 0
pause 1
high 2
goto main
part3: '	Motor off, course relay off.
bit0=0
bit2=0
low 2
pause 1
low 0
pause 1
goto main
error1: '	Wrong value in variables.
b2=b2+1
goto show
error2: '	Wrong state in outputs.
b3=b3+1
goto show
counter: '	Count a number so we can see that program is running.
w3=w3+1
show: '	Show mode, stage and errors.
serout 1,N2400,(254,1)
pause 50
serout 1,N2400,(254,128,"SV=",#b1," Cou=",#w3)
pause 1000
serout 1,N2400,(254,192,"E1=",#b2,", E2=",#b3)
pause 1000
if b2<255 and b3<255 and w3<65535 then reset
end
 
Last edited:

BeanieBots

Moderator
It's still unreadable but at a glance it still looks to me that you have your bytes and words mixed up.

Are you aware:-
bit0, bit1 etc make up b0.
b0 and b1 are the two bytes of w0

Hence, changing the value of bit0 will also change the value of b0 and w0.
 

BeanieBots

Moderator
OK, good.
That leads to the question what does the line...
If outpinN ....
actually return?

Is it the value the PICAXE has set the pin to be, or is it the actual (external electrical) logic state of the pin? One for Technical maybe?
 

Technical

Technical Support
Staff member
BB is correct, outpin cannot be used like this on an 18X

Code:
if outpin0=1 and outpin2=0 then error2
For output pins status use readoutputs
Code:
readoutputs b8
let b8 = b8 & %00000011 'mask off unwanted bits
if b8 = %00000001 then
 

westaust55

Moderator
Also, from what I have read when using one input pin as an analogue input, the others should be tied to ground (0V) with say a 10K Ohm resistor) otherwise they may fluctuate.

You say you have no external devices connected to inputs yet you are testing inputs. It is possible that they are floating as has been discussed in other threads and giving occasional high signals causing your program to "see" errors which in reality are not there but just floating inputs.

And to reiterate and add to what others have already said:
1. add some coments to your code to make it easier for others to understand.

2. Use indentation for your code to make it easier to read.

3. avoid using a label which is a command for another version of the PICAXE.
in your case the label "reset". on the X1 and X2 parts this is a command.
That keeps your code portable for you or others to use in future with least problems.

If it is easy to understand then people are more inclined to help

see formatted version here:
Code:
'PICAXE-test
'Made By Pekari 14.10.2008.

pause 1000
w0=0 w1=0 w2=0 w3=0
readadc 0,b1
goto show

reset:
        b0=0
        low 0
          pause 1
        low 2
        pause 1

main:
        w2=w2+1
        if w2=65535 then counter
        if bit0=0 and bit2=0 then part1
        if bit0=0 and bit2=1 then part2
        if bit0=1 and bit2=1 then part3
        if bit0=1 and bit2=0 then error1
        if outpin0=1 and outpin2=0 then error2
        pause 10
        goto main

part1:
        bit0=0
        bit2=1
        low 2
        pause 1
        low 0
        pause 1
        high 2
        pause 1
        goto main

part2:
        bit0=1
        bit2=1
        low 2
        pause 1
        low 0
        pause 1
        high 2
        pause 1
        high 0
        pause 1
        goto main

part3:
        bit0=0
        bit2=0
        low 2
        pause 1
        low 0
        pause 1
        goto main

error1:
        b2=b2+1
        goto show

error2:
        b3=b3+1
        goto show

counter:
        w3=w3+1

show:
        serout 1,N2400,(254,1)
        pause 50
        serout 1,N2400,(254,128,"SV=",#b1," Cou=",#w3)
        pause 1000
        serout 1,N2400,(254,192,"E1=",#b2,", E2=",#b3)
        pause 1000
        if b2<255 and b3<255 and w3<65535 then reset

end
 
Last edited:

Pekari

Senior Member
You say you have no external devices connected to inputs yet you are testing inputs.
Thanks, but where I am testing inputs?

I am testing variables, outputs and resetting problem.

There is fixed code:

Code:
'	PICAXE-test
'	Made By Pekari 15.10.2008.
pause 1000
w0=0 w1=0 w2=0 w3=0 w4=0
readadc 0,b1
goto show

zeroth: '	Halt a motor.
	b0=0
	low 2
	pause 1
	low 0
	pause 1
	
main: '	Check a states.
	w2=w2+1
	if w2=65535 then counter
	if bit0=0 and bit2=0 then part1
	if bit0=0 and bit2=1 then part2
	if bit0=1 and bit2=1 then part3
	if bit0=1 and bit2=0 then error1
	readoutputs w4
	w4=w4 and 5
	if w4=1 then error2
	pause 10
	goto main
	
part1: '	Motor off (2), course backwards (0), motor on.
	bit0=0
	bit2=1
	low 2
	pause 1
	low 0
	pause 1
	high 2
	pause 1
	goto main
	
part2: '	Motor off, course backwards, motor on.
	bit0=1
	bit2=1
	low 2
	pause 1
	high 0
	pause 1
	high 2
	goto main
	
part3: '	Motor off, course relay off.
	bit0=0
	bit2=0
	low 2
	pause 1
	low 0
	pause 1
	goto main
	
error1: '	Wrong value in variables.
	b2=b2+1
	goto show
	
error2: '	Wrong state in outputs.
	b3=b3+1
	goto show
	
counter: '	Count a number so we can see that program is running.
	w3=w3+1
	
show: '	Show mode, stage and errors.
	serout 1,N2400,(254,1)
	pause 50
	serout 1,N2400,(254,128,"SV=",#b1," Cou=",#w3)
	pause 1000
	serout 1,N2400,(254,192,"E1=",#b2,", E2=",#b3)
	pause 1000
	if b2<255 and b3<255 and w3<65535 then zeroth
	
end
(I am testing this code right now.)

Why it's illegal to receive floating values if them will not read?
I can't believe at it will get reset because of using outpin or inputs are floating.:confused:
 
Last edited:

hippy

Ex-Staff (retired)
This all seems incredibly complicated to check if a PICAXE is resetting when it should not. Perhaps the problem is that it's not clear how the program is a test, what it actually tests for, and how it tests that.

While there has to be some hardware or interface to show a failure has occured, the need for a READADC seems unecessary and a better test would detect a reset failure entirely automatically without any user intervention; no need to note anything or adjust anything, download the code, leave it running, come back to see if failed is indicated, ideally some indicator as to why it failed.

A simplistic approach to catch an output line activation causing a reset using the Programming Editor Terminal and SERTXD ...

Code:
  Eeprom 0,(0)
  Read 0,b0
  If b0 <> 0 Then
    Do
      SerTxd( "Reset when it should not have !",CR,LF )
      Pause 1000
    Loop
  End If
  Write 0,$FF
  SerTxd( "Starting Test",CR,LF )
  Do
    pins = b0
    b0 = b0+1
  Loop
 
Top