Shift Register Woes

booski

Senior Member
Hi there!

As some of you may know, I've been making a set of board for a remotely operated set of mains sockets for a college project.

So far I have:

Made the relay board with a TPIC6C595 shift register
Made the top and bottom controller boards including 6 button ADC control, IR control and PICAXE interface with download socket, LED's indicating socket status etc.

To date I have:

Managed to get the 6 button ADC working including matching LED for each button.
gotten the PWM LED duty to work with the Socket LED's that when sockets(relays)/LED's are ALL off, the PWM LED dims. When 1 or more socket(relay) is on, the matching LED is also on, and the PWM LED is bright.

Now, I have interfaced the controller board to the relay board and using the SPI bus, gotten the controller board to work the relays.

i.e. when button 1 is pressed, relay 1 turns on, when button 2 is pressed, relay 2, turns on. When button 5 is pressed, the relays that are currently on turn off, when button 5 is pressed again, relays 1 and 2 that were previously on but now off, turn on again.

Simply put, it works very well to my liking and also to my design specification although I haven't tested the IR interface.

All that aside, the issue im having now is that when power is applied to the circuit as a whole, the shift register for some reason turns ALL of the relays on even though there is no code in the picaxe for it to do that.
If there's no power to the PICAXE and power is applied, the relays do nothing.
If I include right at the very beginning of the code to write 0's into the shift register, when power is applied and the picaxe powers up, the relays turn ON, and then OFF because the code tells it too.

All I can think is that there is something that the picaxe is doing when it first starts up that's turning on the relays, any idea?

Code:
;Remotely controlled sockets program, written by Nigel Nichols

gosub shift 		' to turn relays off because the relays turn on upon boot

symbol MOSI = B.2		' pinouts to the relay board
symbol SRCK = B.1	
symbol RCK = B.0	

symbol counter = b7	' variable used during loop
symbol var_out = B0	' data variable used during shift
symbol bits = 8		' number of bits

symbol dataout = B0	' data to transmit
symbol Buttons = B3	' variable used to hold button ADC value
symbol PortBstatus = B4	' variable used to hold port status in order to turn all on/off
symbol latch = B5		' variable used to hold port status when 'current on/off' button used
pwmout B.3, 63, 10	' PWM to control status LED

main:
debug
let latch = portBstatus ' copies the portBstatus into latch
if pinsB >14 then pwmduty B.3,255 	' If there is an LED/Relay on, the status LED will be bright, else dim
else pwmduty B.3,10
endif
Readadc c.2,buttons	' Forces a check of the button ADC
if buttons >10 then gosub buttonstatus	'If a button is pressed it will be greater than 1
goto main

Buttonstatus:
Readadc c.2,buttons	' Double checks the button that is pressed as a minor debounce
if buttons >240 then gosub socket1
if buttons <240 and buttons >200 then gosub socket2	
if buttons <200 and buttons >160 then gosub socket3
if buttons <160 and buttons >100 then gosub socket4
if buttons <100 and buttons >50 then gosub Current
if buttons <50 and buttons >10 then gosub All
return

Socket1:
If pinb.4 = 0 then high b.4 	' this acts as a latch, if the LED is on, then it'll 
else pinb.4 = 0			' turn off, if it's off then it will be on
endif
gosub shift				' before the pause but after the selection is made
pause 100				' this will shiftout 
return
Socket2:
If pinb.5 = 0 then high b.5
else pinb.5 = 0
endif
gosub shift
pause 100
return
Socket3:
If pinb.6 = 0 then high b.6
else pinb.6 = 0
endif
gosub shift
pause 100
return
Socket4:
If pinb.7 = 0 then high b.7
else pinb.7 = 0
endif
gosub shift
pause 100
return
Current:
let PortBstatus = outpinsB
if portbstatus > %00001000 then let pinsB = %00001000 gosub shift return	
else let pinsB = latch	' %00001000 is used to keep the PWM out enabled
endif				
gosub shift
pause 100
return
All:
let PortBstatus = outpinsB
if portbstatus > %00001000 then let pinsB = %00001000 gosub shift return
else let pinsB = %11111000 'turns all relays on/off and whatever is on, off also
endif
gosub shift
pause 100
return

shift:
let dataout = outpinsB
dataout = dataout / 16
	for counter = 1 to bits
		if bit7 = 1 then   	' as data if shifted, if its a 1 it stays high, else goes low
			high MOSI 
		else
			low MOSI				
		endif
		pulsout SRCK,1 		' pulse clockpin for 10us 
		var_out = var_out * 2 		' shift variable left for MSB 
	next counter
	pulsout RCK,1
	return
 

Armp

Senior Member
You need to hold Output Enable (pin8) HIGH until the picaxe has woken up. More help will require your schematic.
 

booski

Senior Member
Ah, yes, thanks E!
Been meaning to get around to that, been busy building the boards (and running around Alton Towers :) ) of late to sort the code out but I will look into it.

