20M2 pinB.1 condition

Jaden

Senior Member
Hi, For some reason the following code will fall out of the startsc loop. When I remove
Code:
pinB.1 = 1
then all is good. I replace the 20M2 and still the same. I put a 20x2 in its place and all is good and the program will keep looping. I change pinB.1 to pinB.2 and all is good. There is no high on this pin.

Thanks
Code:
'====================================================================================================================
'==========================================START OF PROGRAM 2========================================================

start:
 ' PICAXE-20M2 
 ' Shotclk.bas
 ' Count down a given number to zero on a two digit 7-segment display
 ' using a 74HC595 Shift Register.
 ' pin 11 SH_CP Shift register clock input
 ' pin 12 ST_CP Storage register clock input
 ' pin 14 DS Serial data input
 '
 ' pin 11 - C.2 SH-CP (20M2 pin 8)
 ' pin 12 - C.1 ST_CP (20M2 pin 9)
 ' pin 14 - C.0 DS (20M2 pin 10)
 '
 
 ;DS = C.0  pin 10 Picaxe / Serial data input pin 14 595
 ;STCP = C.1 pin 9 Picaxe /  Storage register pin 12 595
 ;SHCP = C.2  pin 8 Picaxe / Shift register pin 11 595
 
 
 ;General Purpose Bytes Used
 ;b0, b1, b3, b4, b5, b6, b20 
 
 'Pin 18 - B.0 - resetgc
 'Pin 17 - B.1 - startsc
 'Pin 6 - C.4 - siren
 'Pin 5 - C.5 - startsc
 'Pin 4 - C.6 - pausesc
 'Pin 3 - C.7 - resetsc 
 
 #picaxe 20M2
 symbol dataout = C.0
 symbol clk = C.2
 symbol latchout = C.1
 

 symbol out = b7
 symbol loop1 = b8
 symbol loop2 = b9
 symbol outbyte2 = b3
 symbol status = b10 
 
 'pullup on
 'pullup %00011111						'pull up on B.0 B.1 B.2 B.3
'let pinsB = %11111111						; switch on outputs 0 and 1
startsc:
	 
	outbyte2 = %00111111					'Send 0 to units Segment
 	gosub out595 						'send this b5 value to register, DS
 	outbyte2 = %01001111					'Send 3 to Tens Segment
 	gosub out595
 	pulsout latchout,1 					'Display 2 new digits once both are loaded into their 595s
	if pinC.5 = 1 or pinB.1 = 1then 			'if startsc or startgc button then goto to countdown
 	       goto main
 	endif
 	goto startsc						'loop until it is.
 	debug
 	

main:	 	
'------------------------------------------------  count down from 29 to 20  ------------------------------------------------
	
	
 	for b8 = 0 to 9
 		
 	gosub loop_1sec						'call up 1 second delay with button watch loop
 	lookup b8,(%01100111, %01111111, %00000111, %01111100, %01101101, %01100110, %01001111, %01011011, %00000110, %00111111),outbyte2 'tens segment turn on 9
 		gosub out595	
 	outbyte2 = %01011011					'Send 2 to tens segment
 		gosub out595	
 	pulsout latchout,1 
 	next b8
 	
 	
 		
'------------------------------------------------  count down from 19 to 10  ------------------------------------------------ 
		
 	
 	for b4 = 0 to 9

 	
 	gosub loop_1sec						'call up 1 second delay with button watch loop
 	lookup b4,(%01100111, %01111111, %00000111, %01111100, %01101101, %01100110, %01001111, %01011011, %00000110, %00111111),outbyte2 'tens segment turn on 9
 		gosub out595
 	outbyte2 = %00000110					'Send 1 to tens segment
 		gosub out595
 	pulsout latchout,1
 	next b4	
 	
 	
 
'------------------------------------------------  count down from 9 to 00  ------------------------------------------------	
	
 	for b5 = 0 to 9

 
 	gosub loop_1sec						'call up 1 second delay with button watch loop
 	lookup b5,(%01100111, %01111111, %00000111, %01111100, %01101101, %01100110, %01001111, %01011011, %00000110, %00111111),outbyte2 'tens segment turn on 9
 		gosub out595
 	outbyte2 = %00000000					'blank tens segment
 		gosub out595
 	pulsout latchout,1   
 	next b5  
 	    
'---------------------------------------------  Flash digits and Siren  ---------------------------------------------	
	
	for b6 = 1 to 2	 					'2 cycle loop for buzzer
	outbyte2 = %00111111					'Send 0 to units Segment
 	gosub out595 						'send this b5 value to register, DS
 	outbyte2 = %00111111					'Send 0 to Tens Segment
 	gosub out595
 	pulsout latchout,1					'Display 2 new digits once both are loaded into their 595s 	
	High C.3							'high to buzzer and light
 	pause 300							'slight pause between siren
 	outbyte2 = %00000000					'blank units Segment
 	gosub out595 						'send this b5 value to register, DS
 	outbyte2 = %00000000					'blank Tens Segment
 	gosub out595
 	pulsout latchout,1					'Display "00" once both are loaded into their 595s 
 	low C.3
 	pause 300
 	next b6
 	goto startsc							'go back to start of count
 	
 	'---------------------------------------------  THE END  -----------------------------------------------------
