Silicon ChipA Multi-Function GPS Car Computer, Pt.2 - February 2010 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Wind farms are a blight for people in their vicinity
  4. Feature: A Look At Automotive On-Board Diagnostics by John Clarke
  5. Feature: Saving the Whales with the Aussie Pinger by Ross Tester
  6. Project: An OBDII Interface For A Laptop Computer by John Clarke
  7. Project: A Milliohm Adaptor for Digital Multimeters by Jim Rowe
  8. Project: Internet Time Display Module For The WIB by Mauro Grassi
  9. Project: A Multi-Function GPS Car Computer, Pt.2 by Geoff Graham
  10. Project: Precision Temperature Logger & Controller, Pt.2 by Leonid Lerner
  11. Vintage Radio: The Mullard Meteor 600 4-Valve Mantel Receiver by Rodney Champness
  12. Book Store
  13. Advertising Index
  14. Outer Back Cover

This is only a preview of the February 2010 issue of Silicon Chip.

You can view 17 of the 104 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "An OBDII Interface For A Laptop Computer":
  • OBDII Interface for Laptop Computers PCB pattern (PDF download) [05102101] (Free)
  • OBDII Interface for Laptop Computers front panel artwork (PDF download) (Free)
Items relevant to "A Milliohm Adaptor for Digital Multimeters":
  • Milliohm Meter Adaptor PCB [04102101] (AUD $10.00)
  • Milliohm Meter PCB pattern (PDF download) [04102101] (Free)
  • Milliohm Meter front panel artwork (PDF download) (Free)
Items relevant to "Internet Time Display Module For The WIB":
  • dsPIC33FJ64GP802-I/SP programmed for the Webserver in a Box (WIB) [0711109A.HEX] (Programmed Microcontroller, AUD $25.00)
  • Webserver in-a-Box (WIB) Programming Tables (PDF download) (Software, Free)
  • dsPIC33 firmware (HEX file) and website files for the Webserver in-a-Box project (Software, Free)
  • Webserver in-a-Box (WIB) PCB pattern (PDF download) [07111092] (Free)
  • Webserver in-a-Box (WIB) front panel artwork (PDF download) (Free)
  • Webserver in a Box (WIB) Internet Time Display Module PCB [07102101] (AUD $10.00)
  • PIC18F1320-I/P programmed for the Internet Time Display Module [0710210A.HEX] (Programmed Microcontroller, AUD $15.00)
  • PIC18F1320 firmware and source code for the WIB Internet Time Display module [0710210A.HEX] (Software, Free)
  • Webserver in-a-Box (WIB) Internet Time Display PCB pattern (PDF download) [07102101] (Free)
Articles in this series:
  • WIB: Web Server In A Box, Pt.1 (November 2009)
  • WIB: Web Server In A Box, Pt.1 (November 2009)
  • WIB: Web Server In A Box, Pt.2 (December 2009)
  • WIB: Web Server In A Box, Pt.2 (December 2009)
  • Web Server In a Box, Pt.3 (January 2010)
  • Web Server In a Box, Pt.3 (January 2010)
  • Internet Time Display Module For The WIB (February 2010)
  • Internet Time Display Module For The WIB (February 2010)
  • FAQs On The Web Server In A Box (WIB) (April 2010)
  • FAQs On The Web Server In A Box (WIB) (April 2010)
Items relevant to "A Multi-Function GPS Car Computer, Pt.2":
  • GPS Car/Boat Computer PCB [05101101] (AUD $12.50)
  • PIC18F4550-I/P programmed for the GPS Car Computer [0510110E.HEX] (Programmed Microcontroller, AUD $20.00)
  • VK2828U7G5LF TTL GPS/GLONASS/GALILEO module with antenna and cable (Component, AUD $25.00)
  • Firmware (HEX file), source code and USB driver for the GPS Car Computer [0510110E.HEX] (Software, Free)
  • GPS Car/Boat Computer PCB pattern (PDF download) [05101101] (Free)
