Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Bailey O.H.Embedded systems.Desktop integration.2005

.pdf
Скачиваний:
73
Добавлен:
23.08.2013
Размер:
9.53 Mб
Скачать

250

Chapter 7 / Hardware Development

 

 

 

 

 

 

 

 

 

 

 

 

Figure 7-40: Inverted 1- and 3-Wire

Figure 7-41: Normal 1- and 3-Wire

Chapter 7 / Hardware Development

251

 

 

Chapter 7

Figure 7-42: Inverted keyboard, power, and alarm

Figure 7-43: Normal keyboard, power, and alarm

252

Chapter 7 / Hardware Development

 

 

Chapter Summary

In this chapter we have built the foundation for our embedded system. We now have boards that provide power, alarm capabilities, LCD interface, keyboard interface, temperature, time, and Dallas 1- and 3-Wire interfaces. You’ve been introduced to the BASIC Stamp microcontroller to understand how this device can be used to quickly test a circuit board and its functions. We have also learned how to make a circuit board from scratch using commercially available materials and a little elbow grease. In the next chapter we will add the BASIC Stamp board and build a completed prototype using the boards we have built here.

Chapter 8

The BASIC Stamp

2p Prototype

Overview

It’s time to complete our first prototype. In this chapter we will use the BASIC Stamp 2p microcontroller to complete our embedded system. We will implement our firmware in PBASIC, the free BASIC development system included with the Parallax products. In Chapter 7 we built several boards that will provide the needed functions for our prototypes. So we will begin this chapter with a road map of how our implementation will proceed. Once we have our strategy developed, we will build a BASIC Stamp prototype board so we can connect and test each of our components as we integrate the system.

Note:

Only code snippets that illustrate how to interface each device are provided in the text. Complete program listings can be found at www.wordware.com/files/embsys and at www.time-lines.com/embedsys1.

253

254

Chapter 8 / The BASIC Stamp 2p Prototype

 

 

Our Development Road Map

Since the BASIC Stamp provides a high-level language interface and doesn’t support true interrupts, we need to choose devices that will work within these design considerations. This means we need to choose components that are intelligent and easy to interface since the program running on the Stamp will be infinitely polling for activity. While we have already developed some of the circuits, we still need to determine the best design for communicating to our host systems. The functional aspect of this system has been predetermined in the design, so we are only concerned with the implementation in this chapter. Before we begin to develop the order in which the functions will be implemented, let’s first look at the host interface components that have been chosen.

The Ethernet device we have chosen is the NetBurner SB72. This is an economical board designed to provide either true RS-232 or TTL level RS-232 signals to a microcontroller or other serial interfaced device. It has full support for all Ethernet protocols including standard sockets (TCP/IP), secure sockets (SSL), email (SMTP), and web services (HTTP). This version of the prototype will only be using basic TCP/IP functions, but the expansion possibilities for future revisions are endless. Since expansion capabilities are already in the hardware, we need to only write or update the software to expand the system capabilities. This product also interfaces to the BASIC Stamp using the same interface pins as the RS-232 host connection. This means we can share BASIC Stamp I/O pins and design our prototype board to use either or both RS-232 and Internet interfaces at the same time for debugging purposes. We also have plenty of RAM and program space on the SB72, allowing us to set up large buffers if necessary so the chance of losing data is minimal. In order to effectively use the SB72 we will need to familiarize ourselves with the C language, the GNU C/C++ compilers, and the SDB debugger. We will also need to become familiar with the uC/OS,

Chapter 8 / The BASIC Stamp 2p Prototype

255

 

 

which is the real-time OS running on the SB72. The uC/OS is a multitasking system, so we can have multiple tasks running at once.

There is a wide selection of USB devices to choose from. We will implement two different types of USB interfaces that both use the FTDI serial-to-USB chip set. The first of these devices is from Parallax and is the SER2USB product. This is a very small and inexpensive product that uses transmit, receive, attention, and ground pins. As an alternative, we will also use the DLP Designs DLP-232BM product, which is a pin-for-pin replacement for RS-232 signals. Both of these choices use the same serial commands as the RS-232 and Ethernet interfaces but have different handshake requirements.

The DLP-232BM device provides us with the ability to simply swap the RS-232 interface for a USB interface at the embedded system side. This means that we can swap RS-232, DLP-232BM, or the SB72 with complete software transparency from the BASIC Stamp. There are no tricks here, but both the DLP-232BM and SB72 are intelligent, programmable devices. This gives us a lot of flexibility and additional functionality for this particular prototype. The SER2USB device from Parallax is a simple replacement for an RS-232 that has no onboard intelligence other than programmable baud rates and handshakes. The SER2USB, like RS-232, is strictly a protocol converter. Now you may be asking why we would use such a device. The answer is cost and board space. The SER2USB is the cheapest prepackaged TTL serial-to-USB device around for the BASIC Stamp. Because it simply converts RS-232 to USB, it also has the smallest footprint. If board space is at a premium or you want a very quick USB interface for data I/O, this device makes perfect sense. There are some differences at the software level that we need to consider for interface purposes; we will explore these later in this chapter.

