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
Microcontroller LCD interface using HD44780
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.
woensdag 19 november 2008
Camera GPS official version

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
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
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

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

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

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

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)