Needless to say, I built on Franz example as well as the input devices week documentation from Loes. For the vibration motor, the set up seemed to not be difficult at all and and I started looking at my own output devices week in order to figure out the schematic design in my mind. However, I soon realized, after a quick search on Google, that motors need a few important things around them that I don't have in the board made that week.
Working Board Design: schematic
The first design I made is also the one that I went on to mill and includes several errors that made the communication with the serial port impossible, it is explained in next section. The following one is the last, after being corrected by Emma. Fortunately enough, the footprint of the components that needed to be substituted was the same, what allowed me to correct the errors without milling another board.
- The set up around the microphone is quite a thing. Although digital microphones can be used, I don't know much about them and I went on for the safest option, since there was quite some documentation.
- OPAMP (operational amplifier) is necessary since the small signal at the end of the microphone is right at the limit of what you can read with the ADC.
- The combination of resistors and capacitors around the OPAMP are what is called a "bias circuit", whose role in fact is to feed the amplifying devices with the electrical power (DC) to activate it and make it capable of amplifying signals, which are time varying (AC). After biasing, the amplifier is able to receive the signal to be amplified at its input (more information in my Glossary of Electronic Terms). The chosen values are based on Loes example, which at the same time are based on Neil's example. In essence, the values of these components will set the gain provided by the OPAMP, together with the gain that can be achieved through software.
- Microphone has orientation! Terminal 1 goes to OPAMP, terminal 2 goes to GND (check data sheet).
- 3.3 volts regulator in order to power the vibration motor, that actually works at a maximum of 3.6 volts. Always go for the regulator that can drive 1A, since very few things like an IC, a motor and a led are enough to be demanding more than 100mA.
The data sheet gave an example of a typical application circuit in which 10µF and 100µF capacitors accompany the regulator. The reality is that I installed a couple of 0.1µF capacitors in both sides (as done in previous occasions) and it is working.
Fortunately both the microcontroller and the N-MOSFET work at 3.3 volts, but it is important to check beforehand in the respective data sheet.
- As for the microcontroller, the Operating Voltage is 1.8 to 5.5 (see data sheet).
- As for the transistor (MOSFET type N), the VGS (Gate-Source threshold voltage) sits around the 1-2 volts, which means that 3 volts are enough to activate it.
- The 0Ω resistor after the regulator is there in substitution of a wrongly placed one. It was supposed to be limiting the current through the motor, but the fact that I took VCC after this resistor made that the powering voltage of the microcontroller was fluctuating depending on the current demanded (V=IXR). A mess, specially for the proper serial communication to happen. Placing a 0Ω resistor fixes the voltage and the 3.3 volts regulator outputs the right amount of voltage for all the things to work.
- Attiny 84 was chosen over 44 because of its bigger capacity. Make sure VIN (voltage before amplifier) and VOUT (voltage after amplifier) go to ADC pins! (this is an analog microphone).
- Resonator isn't necessary because the design is not very demanding in that sense (I am not using complex communication between boards) and there are ways to establish serial communication without a very accurate clock (see section below).
- For the motor:
- MOSFET type N: be careful when picking the component to make sure is type N! It drives current through once current is applied at the gate. The resistor before is not really necessary. According to this tutorial, it is necessary to avoid too much current from the MOSFET can be damaging the motor, but Emma said is not really necessary. It is not a pull down resistor since it is not connected to GND.
- The diode acts as a surge protector against voltage spikes that the motor may produce. The windings of the motor notoriously produce voltage spikes as it rotates. Without the diode, these voltages could easily destroy the microcontroller.
- The 0.1µF capacitor also protects the microcontroller by absorbing voltage spikes produced by the motor.
Milling the board: double side
My first double sided board. Made with an advanced milling machine, the twisting was quite easy. Double sided boards can save you a lot of headache with the layout, but they are more difficult to make. Specially avoid having too many vias, since connecting top and bottom for each of them is a tedious work. Here there are a few things to keep in mind:
- Change routing in Eagle from Top layer to Bottom layer and the vias will appear automatically.
- Sometimes auto route in Eagle uses component holes as vias. If you haven’t soldered those holes, top and bottom won’t be connected.
- Don’t put the vias underneath any component or next to their legs. They will not allow it to properly sit on the board.
- Make thick traces, specially if you are milling the double sided board in the Modela, because the accuracy is not exceptional and you don’t want mismatches between Top and Bottom traces.
- Double check the vias with a multimeter. Many times, really. They are challenging to make and the piece of wire might not be connecting both sides even when the soldering looks perfect.
- Place components also on Bottom side. This way you can reduce the amount of vias considerably (otherwise lines have to go from top to bottom and to top again).
Programing the board
Programing this board was quite an odyssey at the the beginning. Because VCC that powered the whole board was fluctuating due R2, the communication with the serial port became impossible. I am still wondering how I was able to read something sometimes. These are some of the faulty readings I got:
Because I didn't include any regulator (8MHz internal clock is enough) there is one thing that needs to be done:
- Run this piece of code by Zaerc in your board.
- Let the serial monitor tell you which configurations (hexadecimal numbers) work best for your specific case.
- Pick the number in the list that is half way the faulty communications (0x6E in my case approximately, one among the good ones, in the middle) and include it in your other code as a script right before starting the serial communication.
Caution!: for some reason the communication with the serial monitor interfered with the proper driving of the motor, so I decided to comment out all the serial communication lines in the final code.
Important things I have learned
- Regulators and other components, although equal in package, might have different pin out configurations. Be very sure about which one yours have before using any given footprint!
- Next time use trick to connect soldered wires (see picture) in order to minimize risk of breaking. Or even better, use female and male headers to safely connect wires in a reversible way.
- Most of microcontrollers have internal pull up resistors so pins are HIGH by default. Consider that when plugging your things to it, so they can go crazy before the code starts running.
- Actually, it is quite likely that when board is being programmed (plugged to the ISP and the computer) all the things go crazy (leds on, motors running...). The microcontroller also takes a few milliseconds to start running the sketch. Keep it in mind.
- Always make sure that the microcontroller is powered at a steady voltage. Specially if you want to establish communication: 2 boards can't communicate if they are working at different voltages (domains), even if the difference is small.
- You can always reburn the bootloader as a way to “reset” the microcontroller when you notice that strange things are happening.
- Always read raw values when measuring analog input. Before you move on to set thresholds, make sure that the raw values fluctuate properly.
- Good to know that there is no magic with electronics. Sometimes it might seem like that, but when things don’t work it is more than often a human mistake. That’s what debugging gear is there for.
- Never trust values that are not fully stable. I have experienced how a board that was completely wrongly designed and running a program that made no sense, did things that were very close to what I wanted it to do. Not enough. Find the reasons and don’t take anything for granted. Double check is your friend.
- Do not to panic. As usual, search for the easiest and most immediate thing you can do to advance towards an answer without asking. Ask to yourself, try to explain the situation to yourself before you reach out to others. Start from scratch if necessary, looking at the most basic things you took for granted. The fact that you were checking step by step and that it was working before doesn’t mean much. Swallow your ego and consider the option that you might have neglected something.
- Always remember to show your layout to an expert before you go on with the milling.
- Keep yourself open to the option of tweaking an existing board that has failed or has been wrongly designed, specially if it is for a prototype. I like thing when they are well done, but being able to repurpose boards in a cheap and dirty way is a very handy skill.
- When boards are complex, and specially when motors are pulling a lot of current, it is recommended to use the whole plate as GND.
Working files
- Schematic
- Board design
- BOM
- Zaercs's callibration code
- Serial check code
- Microphone reading code
- Pin low code
- Motor code
- Motor fine-tuned code
Añadir un comentario