Use the support Web site. It is an important part of all the information you have access to with this tutorial. Specific to the following chapters, it has extensive pictures on it that show how all the projects were built by me, and these can be a tremendous help to you in building your own projects, even if you decide to modify and extend the projects beyond the minimal and basic construction I have undertaken. The pictures are in color and color adds a lot of useful information.
You must become comfortable with eight basic techniques to be able to design and build instruments and controllers that can monitor or control the variables and properties you have an interest in. They are
1. Counting synchronous and asynchronous pulses.
2. Creating accurate short- and long-timed intervals with timers.
3. Using counters effectively.
4. Sensing and reading analog voltages.
5. Using pulses to control external devices.
6. Creating simple scanning routines to monitor phenomena.
7. Controlling the property or function you are interested in.
8. Logging data over an extended time period automatically.
The eight basic constructions in this tutorial cover these techniques one at a time. The projects are designed to give you an expansive view of the many possibilities that using PIC microprocessors offers you, the experimenter. They selectively demonstrate what can be done by the amateur experimenter and engineering student with fairly minimal resources. This is an introductory tutorial, as opposed to a highly technical treatment you might find in a more rigorous text. The projects are fairly straightforward and are designed to expand your horizons and give you the confidence you need to create and build the instruments necessary for the work you want to undertake. They demonstrate a varied approach to a seemingly random set of problems, which when seen as a whole, give us the experiences we need to move to the next level, which is of course the design and construction of the instruments required.
The eight instruments are:
Instrument Name |
Function Being Studied |
1. Tachometer |
Counting pulses (synchronous) |
2. Metronome |
Timer techniques |
3. Marble counter |
Counting techniques (asynchronous) |
4. Dual temperature sensor |
Analog-to-digital conversion considerations |
5. Artificial horizon table |
Converting pulses to motion |
6. Touch screen |
A useful real-world scanning application |
7. Single-point controller |
Controlling a “set point” process with details |
8. Solar collector |
Data logging over time |
These eight projects represent the eight fundamental techniques you must master to be able to build the instruments and controllers you need. Each instrument in the series is designed to isolate and address one part of the data collection or conversion problem. Once we understand the basic components in these systems, we can proceed with the techniques necessary to design the PIC-based instruments necessary for the tasks at hand.
As always, the first thing we must do is to convert the signal we are interested in into a useable digital format. Often, you may need to amplify the signal before converting it to the digital format required.
1. The tachometer project is a basic exercise in understanding the counting of pulses that can come in at widely varying rates. (It also teaches you how to use seven segment displays.)
2. The metronomes have to do with learning how to use the timers to create accurately timed intervals. The metronomes we create will operate identically, but will use the various timers to create the intervals needed. This is a detailed exercise in the use of timers in the PIC 16F877A. Both the LAB-X1 and the tachometer created earlier will/can be used to create the metronomes.
3. In the marble counters section, we will learn about good, bad, and ambiguous signals, and experiment with some of the techniques used for sorting things out with a microprocessor as we collect the data. These counting techniques can and will be applied to all sorts of instruments that you create in the future.
4. The two thermometer instrument allows you to measure two quantities simultaneously. Both are temperatures, but they do not have to be. One can also be designed to be a set point. This is the basic instrument/controller, and the instruments you create will essentially be variations of this project, with the appropriate signal conversion modules added. Later on in Project 13.7, we will convert this instrument into a controller, and then in Project 13.8 we will use it to log the data from a solar collector over an extended period. It is important to understand that the two quantities considered do not have to be the same thing. We could use the linear brightness of a light to control the parabolic speed of a motor by putting the information through a custom-designed controller.
5. In the artificial horizon project, we learn how to use pulsed signals read from a sensor to control the position of a table positioned with two model aircraft servos. The servos are fed signals that are a function of the error signal read from the sensor and hold the table in a horizontal position.
6. Building the touch screen is the basis for learning about scanning routines. Though this is a relatively small surface, we can demonstrate and learn about the techniques used to make a touch screen with this project. A touch screen is a control panel you can make on the laboratory bench with minimal cost and effort.
7. The two-input controller is a finished instrument that incorporates the competencies learned in the previously mentioned projects. We then use this instrument in the next project to create a data logger.
8. Data logging is covered in the context of a solar collector and uses the two-input controller to provide the data that we then log over an extended period of time automatically. The data will be sent to a personal computer for storage and go through eventual analysis at a later date.
Adding a little more detail to the preceding descriptions, we will discuss, then build, and hopefully understand the engineering and science behind the following eight projects.
1. THE BASICS OF COUNTING PULSES: THE TACHOMETER PROJECT
Research has indicated that carefully managing the engine speed as you drive around town can substantially increase the efficiency of your automobile. Design and build an inexpensive tachometer that can be added to an automotive engine with minimal effort. Design the device to display the engine rpm (revolutions per minute) on a four-digit display. The display and the CPU board are to be placed at some convenient location in front of the driver. The system must use the 12 dc power available on the automobile and start when the ignition switch is turned on.
This is an exercise in counting pulses that come in at various rates, and displaying the results on seven-segment displays or on an LCD. Almost all the signals we use with microprocessors end up having to do with counting and manipulating pulses, so this is a core competency you must master.
2. THE METRONOME: CREATING CONTROLLED PULSES
Ms. Music, our local high school music teacher, did not get the funding for the metronomes she wanted for her class. The principal has asked your electronics instructor so see if he/she can get the class to create 25 low-cost metronomes for the music students.
The electronic metronome is an exercise in creating accurate time intervals that are controlled from a potentiometer on both the LAB-X1 board and the tachometer board. The exercise includes programming for both the LCD on the LAB-X1 and for a display consisting of the 4 seven-segment LEDs used on the tachometer in the first exercise.
3. COUNTING MARBLES: DISCRIMINATING BETWEEN VARYING PULSED SIGNALS AND FEEDING THE TIMER/COUNTERS
Part 1… Mr. Marbles the manager of the local marble factory has been plagued with marble counting problems and has approached the head of the electronics department to see if he can come up with an inexpensive solution. The class is charged with designing a marble counter that counts the marbles as they go by single file at the rate of about ten marbles per second, and the factory manager wants to increase that rate as much as possible. The counter that can count the highest number of marbles in 10 seconds accurately will be selected as the instrument of choice by the plant manager.
This is about learning how to count the pulses we encounter when processing information. Some come in slow, some come in fast, some come in very fast, and some are hard to discriminate from the background noise. This exercise exposes you to these real-world problems.
Part 2… Mr. Marbles, our friend from the marble factory, is so happy with the performance of the counter we made for him earlier that he has come back to us for an even faster counter. “What can you make in the way of a really fast counter?” he asks. We have convinced him that we can make him what he would consider a really fast counter, but the marbles need to go by single file just as they did for the previous counters. To this he has agreed.
This instrument will count how many common everyday glass marbles go by its so-called gate. We are doing this just to do it! Someone might just have a use for this, or a modified version of this, but our purpose here is to understand the detection, amplification, and the counting of small seemingly random signals coming in helter skelter.
In this experiment, things start to get complicated and we have to use our wits to figure out how we can solve the problems. So, in a way, this is an exposure to the real world.
4. THE DUAL THERMOMETER: TWO ANALOG SIGNALS CONVERTED TO DIGITAL AND DISPLAYED
Dr. Thermo is in the process of undertaking a large research project to check the energy transfer across a large number of coils to be used in the air-conditioning industry. He has indicated that he needs to know how the temperature of the air and the temperature of the cooling brine changes as the heat exchange takes place. Design an instrument to display the inlet temperature and the outlet temperature for both fluids.
The instrument is an electronic thermometer that reads two temperatures simultaneously. This is an instrument you can use every day in your day-to-day monitoring of the systems around you. Each sensor costs about $3. This exercise is about reading analog signals, converting them to digital format, and then interpreting them for display on a two-line liquid crystal display. With this instrument you can determine the energy flow in most systems if you know the rate of flow and the mass properties of what is going by.
This project contains the basic techniques you will need to master to process analog signals as opposed to digital signals.
5. AN ELECTRONIC ARTIFICIAL HORIZON: SOPHISTICATED INSTRUMENTS MADE EASY WITH MICROCONTROLLERS
Parallax sells a very interesting gravity sensor that indicates the change in gravity in both the X and Y directions as well as the ambient temperature at the instrument as three frequencies. (We will not use the temperature sensor part in our experiments.) The sensor can sense up to 2 Gs of acceleration with a surprisingly good resolution of 0.001 G (a milli-G). We will use this device to create a two-axis table that stays horizontal while the surface it is mounted on is turned every which way (within about 20 degrees) relative to the horizon.
The accelerometer we will be using is the Memsic 2125. The Parallax company delivers it already mounted on a tiny board with pins at 0.1 inches on center. It plugs directly into an experimental breadboard with standard 0.1 inch on-center holes. There are only six pins, and two of them are at ground! Three other lines provide the three frequencies we are interested in, while the sixth pin is the power pin. How simple can this get?!
The signals from this sensor are in the form of frequencies that vary with the tilt of the sensor in the X and Y direction (and the ambient temperature). The sensor is most sensitive near horizontal, and least sensitive when the sensor axis is held vertical. We can take the frequencies received and process them so they give us the signals we need to control a couple of hobby R/C servos. The linkages between the servo and table are to be arranged to keep the table approximately level. The final correction can be provided in software with a lookup table but that may not be necessary depending on how we design the software!
6. THE TOUCH SCREEN
The touch screen teaches us how to scan a number of signals to decide what needs to be done under circumstances controlled by the signals. Useful touch panels can be created to simulate the operation of control panels for electronic devices with minimal expense. In this exercise, we create a touch panel that controls the blinking rate of two LEDs and displays the conditions at the panel on the LCD.
Simple touch panels can be placed in front of simple graphics to create the inputs we need to control the instrument and controller we are building.
7. THE FINISHED CONTROLLER
In this project, we convert the two-temperature thermometer into an adjustable thermostat with an external inhibit capability to demonstrate our ability to create a controller/instrument.
Now that we have a working two-thermometer sensor, we add communications to it and create a system that logs the conditions inside a solar collector, to a PC, automatically every minute (or another time interval) for a year.
A large portion of the tutorial is devoted to each one of the preceding devices, and building instructions as well as a discussion of the theory and the programming techniques used are included in each chapter.
In the following exercises, we will rely as much as we can, on the capabilities of the PIC and try to do the projects with as few external components as possible to keep our costs down and to increase our knowledge of using the PIC to do whatever it is capable of doing. For example, in the first project, the tachometer, we could easily have used ICs that convert BCD (binary coded decimal) data to what is needed by the seven-segment displays to display a number, but we did it without the ICs to learn how this can be done with the PIC alone.
On the software end, we will use as few of the instructions from PROBASIC as possible to keep the emphasis on the design of the instruments as opposed to mastering the tricks and techniques possible with the extensive software language.
The emphasis is on the PIC and what is inside it.
STOP! STOP! STOP! STOP! STOP!
ONCE IN A LIFETIME CHANCE
TO EXERCISE YOUR WITS!
You now have a rare opportunity to exercise your creative thinking!
Now that you know what we will be building, you can substantially increase what you will get from these exercises by not reading the following pages for a couple of days and spending time thinking seriously about how you would use the resources available to you to design the instruments described in this chapter.
Make drawings and sketches of what you would do in your shop log. Later, it will be instructive to compare what you envisioned with how I have described the instruments. Hopefully, what you come up with (in at least some cases) will be more inspired than the simplified methods and techniques offered in this tutorial.
Good luck.