Articles in this series:
  • A Multi-Function GPS Car Computer, Pt.1 (January 2010)
  • A Multi-Function GPS Car Computer, Pt.1 (January 2010)
  • A Multi-Function GPS Car Computer, Pt.2 (February 2010)
  • A Multi-Function GPS Car Computer, Pt.2 (February 2010)
Items relevant to "Precision Temperature Logger & Controller, Pt.2":
  • Software for the Precision Temperature Logger and Controller (Free)
Articles in this series:
  • Precision Temperature Logger & Controller, Pt.1 (January 2010)
  • Precision Temperature Logger & Controller, Pt.1 (January 2010)
  • Precision Temperature Logger & Controller, Pt.2 (February 2010)
  • Precision Temperature Logger & Controller, Pt.2 (February 2010)

Purchase a printed copy of this issue for $10.00.

GPS Part 2 - by Geoff Graham Car Computer Last month, we introduced our new GPS Car Computer and provided full constructional details. But there’s a lot more that we haven’t covered yet . . . F irst of all, we’d better run through some of the functions of the GPS Car Computer for those who might have missed last issue. To build the GPS Car Computer you will, of course, need to refer to that issue. Operation In operation the GPS Car Computer is easy to use. There are seven “screens” that can be displayed and you can step through these screens with the UP and DOWN buttons. All screens have something that can be configured. For example, on the speedometer you can set the over-speed alarm and on the clock screen you can set the time zone. To change a setting you press the SET button and then use the UP/DOWN buttons to adjust the value. Pressing the SET button a second time will save the value and return to the main display. Rather than manually press the UP/DOWN buttons to show a new screen you can put the unit into “Auto Scan” mode. Here the display will automatically flip from one screen to the next every three seconds. When it reaches the end it will wrap around and continue on from the beginning. To enter Auto Scan mode you simultaneously press both the UP and DOWN buttons. To exit this mode press any button. 78  Silicon Chip To reduce the number of screens on show you can configure the unit to hide some of them. To set this up you must hold down the UP button when you apply power. This will put the unit into a mode where you can set the following characteristics for each screen; • Show. • Hide in auto scan. • Always hide. The latter is useful if, for example, you have not connected the unit to a fuel injector solenoid and do not want to see the Fuel Economy display. When set to “Always Hide” that screen will be skipped as if it did not exist. The “hide in auto scan” setting is useful if you want to hide some screens during the Auto Scan mode but still have them available when you manually step through the screens. A good example is the “Signal Levels” screen which you would not normally need to see. While in this mode pressing the SET button will step you through the three settings described above and the UP and DOWN buttons will move you through the list of screens available for configuration. To exit this mode you simply remove and reapply the power. All settings including the currently showing screen are siliconchip.com.au One of the features of our GPS Car Computer is its ability to integrate, via USB, with mapping software on a laptop; in this case OziExplorer, ideal for “back ’o’Bourke” use. The raw data is shown on the GPS Car Computer LCD screen (at left) – 93km, 52 minutes to the destination – but much more information is available on the laptop screen for the navigator to use! automatically saved in non-volatile memory and restored on power-up. Data Display Most of the displayed data comes from the GPS module; it provides speed, time, heading, altitude, latitude/longitude and signal levels. Other displayed data is calculated internally by the microcontroller. The GPS will put out fresh data every second so this is the update frequency adopted by the microcontroller. The speed reading is averaged internally by the GPS module so that the numbers do not jump around with signal noise. As a result it will take a few seconds for the speedometer to settle down. The other readouts update much faster. The distance and time-to-destination is calculated by taking the speed every second and working out the distance travelled during that second. This is then subtracted from the total distance to the destination and the result displayed. While not as accurate as a GPS with in-built maps, it does give a good indication. This function has two main uses. It is handy when you Three of the more common displays you’ll use on the GPS Car Computer. At left is the speedo, arguably quite a bit more accurate than the one on your dashboard! Centre is the distance and time to destination and at right, relative fuel economy. siliconchip.com.au February 2010  79 need to drive along a road for a certain distance to reach a defined point (eg, “drive for 15km then turn left”). It is also useful when you need to count down a larger distance. For example, the next town might be 200km away and you are planning to stop there for lunch. This function will then show you how much longer you will have to put up with hunger pains! The time-to-destination is calculated by taking into account your average speed over the last 10 minutes. So, if you get stuck behind a slow-moving truck you can expect to see the time before lunch increase accordingly. This function is also handy for children who continuously ask “How much longer Daddy?” Economy meter The fuel economy meter is another function that is calculated internally by the microcontroller. While it sounds complex it is quite simple to implement. The microcontroller monitors the percentage of time that a fuel injector solenoid is opened in any second. That, combined with the vehicle speed over the same second, is used to calculate the amount of fuel used per kilometre driven. This assumes that the pressure in the fuel line to the solenoid remains relatively constant and that all solenoids for all cylinders open for the same amount of time. For this purpose these assumptions are close enough and the upshot is that the percentage that the solenoid is open is directly proportional to the amount of fuel consumed by the vehicle. The result is displayed as a bar graph. A longer bar means that you are consuming more fuel per kilometre than a shorter bar. You can adjust the full-scale sensitivity to suit your car and preferences. When driving you should try and keep the bar as short as possible. You will find that during acceleration from a standstill the consumption will shoot off the scale. Not much can be done about this because you are consuming a large amount of fuel for only a small (zero) distance travelled. At cruising speed the graph will sit in the middle of the scale and you can vary it markedly depending on your driving habits. Computer interface The USB interface allows you to connect to any computer with a USB interface. In this mode the GPS Car Computer implements a subset of the NMEA-0183 standard for interfacing marine electronic devices as defined by the USA based National Marine Electronics Association (NMEA). This is an almost-universal standard and most software will communicate seamlessly. If you search on the internet you will find a wealth of software that will allow you to navigate, log your movements, play with the GPS module and much more. We will only cover a few here but you can check www.maps-gps-info. com/fgpfw.html where over 450 free GPS-related programs are listed. While you are using the USB interface the GPS Car Computer Display will continue to operate as normal, showing speed, heading, etc. So it is possible for the driver to have whatever data is of interest showing, while a passenger can be separately using a laptop for navigation or other GPS related functions. Before you can use the GPS Car Computer with your computer you must install the appropriate device driver. This can be downloaded from the SILICON CHIP website where it is listed as “Silicon Chip USB Serial Port Driver. zip”. The driver will work with Windows 2000, XP, Vista and Windows 7 in 32-bit mode and Vista/Win7 in 64-bit mode. It uses the standard CDC serial interface supplied by Microsoft with all modern versions of Windows and there are also Linux versions available on the Internet. The USB standard says that all USB devices must have a unique combination of two 16-bit numbers - the Vendor ID (VID) and Product ID (PID). When you plug in a USB device the first thing it does is send its VID and PID to your computer, which in turn uses them to locate the correct device driver. If you did not use a unique VID/PID you could have confusion where, for example, your computer might try to This screenshot of the PuTTY terminal emulator program gives a good idea of what the data stream received over the USB interface would look like. The format of the data meets the NMEA-0183 standard which is a universal communications format used by most GPS related software. 80  Silicon Chip siliconchip.com.au Here’s a screenshot of the BSGPS software using a map downloaded from the OpenStreetMap project and live data from the GPS Car Computer. You can see that we are travelling up Bland St approaching Birdwood Ave – not bad for software and maps that cost nothing. load the device driver for an Apple iPod. Manufactures can purchase a Vendor ID (VID) from the USB standards body and then use whatever Product ID (PID) numbers that they need in combination with the VID to differentiate their products. Rather than purchase a whole VID for this project we sublicensed a single PID from Microchip for use with their corporate VID. These two numbers are used by the GPS Car Computer and the USB Serial Port Device Driver and ensure that our gadget is legally correct. Driver installation After downloading the driver you should unzip the files into a temporary folder. The method of installing the software varies between versions of Windows but essentially, when you plug the GPS Car Computer into an USB port the operating system will prompt for a driver. You should then point it to the temporary folder and install from there. If, for some reason, you are not prompted to install the driver you can navigate to Device Manager and you should see an entry under Other Devices called “SC GPS Display”. Right click on that and select Update Driver Software. You can then direct the operating system to the temporary folder. After you have successfully installed the driver you should see the GPS Display listed in Device Manager under Ports (COM and LPT) as “Communications Port - Silicon Chip USB Serial Port”. Take note of the COM port number allocated by the operating system, you will need this when siliconchip.com.au configuring software to work with the GPS Car Computer. In this mode the GPS Car Computer appears as a virtual serial port in the operating system. You can use any serial terminal emulator such as Hyperterminal, PuTTY, RealTerm or Hercules Terminal Emulator to access the data. When you run the emulator and configure it for the correct COM number you should see the data streaming from the GPS module. The screenshot of the PuTTY terminal software gives a good example of what you can expect. Note that when setting the COM port number the baud rate and other settings are ignored – the USB Serial Port always runs at the highest speed it can. A good utility for testing the interface is “NMEA Monitor” (http://homepage2.nifty.com/k8/gps). This will show you the raw data as well as decode the NMEA sentences and will give you a better insight to what is going on. Using NMEA Monitor or a terminal emulator you can also send commands to the GPS module. You should be careful here as the microcontroller in the GPS Car Computer expects that the module will be in the normal factory default mode and it may not work if you have changed things too much. In particular, you must be careful not to change the baud rate. The GPS module communicates with the microcontroller at 4800 baud and if you change this nothing will work, including your USB serial interface, even if you remove and reapply power. If you have screwed up the GPS module you can try pressFebruary 2010  81 Here’s a larger view of the OziExplorer software shown on the laptop earlier, with a high resolution HEMA map. Position and heading is shown on the map as a red arrow with the tip pinpointing our exact position. This is live data using the GPS Car Computer. The map will move as the vehicle travels keeping our current position in the centre. The software also shows our speed (98.1Kmh) and altitude (198m). ing the Down Button while plugging the GPS Car Computer into power. This will cause the microcontroller to send a reset command to the GPS module and may recover the situation, although it is not guaranteed. Navigation software The most impressive use of the computer interface is with navigation software running on a laptop. With it you can get a moving map, with your position pinpointed exactly. It is worth noting that this is different from the normal GPS units that you can purchase such as the TomTom or Garmin devices. These are optimised for city driving and, as a consequence, are focused on taking you to a certain place rather than telling you where you are. In addition the accuracy of their maps is very poor once you get into rural areas. This is no good for country travellers and in particular 4WD drivers who are navigating across country following little used roads or tracks. In this case you want to see your exact position on a detailed and accurate map. You certainly do not need to be told when to turn right or left as intersections are far between and generally obvious, when you come to them. A typical software package for this type of navigation is OziExplorer with the HEMA map package for Australia 82  Silicon Chip (oziexplorer.com and hemamaps.com.au). Both of these will load onto your Windows based laptop and combined will give you the equivalent of a detailed printed map. The GPS Car Computer works fine with this type of software and the result is that your exact location will be pinpointed on a high accuracy map with a scale of 250 metres per millimetre (depending on the maps that you bought). The HEMA maps are rather expensive so OziExplorer allows you to scan in your own maps but you still have to buy the software. A number of lower cost alternatives exist and a good example is BSGPS (bettersoftware.co.uk) which is essentially free (they ask for a donation). This software also allows you to scan your maps so you can continue to keep the cost low. If you mostly keep to the more populated areas you can use BSGPS with the OpenStreetMap project (openstreetmap. org). This is a free editable map of the world and contains reasonable detail for urban locations. Using BSGPS you can download the sections that you are interested in and have a very low cost navigation solution. If you have Internet access on your laptop (perhaps difficult in the bush but not impossible!) you could use the GPS Car Computer with Google Earth to dynamically download and display maps. You could even have your position plotsiliconchip.com.au Loading New Firmware The GPS Car Computer includes a small program which is called a bootloader. This enables you to reprogram (sometimes called “flashing”) the microcontroller using nothing more than a normal Windows computer with an USB port. To make it easy for us the GPS Car Computer pretends to be a Microchip PICDEM FS USB board when it is in the bootload mode. That means we can program it using software developed by Microchip to program their own products. Both the device driver and software described here are compatible with Windows 2000, XP (32 and 64 bit) and Vista (32 and 64 bit). Windows 7 is not supported yet but the software does work under the Windows 7 XP Mode. There also may be Linux and Mac versions on the Internet – check the Microchip website or Google for “MCHPUSB Bootloader” or “MCHPUSB Driver”. To start the bootloader, hold down the Set button on the GPS Car Computer while you plug it into a USB port on your computer. If you have not installed a jumper on JP1 you will then have to connect an external 12V power source and hold down the Set button while you plug that in. You can release the button a second or two after. Your computer should make a sound to signal that it has recognised the GPS Car Computer. Note that when it is in the bootloader mode the LCD panel will remain blank or may show some random lines, this is normal. If you have not used the bootloader before on your computer you will be prompted to install a driver for it. This driver is different from the virtual serial port driver used to receive GPS data from the GPS Car Computer. Your computer may attempt to find a driver currently on your computer or the internet. When this fails select the option to choose your own driver. The device driver is in the directory WinDriver which should have been created when you unpacked the zip file containing the updated firmware. Navigate to this directory and tell Windows to search there. When the driver is correctly installed you should see it listed in Device Manager as a “Microchip Custom USB Device”. When you u n p a ck t h e upgrade zip file you should also have a directory titled WinLoader and in that directory will be PDFSUSB. exe. This is the program that uploads new firmware to the GPS Car Computer and is actually intended for use with the Microchip PICDEM FS USB board. Because of this it includes many extra features that we will not be using and can safely ignore. Double-click on PDFSUSB.exe to run the loader. After it has loaded, you can click on the dropdown list and you should see listed PICDEM FS USB which is what the GPS siliconchip.com.au Car Computer masquerades as while it is in the bootload mode. Click on that entry to select it, then click on “Load HEX File” and navigate to and select the new firmware that you want to load. When you load the HEX file you should see a message warning that the configuration data is different from the board’s default setting. Click on Cancel – do not select any other choice otherwise your firmware will not load correctly. Finally, click on “Program Device”. You will see a series of messages and after about 20 seconds it should display the messages shown in the screenshot, which indicate that the GPS Car Computer has been successfully reprogrammed. You can then unplug the GPS Car Computer and use it as you would normally do. Don’t worry about a power failure or accidently unplugging something while it is programming. If something does goes wrong you can always restart (ie, unplug, then plug back in while holding down the Set button). February 2010  83 A challenge . . . re input/ S Car Computer has two spa As described earlier, the GP . Do you ting res inte ing eth used for som eal to output lines that could be app uld your idea is useful and wo ision. have an idea for them? If rev re wa orate it into a future firm our readers we could incorp au. iliconchip.com. is not a Drop us a line at silicon<at>s lement everything as there imp to tee ran a try. We cannot gua rth wo program memory, but it is ld cou lot of space left in the micro’s re the s; car also not restricted to n Eve The GPS Car Computer is t. res inte ent fici n if there was suf sio ver l tica nau a be an ily as eas used suggested that it could be more radical, it has been clock!) The S GP r the ano yet not , ck (no accurate bedside alarm clo r electric you of l used for timed contro various outputs could be tle. n turn on the ket blanket, your radio and eve , display, l purpose device with I/O era gen a as it Just think of k or 12V. pac all powered from a plug re is no USB and an optional GPS, the ily eas be re-programmed so of the Because the gadget can ns sio ver nt ere not be many diff know, reason why there could us Let y. alit son per a different firmware, each providing ething interesting. your idea could trigger som e errata, b page to provide up to dat we The author has set up a check can You r. ute mp the GPS Car Co notes and new firmware for gpscomputer. it out at http://geoffg.net/ ted on a moving satellite image of the country through which you are travelling. Isn’t technology wonderful? External connections All external connections are made through CON1, a 6 pin mini DIN connector. Ground and 12V are on pins 3 and 4 (respectively) of the connector. An external input from the vehicle’s headlight’s circuit can be wired to pin 1 to control the day/night backlight brightness (more on this in the section on assembly options). Pin 5 of the connector can be wired to a fuel injector solenoid if you want to implement the fuel economy meter function. The 82k and 47k resistors serve to drop the vehicle voltage levels to 5V for the microcontroller. There are also two spare connections (pins 6 and 2) which can be connected to pins 9 and 10 of the microcontroller. These are unused and available for future use. They can be set by the firmware to be digital inputs, digital outputs or analog inputs. Future firmware updates could use these to measure voltages (eg, battery voltage or sensor outputs), detect digital inputs (eg, switch closure or tachometer output) or set them to be an output to control something. Firmware In Part 1 last month we described the circuit for the GPS Car Computer but it is in the firmware where the real work is done. We will not go into detail here but if you are really interested the source code is available for download from the SILICON CHIP website. On the surface it appears that the microcontroller only needs to take the data from the GPS module and display it on the LCD and that should be simple enough. As usual, the devil is in the detail and the result was rather more complex – the firmware runs to over 7000 lines of C code. Part of the reason for this size is that we use a graphics display and while this allow us to turn off or on any pixel, it does involve a much greater overhead to drive. For exam84  Silicon Chip ple, we have to create our own fonts - in total we use three different fonts ranging from very large numeric digits for things like the speedometer through to a small font used for detailed screens like the latitude/longitude display. Other features including USB and high speed refresh of the graphic display also add up so that in the end the firmware uses most of the PIC18F4550’s 32KB program space. In summary the operation of the firmware is easy to explain. Firstly there are three interrupts that operate, one when a character is received from the GPS module, one that is triggered by a timer every 85S and one when the USB interface has received or sent a packet of data. The interrupt does just what it says – it interrupts the processor and branches to a different segment of code to do some special processing. For example, when a character is received from the GPS the interrupt code will retrieve that character and store it in memory. When the last character of a message has been received the interrupt code will set a flag to indicate that all the data has been received and is available for processing. Following the interrupt the processor will return to executing the main program at exactly the spot from where it was interrupted. As a result the main program is unaware that the processor has been “hijacked”, all it sees is that a flag has been “magically” set to indicate that there is a message from the GPS ready for processing. Similarly the interrupt triggered by the timer every 85S performs a number of tasks, one of which is to tell if a button has been pressed. There are three flags, one for each of the buttons and the interrupt code will set the appropriate flag when it detects a valid button press. Oblivious to the interrupts, the main code runs in a high speed loop checking these and other flags for something to do. For example, if the main program discovers that the GPS data flag has been set, it will process the data to extract the information that we want. It will then construct an image of the currently showing screen as a bitmap in internal memory and transfer this image at high speed to the LCD’s display memory. “State Machine” An important part of the main program is that it implements what is called a “state machine”. Each display on the graphics display is represented as a “state”. So, when we are displaying the digital speedometer the state machine is in the “display speed state”. When adjusting the over speed setting the state machine is in the “set over speed state”, and so on. The state machine is necessary because an event like pressing the Up Button can mean different things, depending on what state the display is in. For example, when displaying the speedometer, the Up Button will cause the display to switch to the clock display but when adjusting the over-speed setting the Up Button will increase the setting by one km/h. The state machine keeps track of the current state and changes states as necessary. It also directs processing according to the event being processed and the state that is current. Generally a state machine is at the core of most gadgets (microwave, dishwasher etc) and is not very mysterious. If you download the source code for the GPS Car Computer and search for the main() function you will see the state machine implemented in that function. SC siliconchip.com.au