Wednesday, June 25, 2014

Solar Regulator Testing

A quick post today.  I've been roped into another project for my Dad.  This time he wants to use a solar panel to keep a battery on a generator charged.  Before installation, I wanted to test how it performed as I had suspicions about the quality of the solar regulator.

To test the panel it was set up at ground level pointing to the north (southern hemisphere) on the installation bracket.  An old electrical cable was used to connect it to the regulator that was protected from the weather.

Solar Panel
Solar Panel in Test Position

Cheap Regulator Under Test
The connections are simple.  Two wires come from the solar panel, two go to the battery, and two go to a load that only comes on at night, I connected a low power 12 V LED strip to this terminal as an indicator.  When the voltage from the solar panel drops below a certain point for a set amount of time, the regulator switches to night mode and turns the light on.  Under test this feature didn't seem to work.  The load seemed to stay on permanently, day and night, this was enough to make me question the operation of the whole device.  Over the week of testing it didn't seem to charge the battery at all either.

I've since learned that some regulators discharge through the solar panel at night if a diode isn't installed.  This seems ridiculous to me.  That should be built into the regulator.  So it's possible that it was charging during the day and discharging at night.

Cheap Regulator
As the operation and construction of the regulator seemed a bit iffy, I decided to just buy another one.  I got a decent quality one from Jaycar, the MP3720.  This one also has an extra wire that lets the regulator know if it's charging a wet or sealed battery, this seems to just set a different charge voltage.  For a wet battery it's connected to the negative terminal of the battery, for a sealed battery it's left unconnected.  The regulator is also constructed well, it's potted for splash resistance and it feels solid.

Jaycar regulator
I've connected the new regulator and have been testing it for the last couple of days.  The battery seems to be charging, the night light hasn't come on yet, but I think the battery voltage is still too low for that to happen.

I think this will do the job,  I should know after a week or two of testing.
MP3720 under test

Saturday, June 14, 2014

12 Volt Reversal Switch with Dynamic Braking

As you may or may not know my father has a few mobility problems, and a while back he built a winch controlled platform to help him get in and out of the bath.  Up until now there haven't been any problems with it, but recently the momentary switch has started to show intermittent problems.  It still raises and lowers the winch, but it has an extra function that isn't working well.  When the switch is released it returns to the centre position and places a short across the motor.  This is important because it adds something called "Dynamic Braking" to the winch.  When you short out a motor like this it's equivalent to putting a brake on it, if you leave it open circuit the winch won't hold loads and will slowly lower what it's holding.  In this case that is my Dad.  Getting in and out of a bath on a platform that slowly sinks is almost impossible.

We've had this problem before, but were able to clean out the switch and get things working again.  I would have liked to replace the switch but the dynamic braking feature can't be replicated with a normal DPDT switch, and I can't find a replacement anywhere.  Even though I'm holding one in my hand everyone I've spoken to says they don't exist.

Switch
Original Winch Switch
I could have bought something like the product below, but with shipping it would have cost me around $100, and if it were to brake somehow, it's not easy to get hold of another one.

Reversing Module
http://www.cncelectrical.com/servlet/the-13234/Cole-Hersee-Solenoid-Reversing/Detail
Last time this happened I came up with a contingency plan using standard off the shelf automotive relays, so I dusted that off, made some improvements and started building.

I had a few requirements when designing the system.  It had to made of easily obtainable parts, and it had to be reasonably easy to service.  In case I'm not around Dad can fix it himself.  It also had to be as waterproof as practicably possible.  This was to prevent the same problems with water ingress that caused the last one to fail.  This is what I came up with.

Electrical Enclosure
Relay Operated 12 Volt Reversal Switch with Dynamic Braking
This was a difficult project, technologically, it's far from ground breaking, the biggest problem was trying to source quality components from places like ebay and the local electronics store at a reasonable price.  Nothing was exactly what I wanted, I just had to make do with what I could get.

The first thing I had to do was determine the current draw of the motor.  Since I didn't have a meter that would measure such a high current I had to build an adapter.  It turns out that the maximum current draw is about 25 Amp.  Although I would have liked a bit of headroom, I used this as my design current.  All the components I could easily source were rated for 25 Amp or higher, and since it's not in continuous operation, I'm happy with that.  It might only operate for a maximum of 30 seconds at a time.

