GPIO USB Problem

John
hi guys,

i got a strange problem, maybe someone could shine a light on this one.

i got a 1-wire busmaster connected via USB (hostadapter DS9490R), 8 DS18B20
1 wire temperature sensors are connected.


then i got a relayboard with 4 relays -> 2 relays switch some garden lights
and 2 relays who supply 24V , one for my solenoid valve and on the other
one is only a torch bulb connected.

got debian lenny running on the system.
mini2440:~# uname -a
Linux mini2440 2.6.39.1 #1 Sun Jun 19 22:32:25 CEST 2011 armv4tl GNU/Linux
standard kernel with BSP patches onboard

switching the the garden lights and the bulb worked with no problems.
switching the solenoid valve relay on also work,
switching the solenoid valve relay off worked a view times till the whole
system hang, and then it is time for a reset.

i am switching the relay(con4/gpio166) off/on with a simple bash script
echo 0 > /sys/class/gpio/gpio166/value and
echo 1 > /sys/class/gpio/gpio166/value

i also switched it with gpio165(garden lights), but the error also appears
there.
the error only appears when the solenoid valve are connected to the pin.

when i run the command (off) from the command line, the usb connection is
drop and reconnected, kern.log says

May 30 21:09:58 mini2440 kernel: hub 1-0:1.0: port 1 disabled by hub
(EMI?), re-enabling...
May 30 21:09:58 mini2440 kernel: usb 1-1: USB disconnect, device number 13
May 30 21:09:58 mini2440 kernel: usb 1-1: new full speed USB device number
14 using s3c2410-ohci
May 30 21:09:59 mini2440 kernel: hub 1-0:1.0: port 1 disabled by hub
(EMI?), re-enabling...
May 30 21:09:59 mini2440 kernel: usb 1-1: USB disconnect, device number 14
May 30 21:10:00 mini2440 kernel: usb 1-1: new full speed USB device number
15 using s3c2410-ohci
May 30 21:10:10 mini2440 kernel: hub 1-0:1.0: port 1 disabled by hub
(EMI?), re-enabling...
May 30 21:10:10 mini2440 kernel: usb 1-1: USB disconnect, device number 15
May 30 21:10:10 mini2440 kernel: usb 1-1: new full speed USB device number
16 using s3c2410-ohci




and when the system freeze @ 15:50 and reset @ 17:52




