Input not working correctly

LEH

Member
Picaxe 28X2. I am having a problem with switch inputs. The code for one input which works correctly is if pinB.3 = 0 then blay blay endif. The code for the input that does not work is if pinB.6 = 0 then blay blay endif. Both pins are defined as inputs. if I place the mouse over pinB.3 a box appears saying pinB.3=1=$01=%00000001. if the mouse is placed over pinB.6 the box shows pinB.6=0=$0=%00000000. If I simulate the code the pinB.6 software executes correctly, in real life the input is recognized because other things that were working no longer work, but the code for pinB.6 is not executed.
 

LEH

Member
View attachment marble.basHow do I attach the code file here? Schematic not in electronic form. Pulled up switches attached to B.7 through B.3 and A.3. Solenoid drivers on C.0 through C.7. Limit switches on A.1 and A.2. One second latch on A.0 and B.2. Motor control on B.0 and B.1. Hopefully I figured out how to attach the code file. Suspect the chip gets reset when B.6 goes low, not confirmed.
 

hippy

Technical Support
Staff member
You can add the following to the top of your code to have the program report if it is restarting or not ...

Code:
#Picaxe 28X2
#Terminal 9600
Pause 2000
SerTxd( "Restarted", CR, LF )
You can also add further SERTXD to report that it has reached certain parts of the code.
 

LEH

Member
When I turned on the computer this morning, I opened the picaxe editor. I now find that when the mouse hovers over the pinB.n they all show pinB.n = 0=$0=%00000000. I reprogramed the board, but it still has the same problem.
 

Technical

Technical Support
Staff member
The mouse hover value is for on-screen simulation only, it has nothing to do with what is currently running inside the PICAXE chip (which is running by itself without talking to the computer).
 

LEH

Member
Will try swapping B.6 with an output pin, if that resets the chip then I'll have to install 2 diodes and not use B.6. Also may have to think twice before using picaxe in some other project.
 

erco

Senior Member
Also may have to think twice before using picaxe in some other project.
Hope you get it sorted out, but don't be so quick to blame the well-proven and widely used Picaxe. Sounds like you have plenty of potential for wiring and coding errors. If you really have 8 solenoids, then any of those could be causing RFI, voltage sag, back emf, spikes, you name it. How about posting some photos of your installation? Your code won't open on my tablet as you attached, btw. Just paste it into your post.

Is this your first Picaxe project? What kind of decoupling caps are you using?
 

inglewoodpete

Senior Member
Also may have to think twice before using picaxe in some other project.
Changing the pin is unlikely to affect the problem you are having. Similarly, changing the chip to something other than a PICAXE won't have much effect, either. When using motors, relays or solenoids with ANY microcontroller, the wiring of the power feeds to both the chip and these peripherals is critical. A circuit diagram AND a photo or two of your layout will be necessary for members to help you get to the source of your problem.
 

cravenhaven

Senior Member
Copy of the code:

Code:
let dirsB = $07
let dirsA = 0
let dirsC = $FF
let pinsB = 0
let pinsC = 0
setfreq em64
'symbol Mark = A.0
symbol SEC = b2
symbol Mnt = b3
symbol Hrs = b4
symbol Ecyc = b11	'going up, going dwn, off
symbol Last = b12
symbol LH = b13
symbol LM = b14
symbol Stp = b15
symbol Elev = b16	'need to Ecyc
'note b17 is used
symbol Load = pinC.2
symbol Drop = pinC.7
symbol Smin	= pinC.5	'Select min
symbol Stm	= pinC.3	'Select tens of min
symbol Dhrs = pinC.1	'Dump hours
symbol Dtm	= pinC.6	'Dump tens of minutes
symbol Dmin = pinC.4	'Dump minutes
symbol Lelv = pinC.0	'losd elevator
symbol Mca	= pinB.1	'motor control
symbol Mcb  = pinB.0
symbol Ack	= pinB.2
let Ecyc = 0	'elevator not moving
let Stp = 0	'setup
Iset:	'initial setup
gosub Onesec
if pinB.3 = 0 then
	Ecyc = 1	'elevator up
	Mca = 0
	Mcb = 1
endif
if pinB.7 = 0 then
	gosub Onesec
	goto Preset
endif
goto Iset

Preset:
Load = 1	;now we know it took
pause 250
Load = 0

Setup:
let Stp = 1
if pinB.3 = 0 then	'sw4
	Lelv = 1
	gosub Onesec
	gosub Onesec
	gosub Onesec
	Lelv = 0
	Ecyc = 1
	Mca = 0
	Mcb = 1
endif
if pinB.6 = 0 then	;sw2
	Stm = 1
	Smin = 1
	gosub Onesec
	Drop = 1
	gosub Onesec
	gosub Onesec
	Drop = 0
	Smin = 0
	Stm = 0
	Load  = 1
	gosub Onesec
	gosub Onesec
	Load = 0
	Mnt = Mnt + 10
	if Mnt >= 60 then
		Mnt = 0
	endif