The operation of the circuit is pretty simple, it consists of two relays and a momentary SPDT switch with a centre off position.  The diagram below shows the operation of the circuit.  It should be familiar to anyone with an electronics background.  It's a H bridge motor controller, but with one important benefit.  By using relays instead of semiconductors, it's impossible for shoot through current to occur.

When the switch is in the centre position none of the relays are energised, connecting both of the motor terminals to the negative supply line via their normally closed contacts.  This shorts out the motor implementing the dynamic braking feature.

Circuit Diagram
Reversal Switch in the Braked Position
When relay 1 is energised, the motor moves forward.  It's negative terminal is still connected to the negative supply line via the normally closed contact of relay 2, while the positive motor terminal is connected to the positive supply line via the normally open contact of relay 1.

Circuit Diagram
Reversal Switch in the Forward Position
When relay 2 is energised, the current though the motor is reversed.  It's negative terminal is connected to the negative supply line via the normally closed contact of relay 1, while the positive motor terminal is connected to the positive supply line via the normally open contact of relay 2.


Circuit Diagram
Reversal Switch in the Reverse Position
To control all of this I used a cheap pendant switch from ebay.  It's rated to 250 Volt, 5 Amp, personally I wouldn't trust it at that voltage, but for a 12 Volt, 100 mA signal it's fine.  It claims to have a mechanical interlock that prevents both the up and down connection being simultaneously pressed, but I've been able to press them both at the same time.  In this design that doesn't matter, all it does is active both relays and connects both terminals of the motor to the positive supply effectively braking it.

Switch
Pendant Switch
The inside is straight forward.

Switch
Pendant Switch Internals
Annoyingly I couldn't get a rubber boot to fit a small cable.  Apparently they exist but I couldn't source one.  I intended to use an old extension cable I had, but it was too small.  The easiest solution was to just get a half inch 4 core cable and use only three of the cores.  A bit wasteful, but it got the job done.

Cable Seal
Pendant Switch Rubber Boot
Finding a cheap enclosure with a rubber seal was hard enough, so it was rather annoying when it came time to install the cables and the threads on the glands were too small to fit through the case.  I had to hack together a bit of a milling machine to create a recess in the case to make everything fit properly.

Electrical Enclosure
The Milled Recess to accommodate the Cable Glands
Installation of everything required a base plate and some mounting brackets.  How I went about that is described in a couple of past posts.  DIY Relay Brackets and Waterproof Enclosure Mounting Plate.  I did have to slightly change how the relays were mounted to create more room.

There isn't anything special about the relay.  It's something that can be sourced from pretty much any automotive supply store.

Relay
30 Amp Changeover or SPDT Relay
Even though this is personal project, I wanted to try to do everything as professionally as possible.  Within reason of course.  One thing that really bugs me are uninsulated crimp terminals, so all of mine are insulated.  If something works itself loose, it can't short out on other terminals.

Wiring
Insulated Terminations
Even the large terminals on the terminal block are heat shrunk.  I initially tried to make my own terminals, but came to my senses pretty quickly. DIY Eye Terminal Proof Of Concept and Bending an Eyelet Terminal Without Tearing the Metal describe how I went about doing things.

The terminal block may seem a bit redundant, and your right, it is.  In most cases the cabling could be easily connected straight to the relays, but I feel this will make it easier for my father to service it.  The main board can be easily removed and serviced on a bench.

Wiring
Terminal Block
After wiring up all the connections I realised I had made a mistake.  It wasn't bad, but when the circuit was in the braked position, both terminals were connected to the positive terminal of the battery to give dynamic braking.  There is nothing wrong with that electrically, but from a corrosion protection stand point it isn't great.  The constant 12 volts on the motor in a humid environment is likely to promote corrosion.  This was easy to solve though by swapping the normally closed contacts of the relays to the negative supply rail.  This also reversed the direction of the motor and was fixed by swapping the positive and negative motor connections on the terminal block.  The images above reflect the way the circuit was originally connected before the changes, but the circuit diagrams above are correct.

A bill of materials and a wiring schedule for this project can be found here.  Hopefully this will make future maintenance easier.  The diagrams below are used as a reference in the wiring schedule.

Wiring Diagram
Annotated Terminal Block diagram

Wiring Diagram
Annotated Pendant Controller Diagram
I'm quite happy with how this turned out.  The total cost was 140 dollars.  Although that seems high, by the time I purchased an off the shelf solution and put it in an enclosure it would have cost more and replacement parts would have been harder to get.  Most importantly Dad can get out of the bath easily again.


