I was looking for a way to add a human interface to my projects at low cost. Using touch sensitive inputs means that there are minimal wiring requirements, as all the components can be included during pcb manufacture.
My projects may be battery powered, so I cannot rely on the project and the person sharing the same ground – when they touch an input having a different ground reference they are unlikely to be recognised.
With battery powered projects, it is necessary for the capacitance of the finger to affect a measurement made with respect to the project ground. One way is to create an oscillator, and have the capacitance of the finger change the tuning of the oscillator to make it oscillate at a different rate. Counting the number of oscillations in a given time gives an indication of whether a touch is occurring or not.
I chose to use the capacitance divider method, as it was simple to understand and to wire up.
The process is to charge up the ADC capacitor, which is present on the input of the ADC on all micro-controllers, and then parallel it with the capacitance of the touch plate.
The charge on the ADC capacitor will be divided between the capacitance of the ADC capacitor and the touch plate capacitance. If they are equal, the initial charge on the ADC capacitor will be divided equally between the two capacitors and the voltage will therefore halve. If the capacitance of the touch plate is increased by the presence of a finger, the resulting voltage measured will be lower.
First we charge the ADC capacitor up. In this case, we use the internal 4.096V reference. At the same time, we discharge the touch pad by switching that pin to operate as an output, and switching it to ground.
Next, we switch the pin to be an input and select it to connect to the ADC. The capacitors are now in parallel, and the initial 4.096V charge is shared.
Here is the design of the touch pad on the pcb. The aim was to minimise the touch pad capacitance.
Here are the resulting pads on the manufactured pcb.
Running some test code, the measured voltage is 645mV with no finger present, and 555mV with a finger pressing on the pad.
These figures provide excellent recognition of a direct key press. Ideally, averaging over time should be used to determine the “no press” voltage, and the confirmation of a key press should be only after a number of valid readings to prevent spurious detection of a key press.
The typical ADC capacitor value is around 15pF, so starting with a voltage of 4.096V, and dropping to 645mV when paralleled with the touch pad, suggests that the combined capacitance of the touch sensor and ADC capacitor is (4.096/0.645)*15pF= 93pF, or that the touch pad on its own has a capacitance of 78pF.
When the pad is touched, the total capacitance changes to (4.096/0.555)*15pF=111pF. The finger therefore adds a capacitance of 18pF.
Unfortunately, with the current design, if a 1.6mm plastic enclosure covers the keypad area, a valid keypress only results in the voltage charging from 645mV to 638mV. Sensitivity would be increased if the touch pad capacitance is reduced when untouched, and increased whilst touched. For instance, if the touchpad capacitance were reduced to 15pF, the ADC voltage would be 4.096V charged, 2.048V when paralleled but untouched, and 1.36V when touched.
Just received a package with my first order from OSH, just over 2 weeks from the time of ordering.
Three boards, about 5.15 x 2.90 inches (131 x 78mm), delivered to the UK for 58.00 GBP, and no customs to pay. That is a really great price, especially given the size of the pcbs.
Here are the times:
Ordered: Day 0
Added to panel: Day 0
Set to Fab: Day 0
Manufacturing complete: Day 7
Shipped from the US: Day 8
Received in UK: Day 16
Given the cost and the speed, I will certainly be a future customer for all my prototype boards.
No matter how careful I am at the design stage, there are always errors, so this is an ideal testing ground before committing to a large run, where I use pcbcart. Out of interest, I checked with pcbcart how much three boards of this size would be, and the cost was $103 plus about $30 shipping (about 83 GBP in total).
If you up that to 250 boards, the costs are $464 plus about $60 shipping, or about 1.35 GBP per board.
You are never quite sure about the shipping cost until you checkout, and it can add quite a hefty premium.
If you are a coffee lover, you want to stop the shot as soon as all the good coffee flavour has been extracted from your coffee, and definitely before all the nasty flavours begin to come through (known as over-extraction).
This can be see by watching the coffee flowing, and switching off the flow just as the chocolate brown coffee colour disappears from the shot. This point is known as when blonding starts, as the coffee flow is now a straw yellow colour.
The point at which blonding starts is around 15 to 30 seconds of flow, depending on the coffee variety and type of roast.
The trouble is that it is a pain to time the shot every time, or to bend down and look up at the coffee flow to see when the blonding starts, as this all takes place under the overhang of the front of the machine. Commercial machines use a flowmeter to measure the shot volume, and stop the pump automatically when the required shot volume is achieved. Fixing the time of the operation of the pump gives a good approximation of the volume of the shot, at lower cost.
The coffee shot controller monitors the operation of the water pump, which provides the water pressure to force the flavour out of the coffee. Whenever the pump operates for more than 10 seconds, the controller times the operation of the pump. The time at which the pump is switched off is stored in memory.
The next time that the user wants a shot, they only have to flick the coffee switch briefly, and the controller will read the value out of its memory and will run the pump for only that amount of time.
Shown below is the controller installed inside a Gaggia coffee machine. All interconnections are provided with silicone insulated wiring due to the high ambient temperature.
The controller monitors the pump switch volts via an opto isolator. The opto led can withstand 50mA, and a minimum of around 5mA is required to turn the transistor on. For 230Vac (325V peak), a pair of 10k resistors in series, and a diode in series to protect during the negative cycles, are sufficient. The peak led current is (325-0.7-2.0)/20k = 16mA. Every 20ms (for 50Hz mains) the transistor in the opto isolator will be switched on and this can be detected by the micro-controller.
The choice of micro-controller was based on the need for EEPROM memory to store the required time for the pump to operate, and on board ADC for possible future design changes. The choice was either 12F675, 12F683, 12F1822 or 12F1840. All of these cost comfortably less than £1.
The main issue with the construction was to provide isolation of the micro-controller circuitry from the mains voltages present on the pcb. For the present application this is not an issue, as there are no external connections which are accessible to humans. However, there are connections available on the pcb for external sensors (flowmeter, temperature sensor, front panel mounted potentiometer, etc) and these may need to be isolated from the mains in future projects using the same pcb.
The prototype is complete, with no modifications required to move to final production. The anticipated market is the enthusiast coffee maker owner who has completed other modifications to their machine such as adding PID a controller. The next steps are to produce in volume and generate interest through coffee forums.
Browsing on Ebay, I noticed something called a Points Position Indicator (PPI) which is used to record the position of a set of model railway points which are moved by a pair of opposing solenoids, operated by momentary switch action.
One operation sets the points, the other resets them. The problem for the operator is that it may not be clear which action was performed last.
What is needed is a S-R latch, but the latch must retain the status when the power has been switched off. This is ideal for a micro-controller, as it is common for them to have built in EEPROM memory, which can retain data when the power is switched off. The retention life is about 40 years, and the memory can be written to in excess of 1 million times, which is not an issue here.
The main components used in the PPI are MC1489 type input buffers (equivalent LM1489, DS1489, or SN751489). These are designed to buffer RS232 signals, and so are resistant to +30Vdc on the input lines and offer better static protection than connecting inputs directly to the micro-controller.
On the output side, ULN2803 transistor arrays provide open-collector outputs to drive indicator leds.
The choice of micro-controller is mainly based on having sufficient GPIO, and built in EEPROM. I found the 16F884 was lowest cost single chip solution, with 37 GPIO (it has a built in oscillator, so the oscillator pins can be reconfigured as GPIO). There are lower cost solutions using two 28-pin chips, one with EEPROM and one without, sharing the EEPROM as only 1 byte is required. Utilising external serial EEPROM is also a possibility (ie Atmel 24C01).
At present 650+ have been sold.
On early generation PICs the MCLR input was used to provide a reset input to the microcontroller. Pulling the input low would hold the microcontroller in a reset state, and pulling it high would start the microcontroller running.
The most straightforward method to do this is to connect the MCLR pin to the positive rail. When the power supply is switched on, the MCLR pin is automatically pulled high and the micro starts up.
One disadvantage of this arrangement is if the power supply only rises slowly, for instance if it has large smoothing capacitors to charge up when it is first switched on, the reset line could rise sufficiently to start the micro, before its supply is sufficient or stable.
To prevent this, if the power supply rises slowly, it is necessary to ensure that the reset line rises even more slowly. By connecting a capacitor from the MCLR pin to ground, this capacitor is charged via the reset resistor when power is applied. By appropriate choice of capacitor and resistor value, it can be arranged that the micro only comes out of reset once the main power supply has stabilised.
If the power is interrupted just after it is switched on, it could be that reset capacitor has retained sufficient charge to allow the micro to reset despite the main supply not having stabilised. This can be avoided by providing a diode to quickly discharge the reset capacitor (via the rest of the circuit) as the main supply falls.
If you are using ICSP to program the micro, the programmer will drive the MCLR pin positive, to a value above Vcc. To prevent this voltage damaging anything powered from the rail, a second diode is provided.
Now we have four components to include in our design, and we have used one of the pins of the micro, preventing it being used as an input.
Thankfully, the PIC has been designed so that none of these components are normally required – in fact the MCLR pin can be left unconnected if we wish.
I was looking at interconnecting several PCBs with some low speed data (for model railway control) and was looking for a low cost easy to program solution.
CANBUS is all the rage, but the chips which interface the PIC and CANBUS are about £2 each. That, coupled with the complexity of the software required to drive them put me off.
The obvious choice is RS485, with interface chips (MAX485, LTC485, ect) costing $0.25 to connect between the USART on the micro and the RS485 bus itself. These can be dedicated USART pins (RC6 and RC7 on most PICs) or you can use software USART with almost any pins.
I program in Mikrobasic which has built in routines for RS485 comms, able to send 1, 2 or 3 bytes at a time from a master to any slave on the bus. They can then reply back to the master.
RS485 is the definition of the physical interface, although it avoids definition of the connector types (I have chosen screw terminals to minimise cost).
Whenever a master or slave sends a message, it travels down the line, and will reflect off each end. To eliminate this you can choose to terminate both ends of the line (you terminate the sending end so the signals sent by the slaves are also absorbed). The line ideally has a characteristic impedance os 120 ohms, to 120 ohm resistors are placed at each end. The disadvantage for me is that my users need to know about these intracies, and really I want to make things as easy as possible for them. It also means you need to add biasing and power consimption is increased.
Luckily, if you choose low data rates, you can avoid the need for the termination resistors altogether. The signal is sampled half way through the symbol period, so if this is a long enough period after the start of the symbol for relections to have died out sufficiently, then the terminations resistors are unnecessary.
After reading around the subject, I would make my board capable of being connected as follows:
This allows for 120 ohm termination at each end of the line, and also for a pair of 560R biasing resistors at the bus master. The bus wiring is ideally twisted pair, with a screen, which is connected to the ground at each device on the bus via a 100R 0.5W resistor.
I recommend the excellent article by Jane Alexon at http://www.lvr.com/rs-485_circuits.htm which covers RS485 concisely (although note the first image in the article was incorrect when I last looked).
I am working on a PCB design at the moments which has an RS485 connection and is acting as a slave in a network, receiving commands from a master board and replying with its status.
An RS485 network can have several slaves (commonly up to 32, more with different interfacing devices) so my PCB needs to have a slave address setting of some sort.
I was going to add a DIP switch to set a value somewhere between 0 and 32 (32 will be plenty for the size of the network I am planning) but I thought I could simplify it.
The other function of my PCB is to monitor 16 inputs, so I have fitted a simple push button on the PCB. The address of the board can now be set, applying power to the board with the push button pressed and setting the address with some temporary wires to the GPIO pins. The value is saved in EEPROM.
If you don’t want a permanent push button on the PCB, you could use a jumper or similar.
Saving: the cost of a DIP switch, PCB space, and the time of installing the associated dropper resistors.
DIP switches are a common way to allow users of your design to make choices about how your circuit behaves, such as setting a timer value, setting an address on a network, and so on.
They can be greedy about the number of connections they require of your microprocessor, and will need pull-up resistors or need to use precious pins with internal pull-ups which can be enabled through software.
On a recent project, I had only a single pin available, and found a solution in one of the excellent Microchip Tips n’ Tricks documents. It basically consists of creating a switchable potential divider and using an ADC channel to read the value.
The article leaves the reader to work out some convenient resistor values for themselves, which is a shame, as some standard values could have easily been provided which would work for most projects and save time for a lot of people.
An alternative arrangement, which only uses two resistor values is the R2R ladder.
If you only need to set a value occasionally, you could introduce a switchable link using a pin header. This way you can share a pin with another part of your circuit. You could for instance read the ADC value of that pin at boot up, and then for the rest of the time that pin could perform its other function, once the link had been moved. You would need to store the value in EEPROM only when the link was in the DIP switch position, so the microcontroller needs to know the switch position. This could be done by booting with a button pressed.
If it is only yourself using the setting, then you can get more quick and dirty. How about these:
- Using some settings tracks which you saw or dremel to suit.
- Utilise a secret button press sequence using the normal user inputs of your device.
- Provide a snap out section of PCB which can be removed by hand or with pliers which takes some track with it.
- Use a variable resistor as an ADC input to your micro which you set in conjunction with a test point (pin 6 of your ICSP header could suit?). For instance, set 1V for software version 1, 2V for software version 2, etc.
If you want to stop others twiddling, you could store the value in EEPROM, and then disable the function using one of the methods above.
Microcontroller DFM is all about designing circuits for manufacture – minimising build cost, component count, or cost for electronic circuits based around microcontrollers. If you are building only one circuit, you could be interested in using a microcontroller with fewer pins (possibly that you just happen to have in stock in your parts bin). If you are building 10 circuits, you could be interested in reducing the size of your PCB to keep down build cost. If you are planning to hand solder 100 or so boards, you will probably want to minimise the time spent in inserting components, soldering wires, and trimming off the component leads.
My background is mostly from working with PIC microcontrollers, so you can expect to see plenty of examples based on them – but the examples will be equally applicable to atmel, picaxe, arduino, etc.