This is doubtless the most simple way of hooking up a character based LCD display with a built-in HD44780 controller (and almost all character LCD displays are like this). The Vcc and Vdd are connected as usual, with the 0.1uF decoupling capacitor. For the contrast voltage a 10k potentiometer is used. Normally this has to be calibrated once, so a tiny one that you set with a screwdriver is good. The R/W is grounded, ensuring that the connection is write only (do NOT use a resistor for this. Quite some current goes through this pin, and not grounding it will cause the I/O ports to occasionally go into read mode, which will destroy your microcontroller, even if it is a PIC). The RS and E(nable) lines are hooked up to arbitrary pins on the 16F628A, and the D0-D3 are left disconnected. D4-D7 are connected to half a port of the microcontroller, in this case PORTA (RA0-RA3). Pins 15 and 16 are sometimes absent and are used to control the backlight. Regardless, they are left disconnected too.
Controlling this uses the 4-bit interface with maximum delays (it is not possible to use shorter delays, as it is a write only connection and there is no way of knowing whether the sent nybble has arrived). The software should show how it works. The initialization sequence is crucial, and I recommend copying it from the code, as it is easy to get wrong. When you see no characters appear, also fiddle with the contrast setting, as this could be set such that nothing displays.
Drake is the name of the computer I am developing. However, this blog covers all aspects of embedded hardware and software, and explains various projects in detail. Feedback is greatly appreciated.
donderdag 20 november 2008
woensdag 19 november 2008
Camera GPS official version
The final version of the camera GPS had to be smaller. In fact, a number of things needed to happen: smaller, lighter, own GPS module, PC connection and an LCD display. The picture shows the final version. Still slightly bigger and heavier than a flash module, with a rather clumsy 9V battery (which should clearly be replaced with a LiIon one) and a serial output port (which should become a USB port, which can also charge the LiIon battery). On the picture you can see the GPS module (the square at the top left) the LCD display (2x8 characters, on the right), the battery, the 6-pin ICSP connector, a white button, an on/off switch (at the bottom) and an RS-232 output (at the top). The system still uses the PIC16F628A and the 24LC512 memory. The circuit seems a bit awkward because of the attached flash port at the bottom. I did not yet make an enclosure for it.
On the picture you can see the GPS in operation. The display shows the number of the last picture taken (40) as well as the direction in degrees, the quadrant that we are in (NW) and the movement speed. Another picture, below, shows the actual coordinates, although the display is too small to show the smallest values: this is something that still needs to be addressed in the new version of the GPS software.
On the picture you can see the GPS in operation. The display shows the number of the last picture taken (40) as well as the direction in degrees, the quadrant that we are in (NW) and the movement speed. Another picture, below, shows the actual coordinates, although the display is too small to show the smallest values: this is something that still needs to be addressed in the new version of the GPS software.
dinsdag 18 november 2008
7 segment displays
Seven segment displays are basically 8 LED in a pattern. The most convenient way of connecting would be to hook up each LED to one pin of a port, but usually this is not possible because ports have different uses and there is always a certain port you wish to use for a certain purpose. In this case the RX/TX pins in PORT B are used for the serial input, and RA4 is used for the I2C communication. This means we have to select other pins. This design avoids fancy PWM output to the LED and just allows them to be on and off. To avoid the LED dying from current drain I added 330 Ohm resistors. For a brighter result one can go as low as 220 Ohm, to save power you can go as high as 1k Ohm. The part of the software for controlling the LED display is very simple in this case: it just consists of subroutines that send the appropriate output to the port. Normally one would not do it this way, as this is inefficient. A lookup table would be better. In this case, however, there are a limited number of values, and it was meant as a prototype anyway.
Note that it might seem attractive to use a single resistor on the ground pin of the LED display. This, however, will cause the brightness to fluctuate and can even cause damage to the display, and is therefore not recommended.
Note that it might seem attractive to use a single resistor on the ground pin of the LED display. This, however, will cause the brightness to fluctuate and can even cause damage to the display, and is therefore not recommended.
maandag 17 november 2008
I2C EEPROM microcontroller connection
Hooking up an I2C device, like an EEPROM, is relatively simple. I2C uses a 2-pin bus, with labels SCL (clock) and SDA (data). In case your microcontroller has a built in I2C controller, it is wise to hook these two lines to that port. However, I generally write it in software, because the hardware is slightly more complicated than needed (it handles clock skewing, master/slave configurations and multiple devices) in this case. It also does not give you the nice three byte buffer, which the UART (serial port input) does. If you do write it in software, it is best to hook the data input to the so-called "open collector" port. On most older PIC microcontrollers, like the 16F628(A), this is RA4 (port A bit 4). Note that both lines need pull up resistors. The values of these resistors depend on the speed that you wish to transmit data over. The disadvantage of low values is the current drain on the system. 1k Ohm works well. Note that the 24LCxxx (xxx indicates the memory in bits, a 512 module therefore has 64K of memory) needs its own decoupling capacitor, which as usual I chose to be 0.1uF. The write protect line and the address lines can all be grounded, unless you plan to have more than 64K of memory: you will need to configure different addresses for each of the EEPROM in that case.
Reading the EEPROM runs at 400 kHz. Not very fast, but suitable (and it seems most of them allow you to go up to 700 kHz, if needed). Writing is slower: you can send up to 256 bytes to the EEPROM without any delay, but after that a wait is needed (so-called ack-polling) until the EEPROM is available again for other operations.
Reading the EEPROM runs at 400 kHz. Not very fast, but suitable (and it seems most of them allow you to go up to 700 kHz, if needed). Writing is slower: you can send up to 256 bytes to the EEPROM without any delay, but after that a wait is needed (so-called ack-polling) until the EEPROM is available again for other operations.
zondag 16 november 2008
Serial port for input
To allow a microcontroller to read from a serial port (but not write to it) is relatively simple. In principle it is a matter of hooking up a 10 kOhm resistor from the output of the serial cable to any pin of the microcontroller, at which point the microcontroller can read the incoming data using software (note that this could push the microcontroller outside of its specification, as you're using the protection diodes for another purpose). Usually, however, one does not want to rely on software to do the reading, as this is slow, time consuming and prone to errors. Most PIC microcontrollers, including the PIC16F628A, have a so-called UART, which handles the reading and writing of serial ports. Unfortunately you can not use the resistor trick in this case, as the signal is inverted and the UART can not handle an inverted serial signal. Fortunately a simple RTL circuit can solve two issues: the illegal use of the protection diodes inside the microcontroller and inverting the signal so it can be properly read, and this with only one additional transistor and resistor.
The provided circuit can handle almost any serial port, even if the voltage is out of specification. It assumes a male connector, for a female connector it needs to connect to pin 3 (as this is a read operation there is no problem if you make a mistake). Note that transistors are much slower at inverting than regular inverters, and that you should therefore not use very high baud rates.
zaterdag 15 november 2008
Camera GPS
Another project I work(ed) on was the camera GPS. The idea is that when you take a picture, your camera tends to send a signal to the flash port, which could trigger the flash if necessary. A very simple flash port just has an on/off switch, which could be hooked up to a GPS to record the current date, time and place so that you can later associate the picture with this information. The board shown here actually used to be a prototype for the servo controller featured elsewhere in this blog, but was modified to communicate with a gps. On the board you can see a 7-segment LED display in green, an on/off LED, a 24LC512 external EEPROM to store the results, a PIC16F628A microcontroller, an RS-232 input port that would hook up to the GPS, the usual 6-pin ICSP and a 74HC125, which seems useless but was used to hook up a smaller GPS module that worked on 3V. There is also the obvious 7805 power supply with 9V clip. This, as well as the software for the GPS camera controller, will all be explained in more detail in later posts, first another picture of the prototype hooked up to a camera (a Minolta X700 in this case, which worked really well).
Servo controller in action
Here is a short video that shows the servo controller working. As my 9V NiCd battery was still charging I used a regular alkaline one, which actually was better for the video as it made the servo motor respond slower due to the lower maximum current.
donderdag 13 november 2008
Servo controller software
The software for the servo controller is simple: it initializes the analog input AN0, it ensures that the internal clock is running at 8 MHz, and sets the servo motor port to output. The main loop then reads the value of the potentiometer using the ReadPotentiometer routine, and calls DoThisNow to start the pulse on the servo motor control that will cause it to move to the correct position. A servo motor expects a 1ms pulse that is on, then 0-1ms that is on (which determines the position) and finally at least 20ms of offtime. It can therefore change 50x each second, however, it is usually slower in responding.
The software implementation allows a value from 1-511 to define the second 1ms, thereby having a good resolution. A final version of this software would allow storing the values from the potentiometer in either internal EEPROM or external memory, thereby allowing you to replay it. It should also allow for multiple servo controllers. An example of this is my older version of servo controller software, which stores the different settings using macros in program memory, allowing easy control using POSITION and LINEAR macros. This was the version used by balloon manor in 2007 in Rochester, NY.
The software implementation allows a value from 1-511 to define the second 1ms, thereby having a good resolution. A final version of this software would allow storing the values from the potentiometer in either internal EEPROM or external memory, thereby allowing you to replay it. It should also allow for multiple servo controllers. An example of this is my older version of servo controller software, which stores the different settings using macros in program memory, allowing easy control using POSITION and LINEAR macros. This was the version used by balloon manor in 2007 in Rochester, NY.
woensdag 12 november 2008
Potentiometer and servo motor connections
To connect a potentiometer to a PIC microcontroller is very simple. The circuit here is copied from the circuit that is on the PicKit 2's demo board (except that that circuit uses a 330 Ohm resistor, and this one uses a 1k Ohm resistor), and the software that comes with this board can be used to read it. In this case it is hooked up to AN0, which is also the programming input, but because of the high resistance this will not affect the programming of the microcontroller. In addition to the capacitor inside the microcontroller it is wise to keep an external one to avoid fluctuations in the readings.
Hooking up the servo motor is even simpler: a servo motor has 3 wires. Red is the main voltage line, which ideally is at +5V with at least 200mA, although at peak it could use over 500mA. Black is the ground and white is the control wire. The control wire can be hooked up to a PIC16F688 (or most other PIC) directly. Due to the very low frequency needed to control a servo motor there is no need to use PWM hardware, should this be available.
dinsdag 11 november 2008
ICSP for PIC microcontrollers
Microcontrollers are modified by a so-called "programmer". The first programmers you use usually have a socket that allows you to insert the microcontroller, after which you can update its internal memory. It is, however, much more convenient to leave the microcontroller in the circuit, and program it by hooking up the programmer to your circuit. This is called ICSP and relatively easy when one uses a PicKit 2 (I believe there is a PicKit 3 too, but I have little experience with it). The PicKit 2 accepts a regular 6 pin socket, so a simple header pin suffices. The schematic shows how to hook it up. If you align the pins with the PIC16F688 (or PIC16F690, or any other "modern" PIC) you only need to add two wires: Vdd (+5V) and MCLR.
Make sure that the end is marked, so the user can match the white triangle on the PicKit 2 correctly. Note that you should put a 0.1uF decoupling capacitor over the microcontroller, as marked in the circuit. If you are using some of the pins that are used by the ICSP, make sure they do not draw a lot of current away from the PicKit 2 (or other programmer that you might be using). Also avoid hooking up components that are sensitive to higher voltages, as you can't be certain what voltage will come out of the programmer.
Make sure that the end is marked, so the user can match the white triangle on the PicKit 2 correctly. Note that you should put a 0.1uF decoupling capacitor over the microcontroller, as marked in the circuit. If you are using some of the pins that are used by the ICSP, make sure they do not draw a lot of current away from the PicKit 2 (or other programmer that you might be using). Also avoid hooking up components that are sensitive to higher voltages, as you can't be certain what voltage will come out of the programmer.
maandag 10 november 2008
Power
All designs require power. Here I cover the simple design that I use for most power supplies. As you can see from the schematic, most of the work is done by a component that is called the 7805. The 7805 model is the biggest version, and recognizable by its large heat sink, which has a hole so it can be attached to an even bigger heat sink. The 7805 model can output 5V at 1A, which is quite a lot and suitable for projects involving motors, like my servo controller. A smaller model, the 78M05 gives 500mA, and is therefore not very useful. I include it more as a warning: avoid the 78M05. The smallest model is the 78L05, which looks more like a simple transistor. The 78x05 series is inexpensive in terms of money, but not entirely cheap in terms of power consumption. They regulate power quite well, ensuring that their output is 5V (the 05 in their name is this voltage, a 7812 would output 12V) with very small fluctuations. They do require that the input voltage is higher than their output voltage, though, and the difference is converted into heat (hence the heat sink). For 5V output the input needs to be at least 6.6V (or higher, check the data sheet of the particular model you acquired). There are other options, and I will discuss some later in other posts to this blog.
Note that the component does not limit the current to the value specified. All it does is try to maintain the output voltage. I have had a 78L05 output over 1A at 5V. The problem here is mostly the heat: exceeding the output current will cause the component to grow hot, to the point where it will burn you, or even destroy itself. It is therefore wise to know what the current consumption of your circuit will be, and choose the appropriate component.
As you can see from the schematic, there are two other components, both of them capacitors. At the input side I have a 10uF capacitor. This is to ensure that fluctuations in the input voltage are filtered out, as well as moments where the target circuit has peaks in the demand. It generally does not hurt to increase this capacitor: values up to 470uF are quite acceptable. Note that this capacitor has polarization and will therefore need to be inserted correctly. On the output side I usually suffice with a 0.1uF capacitor. Obviously it is possible to add a larger capacitor on this side too, but the ceramic capacitors are much faster than the electrolytic ones, and response time is generally more important. Apart from the one in the power circuit I also put the 0.1uF capacitors near all the current consuming components on the board. This is called "decoupling" and without them you might experience very strange behavior, as voltages might drop below operating requirements. If you feel that ceramic capacitors are not fast enough you could switch them for tantalum. However, tantalum capacitors have polarity, which is why I tend to avoid them.
In the circuit above I assume that it is hooked up to the mains using a wallwart. However, frequently I use batteries. As you need to exceed 6.6V my preferred method is a 9V battery. For high current applications this has to be a NiCd battery, as these give a lot more current than other batteries. This might seem odd, given that a 9V NiCd battery generally has "160mAh" written on it, which implies a small amount of current compared to a NiMH battery (300mAh). However, the C (charge/discharge rate) of a NiCd battery is 5C-10C, so it can actually provide 800mA-1600mA, whereas a NiMH usually doesn't exceed 0.5C, which means it would only provide 150mA. Of course, the NiCd battery only provides this power for 6-12 minutes, whereas the NiMH would last 2 hours. I'm not a fan of batteries that can not be recharged, because I sometimes forget to disconnect them which renders them useless, and because they are not good for the environment and difficult to dispose of.
Note that the component does not limit the current to the value specified. All it does is try to maintain the output voltage. I have had a 78L05 output over 1A at 5V. The problem here is mostly the heat: exceeding the output current will cause the component to grow hot, to the point where it will burn you, or even destroy itself. It is therefore wise to know what the current consumption of your circuit will be, and choose the appropriate component.
As you can see from the schematic, there are two other components, both of them capacitors. At the input side I have a 10uF capacitor. This is to ensure that fluctuations in the input voltage are filtered out, as well as moments where the target circuit has peaks in the demand. It generally does not hurt to increase this capacitor: values up to 470uF are quite acceptable. Note that this capacitor has polarization and will therefore need to be inserted correctly. On the output side I usually suffice with a 0.1uF capacitor. Obviously it is possible to add a larger capacitor on this side too, but the ceramic capacitors are much faster than the electrolytic ones, and response time is generally more important. Apart from the one in the power circuit I also put the 0.1uF capacitors near all the current consuming components on the board. This is called "decoupling" and without them you might experience very strange behavior, as voltages might drop below operating requirements. If you feel that ceramic capacitors are not fast enough you could switch them for tantalum. However, tantalum capacitors have polarity, which is why I tend to avoid them.
In the circuit above I assume that it is hooked up to the mains using a wallwart. However, frequently I use batteries. As you need to exceed 6.6V my preferred method is a 9V battery. For high current applications this has to be a NiCd battery, as these give a lot more current than other batteries. This might seem odd, given that a 9V NiCd battery generally has "160mAh" written on it, which implies a small amount of current compared to a NiMH battery (300mAh). However, the C (charge/discharge rate) of a NiCd battery is 5C-10C, so it can actually provide 800mA-1600mA, whereas a NiMH usually doesn't exceed 0.5C, which means it would only provide 150mA. Of course, the NiCd battery only provides this power for 6-12 minutes, whereas the NiMH would last 2 hours. I'm not a fan of batteries that can not be recharged, because I sometimes forget to disconnect them which renders them useless, and because they are not good for the environment and difficult to dispose of.
zondag 9 november 2008
Servo controller
One of the more recent projects I did was a servo controller. In the past I already designed two (which undoubtedly will feature on this blog too) but because of the new Balloon Manor in Rochester this month I wanted to design one with a higher resolution. It was never used, and this was a very simple prototype, but it did increase the resolution to 512 steps, which is twice the number of the previous version.
As usual with servo controllers the tricky bit is the power supply. As this controller was only controlling a single servo I could suffice with a single 7805 (do not use the 78L05 or the 78M05, as these give too little power, 100mA and 500mA respectively). Again because this was a prototype I hooked it up with a 9V battery clip. As battery it is required to use a NiCd rechargeable battery, because those are the only batteries that would supply the power used by the servo motor. In the end product it is recommended to use either over 7.5V worth of AA batteries, or even D batteries, or use a wallwart to hook it up to mains. As you can see in the circuit board I put a 10uF capacitor (it doesn't hurt to make this bigger) over the input voltage, and a 0.1uF (tantalum is preferred for speed, but ceramic works well and is easier to use, as it doesn't have polarity) capacitor at both the servo motor connector as well as the microcontroller.
As microcontroller I used a PIC16F688, mostly because it is so nice and small, and modern, allowing it to be easily programmed using the PicKit 2 (you can even program it in the PicKit 2 demo board: even though it is made for the 16F690, it fits the 16F688 equally). I used the usual 6 pin programming connector, which, if mounted as displayed, is really easy to hook up: the three pins next to the PIC16F688 (pins 3-5) can be connected directly. The fourth pin (6) is left floating. 2 is connected to the top pin on the other side, as this is the other voltage, and 1 is connected to the reset line, which is the middle pin on the other side of the Microcontroller. For this I use a white wire, so it is quite recognizable on the board, so I can match the triangle of the PicKit 2 with the white wire and do not mistakingly connect it the wrong way.
The final two components are the potentiometer, which is connected to the analog port of the 16F688 and is used as input for the servo motor, and the servo output. On the servo output pins 1 and 2 are connected to the power directly, and 3 is connected to the output pin of the microcontroller that is used to control the servo. Obviously multiple servos can be attached using different pins of the microcontroller. Note that once you exceed two servos, a separate power circuit is needed for the next two. The ground will need to remain the same, to ensure proper functioning of the control line.
The software that I wrote for this servo controller is very basic: it measures the potentiometer and moves the servo motor accordingly. The plan was to include a system that registers the sequence of movements of the potentiometer in memory. This is not very difficult to develop, but the higher resolution of 512 values as well as the limited storage of 256 bytes inside the 16F688 made this trickier. I was contemplating using the difference between two settings and storing it in a 4 bit value, but never got to implement this.
As usual with servo controllers the tricky bit is the power supply. As this controller was only controlling a single servo I could suffice with a single 7805 (do not use the 78L05 or the 78M05, as these give too little power, 100mA and 500mA respectively). Again because this was a prototype I hooked it up with a 9V battery clip. As battery it is required to use a NiCd rechargeable battery, because those are the only batteries that would supply the power used by the servo motor. In the end product it is recommended to use either over 7.5V worth of AA batteries, or even D batteries, or use a wallwart to hook it up to mains. As you can see in the circuit board I put a 10uF capacitor (it doesn't hurt to make this bigger) over the input voltage, and a 0.1uF (tantalum is preferred for speed, but ceramic works well and is easier to use, as it doesn't have polarity) capacitor at both the servo motor connector as well as the microcontroller.
As microcontroller I used a PIC16F688, mostly because it is so nice and small, and modern, allowing it to be easily programmed using the PicKit 2 (you can even program it in the PicKit 2 demo board: even though it is made for the 16F690, it fits the 16F688 equally). I used the usual 6 pin programming connector, which, if mounted as displayed, is really easy to hook up: the three pins next to the PIC16F688 (pins 3-5) can be connected directly. The fourth pin (6) is left floating. 2 is connected to the top pin on the other side, as this is the other voltage, and 1 is connected to the reset line, which is the middle pin on the other side of the Microcontroller. For this I use a white wire, so it is quite recognizable on the board, so I can match the triangle of the PicKit 2 with the white wire and do not mistakingly connect it the wrong way.
The final two components are the potentiometer, which is connected to the analog port of the 16F688 and is used as input for the servo motor, and the servo output. On the servo output pins 1 and 2 are connected to the power directly, and 3 is connected to the output pin of the microcontroller that is used to control the servo. Obviously multiple servos can be attached using different pins of the microcontroller. Note that once you exceed two servos, a separate power circuit is needed for the next two. The ground will need to remain the same, to ensure proper functioning of the control line.
The software that I wrote for this servo controller is very basic: it measures the potentiometer and moves the servo motor accordingly. The plan was to include a system that registers the sequence of movements of the potentiometer in memory. This is not very difficult to develop, but the higher resolution of 512 values as well as the limited storage of 256 bytes inside the 16F688 made this trickier. I was contemplating using the difference between two settings and storing it in a 4 bit value, but never got to implement this.
Abonneren op:
Posts (Atom)