Electronics is fun
even making it.
Really!
Beleive
me!
Even when it does look only tedious, error-prone and boring.
Its fun.
(if I keep repeating that to myself, I will start to beleive it again, I guess).
Actually, I have a lot of fun making something electronic, every time.
Constructing a wedding present
We have
all these are pretty much no-brainers.
The LCD is a well-known thing and libraries exist to drive it.
The
LCD just needs 7 port pins to connect to the µC
(Microcontroller). Solutions exist to use less pins by using port
expanders but on a simple project like this one, we should have 7
pins available, right?
The rotary dial is basically two
switches with one common pin.
When you connect the common pin to
ground and the two others to port pins on the µC, you are all
set to decode the numbers dialled.
The 3-position switch that came with the lamp is connected in the same way as the rotary: the middle pin to ground, the two others to port pins, this way the µC can tell the position lfet-middle-right of the switch.
We also have
that still need control.
The 12V/10W bulbs in the lamp will run
on DC as well as AC (glow bulbs are so wonderfully simple. As simple
as they are inefficient for making light :-). And when the DC is
pulsed, we can easily control the brightness.
So the lamps will be
controlled by a PWM
signal. The AVR
Mega8 processor I am using on every project like this one will
generate up to 3 different PWM signals in hardware, so that is easy.
The lamps use considerably more power
than a µC pin can provide, so we need some amplification.
If
you understand electronics, you may want to stop reading, becaus my
solution is somewhat underengineered1.
But
I like it: it is simple, cheap and works quite well :-)
I simply drive the gate of an IRLIZ44N MOSFET from a processor pin. With the processor running from 5V this is enough to switch the transistor on and off and the processor pin can source and sink enough durrent to charge/discharge the gate fast enough. At least at the low switching frequencies we use here.
Everything but the motor is covered
now. All with solutions I had done or used before.
A motor I had
never driven from a µC myself. That is one of the reasons I
wanted to use some electronics here, to learn about that.
Googling and researching a bit I found
there is one standard solution to driving a motor that everybody and
his dog uses.
The L293D
chip includes the power transistors to drive motors up to 600 mA
current consumption.
My motor uses at most 300mA so we are on the
safe side here.
The chip is pretty simple to use: 3
port pins drive the enable and the two direction inputs. When both
direction inputs have different logic value, the motor turns, when
they have the same value the motor is stopped (and acts as an
electric brake).
The enable can be driven by a PWM signal again to
control rotational speed of the motor – perfect.
I am actually using the PWM to
soft-start the motor (ramp up the voltage slowly). This makes the
sound and motion appear very smooth, not jerky.
I also use the PWM
control to use less voltage when closing the box; this way opening
(lifting) and closing (lowering) the box works at pretty much the
same speed. Applying maximum voltage when closing makes the closing
process visibly faster than opening – and that gives an
underpowered or chinese-engineered look :-)
Lets heat up the soldering iron
Why is that thing still called a soldering iron? There is no iron in there nowadays, right? Whatever.
|
|
First order of business: place all the parts on the PCB to get an impression of the space required.
Looks fine to me. „There is lots of space in this mall“ (Jake to Elwood) We can not see the motor control IC here, because I did not have it in stock on the week-end when I started soldering :-)
|
|
|
Every appliance is only as good as its power supply. Thoses wise words appeared in Elektor magazine in 1971 (I think). I learned of them as a frequent citation when I started working profesionally (i.e. getting paid for it) electronics in the mid-80ies of the last century. In order not to learn that again the hard way, I started with the power supply part of the controller board. The SB360 diodes in the rectifier are choosen for a very good
reason: they were in stock. |
|
|
Wiring up the 6-pin header for flashing the firmware and the 10-pin header for the display is pretty straightforward. Or it should be. I found the error (a good thing the programmers are so robust: nothing burnt out :-) and fixed it. At least I wanted to. But somehow I managed to leave out the connection from
processor ground to the power supply ground. |
The type of wiring I use here is known as „Fädeln“ in german. The small copper-coloured wires are 0,2mm strong copper wires with an enamel insulation that can withstand about 60V. Therefore the wires may cross each other without forming a connection.
For a small circuit like this one this
method is much faster than making a layout and etching a PCB. It also
avoids messing with chemicals lile FE-III-Cloride.
Debugging that
stuff can be quite annoying, though.
The enamel insulation is supposed to
melt and burn at 300°C, so the 370°C hot tip of the soldering
iron should burn it right off, exposing the raw copper below. That
copper the tin then bonds with forming a solder joint.
But the
stupid stuff does not know that and sometimes does not burn off –
so the joint looks like it is soldered but the electrical connection
is not there. Grummel.
|
|
I love the crimp connectors. It is soo simple: fiddle a piece of flat-ribbon cable in the opening between the bottom and top half of the connector, close the vice all connections are made at the same time. Unless you hat the ribbon cable in there not properly aligned or not exactly orthogonal :-) If you do this at home:
I did after about 2000 crimps or so :-) |
|
|
Soldering the 10 pins to the display takes so much longer than crimping the other side... The two black blotches are PU-resin poured on the chips on the board. These chips are soldered to the board without an IC housing and then covered with PU. This type of assembly is found only on stuff made in rather large quantities (like pocet calculators and LC displays). I sometimes wonder, why it is not used more frequently. |
|
|
Anyway. Once all joints are made, the mirrored pinout corrected and the missing ground wire is foud and replaced...
... a first simple firmware can actually show „Erster Test“ on the display. So this works.
|
End-Switches: Electronic or mechanic?
We will have limited-length linear
motion on this project.
We must limit the motion of the drawer,
the motor must turn off at tow points.
Reliably.
Or the whole thing will self-destruct.
Reliable sensors for the end positions are...
Well, there is a very good reason why
the big CNC machines
almost always use inductive end-switches.
Mechanical switches are very reliable.
My mouse has two and they always work – unless I am targeting a
boss mob in WoW.
Mechanical microswitches are very
reliable – unless used in one of my projects.
They never work there.
|
|
I want something else this time. Hmm, the CNY70 looks promising. Basically it is an infrared LED nad a phototransistor in one
package. The simple appliction is to connect the IR-LED to a power
source and the phototransistor to a processor port pin (with a
pullup). A Schmitt-Trigger provides that. |
|
|
A complicated selection process led to the TL061C operational amplifier which would become the base for my Schmitt-Trigger. The selection process involved looking through multiple biscuit boxes full of left-over electronic parts from older projects. One box that has parts in there I did not use for like 20 years. There I found the 061 single-opamps :-) Had I not found them, each end-switch would have ended up with a Schmitt-Trigger made from one quarter of an LM324 which is the usual opamp I am using. The breadboard setup pictured above allowed me to quickly experiment with different values for the resistors and see the effect. This method of finding the right values for components for an application is frowned upon in the academic cicles all the time. But it is providing resulsts faster by a factor of 10 compared to running simulations :-) |
Always remember the wise words my first boss told me when he found me using pen and paper to find the proper values for the feed-back resistors on an Opamp-based amplifier:
„The experiment is a well-accepted scientific method for gaining knowledge“
Or in other words: just try it. If smoke appears, try something else. :-)
The circuit above gives me an
optical-end-switch with a pretty good sesitivity. It will trigger
when the reflecting surface is about 5mm above the CNY70.
The
hysteresis is about 3mm: the signal will switch again when the
reflecting surface has moved away to 8mm above the CNY70.
Even if the drawer is vibrating when
moving or the movement is a little jaggy, the vibration will not
exceed 3mm for sure.
The processor should see a very stable
„destination has been reached, turn off motor“ signal.
|
|
So its time to move from breadboard experiments to PCBs.
Since I need two end-switches, I make them at the same time. Note the lead-free solder and the good old „Fädelstift“. |
|
|
And when both are wired, they are cut out of the larger PCB. The connector on the solder side of the PCB was an afterthought – a useful one :-) Please note the lack of PCB space to put mounting holes or the
like. |
|
|
Even the fairly large components
used here can create some challenges for soldering. I di not use a microscope for soldering for a very simple
reason: I do not have one. |
Wiring it all up
with the controller board and
end-switch modules finished it is time to wire it all p for the first
time and see if the motor actually runs.
And – surprise? -
it does and creates exactly the right sound: audible but not too
loud.