endif
if pinB.5 = 0 then	'sw6
	Dhrs = 1
	Hrs = 0
	gosub Onesec
	gosub Onesec
	gosub Onesec
	Dhrs = 0
endif
if pinB.4 = 0 then	;sw5
	Dtm = 1
	Mnt = 0
	gosub Onesec
	gosub Onesec
	Dtm = 0
	Dmin = 1
	gosub Onesec
	gosub Onesec
	gosub Onesec
	Dmin = 0
endif
if pinB.7 = 0 then	;sw1
	Hrs = Hrs + 1
	if Hrs = 13 then
		Hrs = 1
	endif
	Drop = 1
	gosub Onesec
	gosub Onesec
	Drop = 0
	gosub Onesec
	Load = 1
	gosub Onesec
	gosub Onesec
	Load = 0
endif
if pinA.3 = 0 then	;sw3
	Mnt = Mnt + 1
	if Mnt >= 60 then
		Mnt = 0
	endif
	Smin = 1
	gosub Onesec
	Drop = 1
	gosub Onesec
	gosub Onesec
	Drop = 0
	Smin = 0
	Load = 1
	gosub Onesec
	gosub Onesec
	Load = 0
endif
gosub Onesec	'this will control elevator
if Ecyc = 0 And pinA.1 = 0 then Bgmain	'Begin Main
goto Setup

Bgmain:
Load = 1	;notify that we are here
pause 250
Load = 0

Main:
let Stp = 0
gosub Onesec
if Sec = 56 then
	if Hrs = 12 AND Mnt = 59 then
		Dhrs = 1
		Hrs = 0
		Elev = 2
		Lelv = 1
	endif
endif
if Sec = 57 AND Mnt = 59 then
	Dtm = 1
endif
if Sec = 58 AND Mnt = 59 then
	Dmin = 1
	Mnt = 0
	Dhrs = 0
	if Elev = 0 then
		Elev = 1
		Lelv = 1
	endif
endif
if Elev = 2 AND Sec = 59 then
	Lelv = 0
endif
if Sec = 59 then
	Dtm = 0
	if Hrs = 0 then Main
	let b17 = Mnt//10
	if b17 = 9 then
		Stm = 1
	endif
	Smin = 1
endif
if Elev = 1 AND Sec = 1 then
	Lelv = 0
endif
if Sec = 0 then
	Dmin = 0
	Drop = 1
endif
if Sec = 1 then
	Drop = 0
	Stm = 0
	Smin = 0
endif
if Sec = 2 then
	Load = 1
endif
if Sec = 3 then
	Load = 0
endif
if Sec = 15 AND Elev <> 0 then
	if Ecyc = 0 then
		Elev = Elev - 1
		Ecyc = 1
		Mca = 0
		Mcb = 1
	endif
endif
	
goto Main

'subroutines
Onesec:
Last = Sec
LH = Hrs
LM= Mnt
Wos:	'wait one second
if Ecyc = 1 AND pinA.1 = 0 then
	Ecyc = 2
	Mcb = 0
	Mca = 1	'why isnt this enough
	pause 2
	Mca = 1
endif	
if Ecyc = 2 AND pinA.2 = 0 then
	Ecyc = 0
	Mca = 0
	Mcb = 0
endif
if pinA.0 = 1 then
	Sec = Sec + 1
	if Sec = 60 then
		Sec = 0
		Mnt = Mnt + 1
		if Mnt = 60 then
			Mnt = 0
			Hrs = Hrs + 1
			if Hrs = 13 then
				Hrs = 1
			endif
		endif
	endif
	pulsout B.2, 2
endif
if Sec = Last then Wos
if Stp = 1 then
	Hrs = LH
	Mnt = LM
endif
return
 

LEH

Member
If RFI was the problem, chip would reset at random while running. Runs fine. Fails in setup, switches read while solenoids, motor not active. Fails on switch press, no motor or solenoid is activated.
 

hippy

Technical Support
Staff member
What exactly is the problem ?

Earlier on you were reporting an issue with PE6, that it was not reflecting what your program running on physical hardware presumably should have been showing. That was not a fault, that was correct and expected behaviour, because PE6 does not reflect what a program running on physical hardware is doing. It seems you were expecting PE6 to do something which it does not.

Beyond that issue, it is not clear what issue you now have. If you could provide more detail on what does not appear to work as expected, how that manifests itself that will help.

If something fails on a switch press which should activate a motor or solenoid, it is possible that it was the activation of the motor or solenoid which reset the PICAXE. This can happen so quickly that the reset occurs before any activation of a motor or solenoid is seen.
 
Top