Although ‘just for fun’ robotic applications can usually male do with the few bytes to few hundred bytes of Flash memory that’s available in most current microcontrollers, certain more ‘serious’ or more complex applications do need much greater mem-ory capacities. A mobile robot may hold in its memory a complete mapping of an area in the form of co-ordinates like those provided by a GPS, for example. Alterna-tively, it may be required to collect a large quantity of data furnished by its sensors. Faced with such a situation, it is of course possible to produce one or more special memory cards using the high-capacity Flash EEPROM packages available on the market today. However, this approach fairly soon comes up against numerous problems. The first is making the necessary PCBs. Most memories of this type are only available in SMD packages, and their dose pin spac-ing makes producing a PCB a tricky job for amateurs, not to mention the difficulty you then have soldering such ICs correctly. The second problem is that as these memories are intended above all for the professional market, they’re sometimes very difficult for amateurs to get hold of.
So in this article, we’re proposing aril original solution to this problem, provided your robot is fitted with at least one PIC microcontroller and you don’t mind pro-gramming it in Basic. You’ll agree these are relatively minor constraints, especially when you think that by doing it this way you’ll be able to give your robot a gigabyte or even more of memory for just a few tens of pounds! The memory we’ve adopted is quite simply the memory sold in the form of SD cards (Secure Digital), originally intended for digital cameras and portable music devices. This memory is very inexpensive today (around f 7 for 1 GB at the time of writing), very compact, and unwaveringly reliable, provided you do not exceed the maximum number of write cycles, which is, however, hundreds of thousands, or even millions, depending on how optimistic the manufacturers are. The hardware interfacing of such memory with a PIC microcontroller is relatively easy, as the SD-type memories’ mode of operation is compatible with the SPI-type synchronous serial interface available in these microcontrollers.
The only thing to watch out for is the electrical levels, as these memory cards work on 3.3 V while the PICs in our robots are most often powered from 5 V. The figure suggests a circuit that can be used with all PIC microcontrollers in the PIC18 family from Microchip. However, the problem is noticeably trickier when it comes to the software for managing these memory cards. Contrary to what we might at first think, these are not just simple EEPROM Flash memories with serial access, but modules that have their own internal intelligence. So it’s not possible to read or write directly to these memories as you would do with an ordinary serial access EEPROM like 2406, for example. The dialogue has to respect a precise protocol, as the card only recognizes and responds to a certain number of commands. We also have access to various internal registers for quite specific purposes. Lastly, the location of the data in the card is net just ‘any old how’, but follows a principle similar to that found on diskettes and hard disks, using, in particular, a FAT (File Allocation Table) that shows where the data, contained in files, as a result, are stored. Even though it is possible to manage all this information by writing the necessary sub-routines yourself in machine language, this is a long, tedious, and error-prone task Very, fortunately, if you’re interested in using such a memory card in your robot, there is one Basic compiler (for PIC micro-controllers only, at the time of writing) that has a full management Library available for SD-type memory cards wired as shown in our figure.
This is the MikroBasic compiler from Mikroelektronika, which you can find on the publisher’s website (www.mikro-electronika.co.yu), with a working demo version allowing you to try it out before buying. Apart from those standard functions available in all Basic compilers for PIG worthy of the name on the market today, it has a full management library for SD-type memory cards (also for Compact Hash types, but they’re not the subject of this article). We’re not going to detail here the sixteen instructions available for manipulating SD cards, especially since you can download the manual for this compiler free of charge from the publisher’s website. Just be aware that using this product makes the management of such cards ever so much easier, to say the very least! So for example, if you have filled a buffer and want to now store it onto the SD card, all you have to do is write: status = MMC _ Write Sector (number, buffer) where
• status is a variable containing a numeric code returned by the command indicating the outcome of its execution (0 for successful, 1 for an error sending the command, 2 for an error during the writing proper).
• the number is the number of the SD memory sector we want to write to (we explained above that the data storage is similar to that on a hard disk, and now you can see this in practice).
• a buffer is a label marking the start of a buffer able to hold up to 512 bytes, which is the size of the SD card sectors. Reading the information stored on the SD card and transferring it to the robot processor’s RAM is just as simple, and amounts to a single line of code status = MMC _ Read _ Sector (number, buffer) where:
• status is a variable containing a numeric code indicating the outcome of the execution of the command (0 for success, 1 for failure).
• the number is the number of the SD memory sector we want to read.
• a buffer is a label marking the start of a buffer whose size must be at least 512 bytes; this buffer is going to receive the data read from the selected sector on the card. As you will note, it would be difficult for things to be much easier, even though in this article, by nature only a summary, we have not said anything about the card’s FAT management instructions. However, the latter is much less frequently used, once the structure of the card is defined, and a detailed, annotated example about these is Oven in the compiler manual. So then, if your robot needs lots of memory, lend it the SD card out of your camera and pay a visit to Mikroelektronika (www. mikroelektronika.co.yu).