Tuesday, June 3, 2014

Imitating a Bar Code with a Modulated LED

You may have seen recently that I've been playing around with bar codes.  Mostly just figuring out how they work and how to encode certain characters, now for the fun part, I've finally got some hardware to play around with.  I bought myself a cheap USB laser scanner off ebay for about $20.  It's not going to be anything fantastic, but it'll be good enough to test a few ideas I have.

Bar code scanner
USB Bar Code Scanner
One of those ideas is, can I use an LED to impersonate a bar code?  Or more specifically can I create a dynamic bar code?  By taking the bar code out of the system, can the scanner be fooled by an LED flashing the reflected light pattern?

First a small refresher on how laser bar code scanners work.  A laser beam is swept back and forth over the code.  If the laser light hits a white area, light will be reflected, if it hits a black area, less light is reflected.  A photo-diode in the scanner constantly measures the intensity of this reflected light, and with further processing the scanner is able to decode the bar code.

I plan to use an LED controlled by a micro-controller to flash the pattern of the bar code at the scanner.  The speed of the pulses first needs to be determined.  To impersonate a bar code, the message transmitted by the LED needs to fit within the time period of either a reverse or forward scan, this is the period of message that the scanner is designed to detect.  As there was no data in the manual, this had to be done empirically.  A voltage divider where one leg is a light dependent resistor (LDR) will do the job.  Aiming the scanner at the LDR will allow the scan rate to be determined.  The image below shows the set-up.  The values aren't important, all that matters is that we can observe a voltage change when the laser sweeps across the LDR.

Circuit on a bread board
Light dependent resistor voltage divider
The scope display below shows the results  The time for the laser to sweep back and forth is about 44ms.  This means the message has to be transmitted in at least 22ms, but to leave some wriggle room, I'm aiming for 7ms.

Oscilloscope display
Output from the LDR circuit
So, what's the message?  I'm going to be sending the string "Test <Carriage return>123".  Encoding this as a code 128 bar code gives the following pattern.  A zero represents a white space of width 1 unit, while a one represents a black space also of width 1 unit.  A quiet zone of all white has also been added at both ends of the bar code.

00000000 01101001 00001101 11000101 01100100
  0x00     0x69     0x0D     0xC5     0X64

00101111 00100100 11110100 11110100 01011110
  0X2F     0X24     0XF4     0XF4     0X5E

11101010 01110011 01100111 00101100 10111001
  0XEA     0X73     0X67     0X2C     0XB9

11101011 10110001 11010110 00000000
  0XEB     0XB1     0XD6     0X00

As a printable code it would look like this.

Bar Code
Bar code containing the string "Test <carriage return> 123"
To quickly prototype the design, an old ATMega 128 development board was used.  An LED in series with a couple of resistors was connected to a pin on port D.  The values aren't really important as long as they limit the current through the LED to a safe amount.  In a real design you would take time to choose resistor values to optimise performance.

To get stable timing, an internal timer was used to trigger interrupts that in turn control the LED.  The bar code has 152 (19*8) bars, this means that for a total message time of about 7 ms, the period of each bar is approximately 46 us, this value was used to set the timing interval for the interrupts.

Development Board
Prototype set-up
The code used to flash the LED in the above pattern is pretty basic.  There's nothing fancy in the code, just the basics.  It's only a proof of concept after all.  I'm trying to learn git and github so I've created a repository containing the code here.

Circuit on a breadboard
Modulated LED in action
I've put together a small demonstration showing me scanning the bar code and then scanning the LED.  It's sensitive to position, and although some of this could be calibrated out, I think this is mostly a problem with the cheap scanner.  I think better performance could also be obtained by synchronising the transmitter to the sweeping laser.  Photo-diodes could be used to do this by dynamically, adjusting the length of the transmitted pulses and also varying the start time of pulse transmission.

I believe an increase in performance could also be obtained through component selection and using a PCB.  The LED used was something I had laying on my desk, when switched on it may have large rise and fall times leading to poor performance.  Choosing an LED designed for fast switching might make a difference.  The prototype also has long jumper leads everywhere, adding inductance to the already capacitive breadboard, this could also affect the switching characteristics of the LED.

EDIT While doing further research on this topic I found this site on Barcode Fuzzing.  Basically the same thing I'm doing, but a little more advanced.