'
' **** Subroutines ****
'
out595:
 	b0 = %10000000 						'We want to look at the left most bit(MSB) first
 	for b1 = 0 to 7 						'loop 8 times to get all bits
	 	b2 = outbyte2 & b0 					'Look at the MSB
	 	if b2 = b0 then 					'if the MSB is high output high
			high dataout
	 	else
	 		low dataout 				'else if the MSB is low output low
	 	endif
		pulsout clk, 1 					'pulse the clock line to move the output bit into the register
	 	b0 = b0 /2 						'clock the next bit out
 	next b1
 	return
 	 	
loop_1sec:
	
	
	for w1 = 1 to 112						' 112 seems to take 1 second
	gosub buttonck
		next w1
	return
	
	
buttonck:
	
	if pinC.6 = 1 then 					'if pausesc button then goto to pause
 	       goto pausesc
 	endif
 	if pinC.7 = 1 OR pinB.0 = 1 then 			'if resetsc button pressed restart countdown
 	       goto startsc
 	endif
  	 return



pausesc:
	
	pause 10						
	if pinC.5 = 1 then 					'if pausesc button then resume to countdown
 	       return
 	endif
 	if pinC.7 = 1 OR pinB.0 = 1 then 			'if resetsc button pressed then go back to start
 	       goto startsc
 	endif
 		 
 	goto pausesc
end
 

PaulRB

Senior Member
Jaden, what happens if you replace that long program with a tiny one that just sends pinb.1 to the pc (sertxd command) in a loop? If it shows 1, can you show us a schematic, and a sharp closeup picture of the circuit.

Paul
 

srnet

Senior Member
It is still strange that only this pin is playing up!
Maybe not, the circuit diagram shows that b.1 is connected to b.2 on a 14M2 and something called 'Remote P2'.

Maybe pin b.1 is floating, hence the suggestion for a pulldown resistor.
 

srnet

Senior Member
Hi, For some reason the following code will fall out of the startsc loop
If it falls out at this point;

if pinC.5 = 1 or pinB.1 = 1then 'if startsc or startgc button then goto to countdown
goto main
endif
Then it will be because c.5 is high (1) or b.1 is high (1) or indeed floating.
 

Jaden

Senior Member
Maybe not, the circuit diagram shows that b.1 is connected to b.2 on a 14M2 and something called 'Remote P2'.
Na. The remote P2 is a future idea that I incorporated that is not in circuit, only a header after the signal diode. Like I said to start with... Why does B.2 or any other pin work OK if I change the "pinB.1" value in the original code? The pin is low when measured and when I was originally chasing the fault I removed the 14M2 and still got the fault! Also like I mentioned when I replace the 20M2 with a 20x2 I do not get this fault???? Soooo to me the fault is from within the 20M2 on that particular pin?
Then it will be because c.5 is high (1) or b.1 is high (1) or indeed floating.
As stated earlier I can change it to "pinC.5 = 1 or pinB.2 = 1 then" and it does not fire of out of the loop.

I will try and set pins B on the 14M2 to low and see if this helps. Thanks so far folks.
 

Goeytex

Senior Member
What supplies the high & low signals to the 20M2 PinB.1 ?

Unless b.2 on the 14M2 is dedicated output ( we have no code to tell) and is being set low in Code, then PinB.1 is floating and will be unpredictable. It may measure low with a meter or a scope because the impedance of the meter/ scope is enough to pull it low. Different pins may behave differently to a floating condition. The fact that a 20X2 works is irrelevant if the pin is floating since it is different silicon and has different loading characteristics. But an input pin on any Picaxe, regardless if it seems to work ok, must never be left floating. The fact that the behavior changes when the Programming Adapter is plugged in may suggest a grounding problem.

A quick test would be to connect one end of a 10K resistor to a ground and while the program is running touch the other end of the resistor to pin b.1. If it stops breaking out of the loop, then you have your answer.

If the pin is not floating and the grounds are confirmed /sorted out, I would then put the 20M2 on a breadboard with a minimum circuit & minimum code for testing.

I don't see them on the schematic, but I trust that there are decoupling capacitors on the Picaxe Supply pins.
 
Last edited:

Technical

Technical Support
Staff member
Soooo to me the fault is from within the 20M2 on that particular pin?
You are missing the point. An input should never float. If it does the program may appear to work sometimes, may not work other times. May work on one chip, may not work on another chip. May work when the programming cable in inserted, may not work when the cable is not inserted. May work when you have your hand on the pcb, may not work when you don't touch it. But the bottom line is the circuit is faulty, not the chip.
 
Top