I need to sort the values out anyway as the difference between each byte value from the ADC is a little off but it works for testing in the meantime anyway.

I have found something interesting though, I've just gotten my little DSO nano scope and looked at the serin on the TPIC6C595 when I flick the switch and apply power.

Surprisingly enough, there was nothing, at the same time however, the relays did nothing also.
So I powered down, removed probe, powered up, the relays all turned on.
Powered down, placed probe, powered up, relays did nothing!
So im thinking that perhaps I need a small pull down resistor on the serin pin of the shift register to stop is going silly?
 

Dippy

Moderator
I haven't seen your schematic or the layout you have done...

If your tests in the above post were done in isolation (i.e. a bare shift reg) then floatings pins can obviously result in unpredictable behaviour and this is where pull up/downs can help.

If your test was done with a powered PICAXE connected then it probably depends on the pin status as to how it would behave.
That includes signal, enable and clock.
But, hey, why not try it. It won't explode. Are you scared? :)

Once your PICAXE is up and running properly with it's pin is in Output mode then a pull-down is irrel as the PICaxe output is driven up and down push-pull . A resistor will have no effect in normal use.

What any uP or uC does at startup can cause problems in many circuits. The solutions can be easy/hard depending on the circuit requirements (which I don't know).
Some times extra goodies have to be added and a 'scoping of the pins will help you with your design choice.
 

booski

Senior Member
Relay board sche.jpg

This is the relay board schematic.

Also, I'm pretty sure someone is going to notice that there is an LED on the SEROUT pin on the chip.
I figured, instead of leaving it floating, I'll stick an LED on there so that when the outputs are changed, it indicates that something has been shifted out because something new has been shifted in.
 

booski

Senior Member
Bottom control board sche.jpgtop control board sche.jpg

This is the control board schematic for the top and bottom boards.

And no, the tests weren't done with in isolation, it was done with fully completed boards as there really isn't a great deal of components.

Initially, the test was done with a powered picaxe which when power was initially applied, is when on startup the shift register went nuts and turned on all the relays.
With an unpowered picaxe, when power was applied to relay board, it was fine. Hence why I can only assume that something when the picaxe starts up affects the shift register.
When I plugged the picaxe back in and touched a scope probe on ANY one of the SPI bus pins and applied power, nothing happened which is perculiar.

Luckily enough though, on the control board, the SPI out pins run parallel to a ground line, so I'll solder a few 0805 resistors between the SPI out pins and ground line, see if that helps on startup.
 

Dippy

Moderator
"When I plugged the picaxe back in and touched a scope probe on ANY one of the SPI bus pins and applied power, nothing happened which is perculiar."
Why is that pe(r)culiar?

Your previous tests with scope probes (I assume) where with floating pins weren't they? or...?
Any connection to another device (e.g. PICAXE) will provide load or drive to the previously floating pin.
Maybe I have misunderstood.

Why don't you 'scope the PICAXE pins during power-up?
Have a look-see. Surely that is the next step?

You may have to include some extras on the serial or clock lines (or even hold the CLR line) to reduce power-up funnies, but without measurements you are simply guessing and hoping.
 

booski

Senior Member
It was peculiar because without a scope probe on the SPI bus pins, then on start up the relays would operate. Soon as I touched a probe onto a SPI bus pin and applied power the relays didn't operate. Was almost like the probe was acting as some sort of high impedance pull down. Obviously not high enough impedance in order to show what happens

All tests have been conducted with fully populated boards, i.e. everything connected so no floating pins.

I will as I say, solder a pulldown resistor onto the SPI bus pins and see if that helps.

EDIT:

Fixed! Added some pulldown resistors onto the SPI bus pins and it works very gracefully.
No spurious relay happenings when power is applied! woop :)

Just need to sort IR control and re-write the code a little better. Thanks for all your help :)
 
Last edited:

booski

Senior Member
Right, im now trying to implement the Select Case code but it doesn't seem to like AND.

Any particular reason?
 

booski

Senior Member
Don't get me wrong, I read the manual, which is why I was confused as it had been suggested but not in the manual.
 

hippy

Ex-Staff (retired)
Right, im now trying to implement the Select Case code but it doesn't seem to like AND.

Any particular reason?
My fault for confusing PICAXE Basic with something else and having not tested it.

Case >= 200 And <= 299

Should be

Case 200 To 299
 

booski

Senior Member
Code:
Buttonstatus:
Readadc c.2,buttons	' Double checks the button that is pressed as a minor debounce
Select case buttons
case 20 to 62 : gosub All
case 63 to 103 : gosub Current
case 104 to 144 : gosub socket4
case 146 to 186 : gosub socket3
case 189 to 229 : gosub socket2
case >235 : gosub socket1
end select
return
Sorted!

Thanks hippy, thats much clearer
 
Top