Firmware
Time to get started on the
firmware.
The firmware takes input from the rotary dial, controls
the motor (stop, direction, speed), test for end-switch conditions
and control the light (brightness).
The firmware also reads some values
from the EEPROM in the processor and displays a riddle to be solved
before the box opens for the first time.
And while we are at the
EEPROM anyway, it also remembers the last setting for the lamp
brightness.
After solving the riddle the user can
choose to enter a 6-digit pin. Once that is set, it can be used to
open the box without entering the solution to the riddle.
I admit:
the PIN-feature I put in just for me, so I could test the mechanics
without solving the riddle all the time :-)
|
|
The orange LED stands in for the lamp while experimenting. The reason is that the space on my desk is a bit limited.
I bet, SMD technology (you know: the stuff with the components you can hardly see if you are older than 40) was invented to allow for even smaller lab spaces :-)
In the back the AVR Studio application is already open, GCC is primed and ready. My trusty ol Cherry keyboard takes up some valuable space2. The dark spot between the two monitors is home to my Weller soldering iron and to the right in the back you see my lab power supply. |
|
|
But most my experiments are powered from my PC. PC type power supplies provide very stable 5V and 12V with really high output (current-wise) and they are dirt-cheap.
So my PC has outputs for 3,3V, 5V and 12V on the front panel. Comes in handy when experimenting with electronics :-) The flimsy-looking black and white wires running up to the desk are actually puwering the wedding-box-controller. |
Features
All my programs for µC end up to be some state machine.
There must be a reason to that and it may be very interesting for
some psychiatrist – but for me that is just the way I program
:-)
Basically all µC programs are endless loops and my main
loop typically has some code checking stuff (i.e. Flags from ISRs)
and then goes into a switch(state) {}.
On powerup the firmware checks the 3-position-switch.
In middle position, we are in idle state: stop motor, display „Ready“, load the last-remembered brightness value into the timer compare register and that is it.
Switch in left position activates the dimmer function.
In this
state the display shows „Dimmer“ and the rotary dial
becomes a 10-level dimmer. Level 0 switches off the lamp alltogether,
level 9 is 100% power, the other are somewhere in between.
The
value is stored in EEPROM every time it is changed.
The switch in the right position brings the firmware into motor
control mode.
This mode can be left only by entering something or
poweroff. That is a feature, not a bug!
In motor control mode I first check if the riddle was solved before and a PIN has been stored. In that case the display shows „PIN“ and the controller reads 6 digits. The box opens with the correct pin.
If the riddle was never solved, the Display shows „Zauberwort“
and a blinking cursor in the second line.
Now the user must enter
the solution (which is „SESAM“, the german equivalent of
„SESAME“ as in „Sesam öffne Dich“ or
„open sesame“).
This is done by entering letters with the rotary dial. A mobile phone came in handy for the bride and groom when they tried to figure it out.
I had a really good time watching them fiddling with my contraption :-)
The digits 2 to 9 produce the usual letters we all know from
entering SMS messages without the T9 dictionary. The digits 1 and 0
move the cursor one position forward or backward respectively.
Once
the user has figured out to dial „77771331777712161“ the
diplay shows „richtig!“ and one second later the motor
starts.
The motor is started with approximately 50% duty cycle on the PWM,
the cycle is increased a bit every 2 microseconds. That creates a
nice soft start and the movement ramping up to full speed.
The
motor is run until the end-switch for „open“ triggers or
a timeout is reached. The timeout is really important: I had the
end-swtich disconnected on one test and without the timeout, the
motor would have done something very destructive.
Once the box is open, the user is kindly asked to place the
3-position switch in the middle position again. That triggers the
closing.
Again the motor is run starting at 50% duty cycle and
ramping up to about 86%, so the motor gets less power on closing.
That makes it run about the same speed as in the opening cycle.
Again
this runs until the end-switch fires or a timeout is reached.
1Actually, it is quite well-engineered, since I had a plan B using the motor driver to drive the gate with full 12V – but the direct drive turned out to be sufficient.
2No,
the keyboard is not broken.
Actually, all other
keyboards that do not have an adjustable gap in the middle, are
broken!
If you find a source for this Cherry keyboard, the
adjustable ergonomic model MX 5000 aka G80-5000, mail me! I want one
more! Two! Paying well!