May 30 13:55:05 mini2440 kernel: usb 1-1: new full speed USB device number
9 using s3c2410-ohci
May 30 13:55:05 mini2440 kernel: usb 1-1: device descriptor read/64, error
-62
May 30 15:05:05 mini2440 kernel: usb 1-1: USB disconnect, device number 9
May 30 15:05:05 mini2440 kernel: usb 1-1: new full speed USB device number
10 using s3c2410-ohci
May 30 15:50:06 mini2440 kernel: Unable to handle kernel paging request at
virtual address a0000090
May 30 15:50:06 mini2440 kernel: pgd = c04e4000
May 30 15:50:06 mini2440 kernel: [a0000090] *pgd=00000000
May 30 15:50:06 mini2440 kernel: Internal error: Oops: 80000005 [#1]
May 30 15:50:06 mini2440 kernel: last sysfs file:
/sys/devices/virtual/gpio/gpio166/value
May 30 15:50:06 mini2440 kernel: Modules linked in:
May 30 15:50:06 mini2440 kernel: CPU: 0    Not tainted  (2.6.39.1 #1)
May 30 15:50:06 mini2440 kernel: pc : [<a0000090>]    lr : [<c03729a0>]   
psr: a0000093
May 30 15:50:06 mini2440 kernel: sp : c106dde8  ip : c033f000  fp :
00008000
May 30 15:50:06 mini2440 kernel: r10: 000319cd  r9 : c1193a80  r8 :
c13a3c60
May 30 15:50:06 mini2440 kernel: r7 : 319cd18f  r6 : 00000000  r5 :
c03729a0  r4 : c348af80
May 30 15:50:06 mini2440 kernel: r3 : 00000014  r2 : 00000000  r1 :
40000013  r0 : 000019cd
May 30 15:50:06 mini2440 kernel: Flags: NzCv  IRQs off  FIQs on  Mode
SVC_32  ISA ARM  Segment user
May 30 15:50:06 mini2440 kernel: Control: c000717f  Table: 304e4000  DAC:
00000015
May 30 15:50:06 mini2440 kernel: Process check_solar_tim (pid: 27833, stack
limit = 0xc106c270)
May 30 15:50:06 mini2440 kernel: Stack: (0xc106dde8 to 0xc106e000)
May 30 15:50:06 mini2440 kernel: dde0:                   00000000 c3ba7020
c3bddd00 c00626c0 00000020 00000000
May 30 15:50:06 mini2440 kernel: de00: 00000000 c106de48 c13a3c60 c348aed0
c3b6d700 00000000 c03729a0 00000000
May 30 15:50:06 mini2440 kernel: de20: 319cd18f c13a3c60 c3ba7020 00000000
00008000 c00763a4 3180918f c1193a80
May 30 15:50:06 mini2440 kernel: de40: 00000000 00000200 00000000 00000000
00008000 c03729a0 22a99d6b 00000000
May 30 15:50:06 mini2440 kernel: de60: c3ba7020 00008000 c13a3c60 00008000
00000000 00000000 c1193a80 c0076fe4
May 30 15:50:06 mini2440 kernel: de80: 00000000 00000000 00000000 c008e6ec
c3b6d900 c106dfb0 fffffffe 00000000
May 30 15:50:06 mini2440 kernel: dea0: c04e4000 00008000 c04e4000 c1193a80
00000000 c13a3c60 bea62b3c c007776c
May 30 15:50:06 mini2440 kernel: dec0: c04e4000 00000000 c13a3c60 00008034
c126aa80 c1193a80 00000017 c106dfb0
May 30 15:50:06 mini2440 kernel: dee0: c1193ab4 c0027ed8 00008034 00000017
c02ef01c 40025050 00000017 c106dfb0
May 30 15:50:06 mini2440 kernel: df00: 00008034 00000001 6474e552 c00222d4
c02f2990 00000000 c106df3c c0032db0
May 30 15:50:06 mini2440 kernel: df20: 00000f50 80000093 c3835fa4 c02f6988
00000000 00000001 c106df6c c004b77c
May 30 15:50:06 mini2440 kernel: df40: c3835fa4 c0030980 00000000 20000093
000befe8 0095dd88 00000001 c126aa80
May 30 15:50:06 mini2440 kernel: df60: c383401c c126aa80 00000017 c3824d20
0104f000 40024db0 c1193a80 00000000
May 30 15:50:06 mini2440 kernel: df80: c1193ab4 c106c000 00000000 c007c908
40025000 40024db0 ffffffff 40025050
May 30 15:50:06 mini2440 kernel: dfa0: 40025000 00000000 00000000 c0022ec0
00008134 00000050 4002560c 40025600
May 30 15:50:06 mini2440 kernel: dfc0: 6474e551 40025050 40025000 00000000
00000000 00000001 6474e552 bea62b3c
May 30 15:50:06 mini2440 kernel: dfe0: 00008034 bea627f8 00008034 40002490
80000010 ffffffff 00000000 00000000
May 30 15:50:06 mini2440 kernel: Code: bad PC value
May 30 15:50:06 mini2440 kernel: ---[ end trace a9491bee312f1f5f ]---
May 30 15:50:06 mini2440 kernel: hub 1-0:1.0: port 1 disabled by hub
(EMI?), re-enabling...
May 30 15:50:06 mini2440 kernel: usb 1-1: USB disconnect, device number 10
May 30 15:50:06 mini2440 kernel: usb 1-1: new full speed USB device number
11 using s3c2410-ohci
May 30 17:52:17 mini2440 kernel: imklog 3.18.6, log source = /proc/kmsg
started.
May 30 17:52:17 mini2440 kernel: Linux version 2.6.39.1 (root@testbox) (gcc
version 4.3.2 (Sourcery G++ Lite 2008q3-72) ) #1 Sun Jun 19 22:32:25 CEST
2011
May 30 17:52:17 mini2440 kernel: CPU: ARM920T [41129200] revision 0
(ARMv4T), cr=c0007177
May 30 17:52:17 mini2440 kernel: CPU: VIVT data cache, VIVT instruction
cache
May 30 17:52:17 mini2440 kernel: Machine: MINI2440
May 30 17:52:17 mini2440 kernel: Memory policy: ECC disabled, Data cache
writeback
May 30 17:52:17 mini2440 kernel: CPU S3C2440A (id 0x32440001)
May 30 17:52:17 mini2440 kernel: S3C24XX Clocks, Copyright 2004 Simtec
Electronics
May 30 17:52:17 mini2440 kernel: S3C244X: core 405.000 MHz, memory 101.250
MHz, peripheral 50.625 MHz
May 30 17:52:17 mini2440 kernel: CLOCK: Slow mode (1.500 MHz), fast, MPLL
on, UPLL on
May 30 17:52:17 mini2440 kernel: On node 0 totalpages: 16384
May 30 17:52:17 mini2440 kernel: free_area_init_node: node 0, pgdat
c0308f24, node_mem_map c033f000
May 30 17:52:17 mini2440 kernel:  Normal zone: 128 pages used for memmap

i dont understand why this happend when i switch the realy off.
the gpio direction is out, and switching off means no voltage on the pin,
why is the usb connection droped and why does the system freeze after some
time.

must be some kind of electric stuff i think, but i donīt understand a much
about that.

any idees?

regards john

davef
> the error only appears when the solenoid valve are connected to the pin.

Got a schematic?

Which pin?  The GPIO or some pin on your relay board?

John
hi dave

donīt have a schematic, only photos ;-)
some electric ing. set it up for me.

http://s14.directupload.net/images/120531/2yyjlwop.jpg
http://s1.directupload.net/images/120531/39mwhqsr.jpg
http://s1.directupload.net/images/120531/jn4q2kmw.jpg
http://s7.directupload.net/images/120531/jl2mti4g.jpg
http://s7.directupload.net/images/120531/ydhfp2z2.jpg
http://s7.directupload.net/images/120531/9txozo6f.jpg

yes i mean the gpio pin.
doesnīt matter which gpio pin i user, when the solenoid valve is connected
to the relay(K3 or K4) this happen, when the bulb is connected to K3 or K4
not.

relay K3 and K4 is the 24V outputs, K3 is my valve at the moment and k4 the
bulb.
K1 and K2 is just simple relays for switching the garden lights and a water
pump. 

i donīt understand why this happen. 
switch the gpio off means for me no voltage on the pin from the controller
side, 
does some noise getting on the gpiopin from the valve/relay side.

the gpiopin direction is out, does some noice coming in on the pin pass
throug to the board?

why does it only happen with the valve and not the bulb, same trafo and
output on K3 and K4

the guy told me the diodes between the relays and wire to the gpio pins are
very importand,
when the relay is switched off the noice run off over the diodes or
something like that, not my world.

any idees?

davef
> the guy told me the diodes between the relays and wire to the gpio pins
> are very importand,

Looking at the pictures I think what you mean is that "the transistor
drivers between the GPIO pins and the relays are important".

The diodes across the relays are there to protect the transistors.

It looks like the relay drivers have been built correctly.  At first I
wondered how these two boards grounds are connected together and then I saw
the fifth brown wire running along the inputs to the driver transistors.

I guess the thick white cable are the two wires going to the external
relay.  

I would then look at how the ground side of the that relay is connected to
the relay board ground.  Also, I would not rely on all your relay board
grounding on that one brown wire connecting the relay board to the GPIO
connector ground.  I would try connecting the relay board ground connection
to one of the corner brass posts on the right side of picture #1.

All relays generate back-EMF when they turn off and this can induce
unwanted spikes or noise into your board.
   
I would also try placing a diode across the external relay like the guy has
done on the 4 relays on the board . . . with the correct polarity of
course.

John
hi dave

the 4 relays K1 K2 K3 and K4 are connected
K1 garden light - thick white cable
K2 230V water Pump
K3 valve
K4 bulb

no other relays and ground as you said the brown cable.
so you think the ground could be the problem

Thx for your time!
john

davef
Or back-emf from your valve. Sorry, I been saying external relay when I
should have said your external valve.

The fundamental fact is that a solenoid valve is very similar to a relay in
that they both have coils.  When your valve switches off you could get
spikes on your ground system.  Try a "catch" diode across the valve.

Dave McLaughlin
Hi John,

As a follow up to Dave's excellent help, where does the Mini6410 get it's
power from?

Is this via the original power supply or is this being powered from the
relay board?

As Dave points out, if your system starts to miss-behave when the valve is
connected (I assume actually when it is switched off or on?) then it is
inducing spikes to the supply and this will likely knock out your Mini6410
power supply. If the Mini6410 is being powered from it's own supply, you
could try running this via a surge protection block or better still, as a
test, via a UPS.

If this is the case, then a protection diode across the valve will help (I
assume from the 24V that this is a DC supply?) Wire this the same polarity
as the ones on the relays.

Dave...

john
hi daveīs

the mini2440 got ist own power supply.

the valve got 24V/AC, it is this one over here

http://www.magnetventile-shop.de/magnetventile-2/magnetventile-kunststof...

ok then i will try the protection diode across the valve,
donīt have something like that here.

John

Dave McLaughlin
As you are switching the AC valve with a relay, you don't really need the
diode protection as there is no semiconductor to protect. In fact, with AC
it won't work as you have positive and negative polarity effectively on the
relay.

This sounds more like a common ground issue than anything else. This is
what Davef already pointed out before. Ground faults can be hard to
diagnose and sort out.

I had a microcontroller doing exactly the same thing controlling a boilers
AC relays with no issues of crashing. I used a smaller relay to switch a
220Vac relay and no issues with back EMF as per our thoughts above. The DC
relay on the board had a diode and transistor etc but the 220Vac relay was
simply connected to the switched terminals. No back emf issues as it was
not connected to anything else.

Dave...

sean_h
In the real world you typically switch via opto-couplers. You then avoid
ground issues.

Dave McLaughlin
Another option Sean_h is to use solid state relays when switching AC. The
types with zero crossing detection are even better.

I have used this very type of device to switch a water heater on and off
from a microcontroller with no issues whatsover.

John, how much work would be involved in changing this to opto-coupled as
per sean_h's idea?

Dave...

John
Like I said I dont understand a lot of Electric :-((
wouldnt be able to do that without a howto for Dummys.

Anoughter question,

The mini2440 got its own powersupply, but there is no ground Connection at
the powerplug side,
how is the mini2440 grounded?

The relayboard is also not grounded from the powersupply side, only N and L
connected.

Can I connect ground like Dave suggest

I would try connecting the relay board ground connection
to one of the corner brass posts on the right side of picture #1.

and connect the brass posts to ground from the powerplug side?

Dave McLaughlin
Hi John,

Be careful what is being referred to as ground. What davef and I were
talking about is the DC ground. To make the relays switch (as they are on a
different supply to the Mini2440) you have the connect the ground on the
Mini2440 to the ground on the relay board (your brown wire in this case)

The earth connection at the AC plug is not the same ground, although it can
be connected but in most cases is kept isolated from the DC ground unless
designed so. Normally this is only connected to metal bodies of the
enclosure if there is one.

You only have the one brown wire but as the current drawn from the GPIO and
as this is only using a very small this should be sufficient.

One thing I have picked up is the routing for the control lines from the
GPIO. You want to make sure this is routed well clear of any AC wiring,
including close proximity to the transformer. Try routing this away from
the AC part of the design and if you can, get a short length of screened
cable and connect the screen to the ground (brown wire connection) as this
will reduce any pickup on the GPIO lines if this happens to be where the
issue is.

You must always route low voltage wiring, be it AC or DC away from high
voltage. This is what is referred to as the low voltage directive and is
for immunity as well as safety.

Dave...

davef
The 24Volts AC only goes to the switch contact on the relay  and then to
the valve, ie there is no connection between this supply and ANYTHING else?