Since we have already developed and tested our RS-232 level interface in Chapter 7, we can now move on to listing the required functions to make our prototype complete. The

Chapter 8

256

Chapter 8 / The BASIC Stamp 2p Prototype

 

 

following functions are needed to complete our prototype using the BASIC Stamp:

Display output — Formatted time, temperature, and error messages

Keyboard input — Function selection, menus, and variable storage routines

1-Wire functions to read and set date, time, and high and low alarm thresholds, service a temperature alarm, read/write to 1-Wire memory, read/display power outage and brownout counter, and read/display the current temperature

3-Wire interface to provide high-speed memory and clock access

High and low temperature alarm routines

Develop the host protocol to communicate with a desktop system

Implement RS-232 communications with a desktop computer

Implement USB communications with a desktop computer

Implement Ethernet communications with a desktop computer/LAN/WAN

Develop a device interface layer that will work on Windows, Linux, and UNIX to support a single-source code solution for all supported platforms

Develop a desktop application that will work on Windows, UNIX, and Linux using the same source code

Implement automatic fan control

Note:

The Dallas 1-Wire interface is very flexible but with that flexibility comes a level of complexity when adding devices while the network is in operation. To keep the 1-Wire interface simple we will add device IDs and types manually. There are plenty of resources that explain how to build more complex 1-Wire networks.

Chapter 8 / The BASIC Stamp 2p Prototype

257

 

 

Using the BASIC Stamp 2p24

We used the BASIC Stamp 2p24 device in the last chapter for testing but did not cover the specifications, so here are the highlights. The BASIC Stamp Professional starter kit contains most of the components we need for this chapter. The kit includes a BASIC Stamp 2p (with program memory, power regulator, and BASIC interpreter), a Windows versions of a BASIC editor and tokenizer (Linux users can find resources and resource links at the Parallax web site), serial cable, miscellaneous support components, and several Dallas 1-Wire components. Figure 8-1 shows the contents of the starter kit.

Chapter 8

Figure 8-1

Starting from the upper left and going clockwise we have the BASIC Stamp 2p24, clock crystal for Dallas 1-Wire devices, Dallas DS-1822 sensor, Dallas timekeeping chip, resistors, serial cable, manual and CD, and development board, which includes a prototype area.

258

Chapter 8 / The BASIC Stamp 2p Prototype

 

 

Implementation Strategy

The first step is to break down our task list into manageable pieces. To do this we will first take a look at all of the tasks needed to accomplish our end goal. The following list accounts for all the pieces that make up the temperature sensor and controller that have remaining work to be completed.

Display output

Keyboard input

1-Wire communications

RS-232 communications

USB communications

Ethernet communications

Desktop/host communication protocol

Read temperature

Set low alarm threshold

Set high alarm threshold

Temperature alarm detection and action

Fan control logic

Note:

Fan control is not required but for the experience we will examine how to control the fans. This would be required before the product goes to market.

The BASIC Stamp 2p24 provides us with 16 general-purpose I/O lines, unregulated voltage in (6 to 30 volts), regulated voltage out (+5 volts), ground, serial in, serial out, and one handshake line for programming.

Chapter 8 / The BASIC Stamp 2p Prototype

259

 

 

Developing Our BASIC Stamp Board

You’re probably wondering why we are making a BASIC Stamp board since one is included in the BASIC Stamp development kit. The board included in the development kit is a prototype board that is great for testing and debugging portions of a circuit. But as we progress through this chapter we will be interconnecting the modules together, and if we don’t make secure connections we will find ourselves in a bowl of spaghetti fixing broken wires. By developing our own BASIC Stamp board we will be using solder instead of wire-wrap or jumpers, making things much easier as we get closer to completion.

We will use off-the-shelf components whenever possible. Most of the components we use can be purchased at your local Radio Shack store. For those who wish to make a circuit board I will provide artwork at the end of this chapter just as I did in the previous chapter.

We will start by using another prototype board (Radio Shack 276-150). This board will provide enough space for the BASIC Stamp 2p24, our serial interface to the host, power LED, and Stamp reset switch. We will place a 24-pin socket (Radio Shack 900-7249) almost in the center of the prototype board so each row of pins is within a three-column contact. This will allow use to solder additional wires without the worry of overheating the parts. When completed your board should look similar to Figure 8-2.

Chapter 8

Соседние файлы в предмете Электротехника