Prototyping a Digital Tachometer Using Paralax MicrocontrollerBy: Kamran Niliemail: kn592@yahoo.com
It was about a month or so ago when I decided that I want to measure the RPM of one of my engines. I started to think about prototype my own digital tachometer. Also I wanted to have the flexibilities of customizing the circuit; therefore Microcontroller was a good choice for this project. I Looking at a few options and decided to go with Basic Stamp 2 Microcontroller made by a company called Parallax Inc. Parallax Inc. It took me almost 3 weeks form the day I decided that I want to build the circuit, ordering the parts, design, programming, and test it on my engine. Now I'm about to share my knowledge with you and show you all how to build this digital tachometer step by step. Let me start by saying that the initial coast would be around $90 and you need to have a PC. . But bear in mind, this $90 includes the programming board, microcontroller, cables, Basic Stamp 2 Microcontroller. Once you get the hang of it, you can do much
As you can see from the top picture, the size of this tachometer is a bit larger than commercial unit. Well this is why I called this article “Prototyping a digital tachometer”. Once we're satisfied with it functionalities, we can reduce the size to fraction of what it is can install it in a nice compact project box and move it around freely. If I see enough interest in this article, I can show you how to do that in the next article. I think enough said, so let us get technical and start building the circuit. The approach I like to take is as follow:
Terminology: These terms are used through out this document, so is a good review if you don't know them. Capacitor: An electronic component that can store and maintain an electrical charge for a period of time, releasing it cleanly and evenly. Capacitors are used to smooth out the flow of electricity. Hall Sensor: A Hall Effect sensor is an electronic device that varies its output voltage in response to changes in magnetic field density. Hall sensors are used for proximity switching, positioning, speed detection and current sensing applications. Resistor: A circuit component which offers resistance to the flow of electric current. Its electrical size is specified in ohms or megohms (1 megohm = 1,000,000 ohms). A resistor also has a power handling rating measured in watts, which indicates the amount of power which can safely be dissipated as heat by the resistor. Microcontroller: A single-chip microcomputer with on-board program ROM and I/O that can be programmed for various control functions. Multiplexer: This is a piece of hardware that allows one item to take the place of several. An example would be using a multiplexer to allow 10 computers to attach where only one could before. LED: A light-emitting diode (LED) is a semiconductor device that emits incoherent narrow-spectrum light when electrically biased in the forward direction. This effect is a form of electroluminescence. The color of the emitted light depends on the chemical composition of the semiconducting material used, and can be near-ultraviolet, visible or infrared. Nick Holonyak Jr. (born 1928) of the University of Illinois at Urbana-Champaign developed the first practical visible-spectrum LED in 1962 Jumper wire: A short length of wire to route a circuit by linking two cross connect termination points. Breadboard circuit: A circuit simulation using discrete components or partially integrated components to prove feasibility of a circuit. Power Supply: Well I let you figure this one out USB port: Universal Service Bus - used for connecting peripherals (printer, scanner, modem, etc.) to a PC off of a single port with the devices in a daisy chain. Computer Program: A series of instructions or statements, in a form acceptable to a computer, prepared in order to achieve a certain result. Debugging: The process of detecting and eliminating mistakes in computer programs or other software. Also called troubleshooting. EEPROM: Acronym for electrically erasable programmable read-only memory. Pronounced double-ee-prom or ee-prom, an EEPROM is a special type of PROM that can be erased by exposing it to an electrical charge. Like other types of PROM, EEPROM retains its contents even when the power is turned off. Also like other types of ROM, EEPROM is not as fast as RAM. EEPROM is similar to flash memory (sometimes called flash EEPROM). Bit: A single binary digit. Is either 0 or 1. 8 bits is on byte Byte: Eight bits. The byte is the basis for measurement of most computer data as multiples of the byte value. A "megabyte" is one million bytes or eight million bits or a "gigabyte" is one billion bytes or eight billion bits. 1 gigabyte = 1,000 megabytes 1 terabyte = 1,000 gigabyte Requirement: In order to design something successfully, the first thing is to gather the information about the functions it is going to perform. Therefore in this section we are going to gather the information about the circuit that we are building. A system may have from dozens to thousands of requirements. This project only has a few requirements. So lets start listing them
This is all the requirements that I can think of at this time. Now we need to identify the components that we need to accomplish the above task. the table below will list all the components that we need for our project. Later on we will take a closer look at each component Table 1
Note: The above is just a suggestions where you can purchase these components. There are other suppliers that will carry them as well. Digikey is another alternative place to purchase them. Note: The Microcontroller Basic stamp kit that I listed from Radio Shack is really made by a company called Parallax Inc. For some reason they don't sell that to customer directly and it is distributed through Radio Shack. Also you may get luck and find it on eBay for much cheaper. What's a Microcontroller? The What's Microcontroller package comes with Basic Stamp 2 Microcontroller (BS2), Programming board called Board of Education (BOE), book, Hardware packages, contain servo, LED, 1 7-sigments LED, resistors, capacitors, jumper cables and whole bounce of other stuff. Included in the package is a book that gives you a step by step introduction to BS2 . The Book also walks you through numbers of experiments that you can do with your new BS2. Also included in the package is the software, an interface cable for programming the BS2 module and connect the BOE to you computer during programming phase. Understanding Microcontroller Microcontroller can be thought of as very small computers which may be programmed to control systems such as cell phones, robots, automotive systems and of course our digital tachometers that we are about to build. The Microcontroller that we are using in this project is called Basic Stamp 2 or simply BS2 and is manufactured by Parallax inc. The BASIC stamp 2 is hybrid Microcontroller which is designed to be programmed in a version of the BASIC programming language called PBASIC. It is designed to be easier to work with than most assembly language based Microcontroller. Parallax makes several versions of the BASIC stamp Microcontroller. BS2 has 2K Bytes of EEPROM of memory with speed of 20 MHZ which gives you 4000 instructions/second and 26 Bytes of RAM. The BS2 stamp module needs to be connected to power for it to run. It also needs to be connected to PC so it can be programmed. The program is then tokenized or converted into symbolic format. The tokenized program is transmitter through the serial or USB cable and stored in EEPROM memory. The interpreter Chip reads the program from EEPROM and executes the instructions reading and controlling the I/O pins. The program will remain in the EEPROM indefinitely with or without power applied. The quick steps to prepare your BS2 for operations are
The picture below shows you the BOE and Stamp 2 Microcontroller. The BOE makes it easy to connect a power supply and serial cable to the BS2 module. Also make it easy to build circuits and connect them to your BS2 module. It is an excellent board for prototyping phase like we're doing here. Please note that BOE is not a must in order to use the BS2 module. Diagram 1
As mentioned before, first thing to do is to plug BS2 into the BOE. You will then need to install the Basic Stamp Editor from the Parallax CD. This CD should be in the kit you purchased. Once the Editor installed then the module needs to be connected to a PC so it can be programmed. The BOOK you get with your What's Microcontroller Kit explains everything in very detail as far as how to setup your hardware, software and test your setup. To fully understand how to setup and program your BS2 please read chapter 1 Activities 1- 7. Before we move to next section let just quickly go over the pins of BS2 and see what each does. From the Diagram below we can see that the BS2 module has 24 pins, 12 on each side Diagram 2 Table 2
MC14489 MC14489 chip is manufactured by Motorola Inc. It is called Multi-Character LED Display/LAMP Driver and also refers to as multiplexer. It is a bit tricky to work with this chip. I will briefly go over its basic features but if you like to fully understand it, you must read, read, and read the manual. But don't worry; I will cover everything that you need to know for building this circuit. This multiplexer is designed to directly interfaces to individual 7-segments display. A single MC14489 can drive up to 5-digit display. The reason we are using this chip in this project is that the BS2 doesn't have enough pins to satisfy all the connections to our 4X7-segments LED display or even if we go through hassle of making it to work, it won't be an efficient way of doing it. Again I'm not going into the details of how this multiplexer works. We're only covering what you need to know for this project. If you're novice, the best way to understand its entire feature is to read the manual not once but maybe a few times. Just remember this is not an easy one to deal with. Click Here to download the manual. The table below shows the pin assignment for MC14489 Diagram 3
As you can see, this multiplexer has 20 pins, 10 on each side. Out of the 20 pins, we will use 17 of them for this project (3 to BS2, and the rest to Vdd, Vss, and the LED display). When you looking at the top of the chip, you will see a little hallow dot on the top. The pin next to that is Pin 1 and the opposite side on the top is the last pin which is pin 20. The diagram below shows you the schematic diagram of MC14489 connection to BS2 and 4 X 7 segments LED Diagram 4 From the above diagram you can see the BS2 only controls Data In (pin 12), Clock (pin 11), and Enable (pin10) of MC14489. A,B,C,D,E,F,G,H (pins 7,6,5,4,2,1,20,19) are connected to the LED and bank1, 2, 3, 4 (pins 9,13,15,16) control the Digit 1 through 4. VDD (pin3) is connection to +5 volts. A resistor connected to RX (pin8) and ground. This resistor is to control the brightness of the display. Later on I will show you how to program the BS2 to interact with this multiplexer. 7-Segments LED. The LED display we're using for this project is purchased from Futurlec. But you can use any 4 digit 7-segment Display. The below images shows the picture and the pin layout of the 4 X 7-segments LED Display Diagram 5 From the above diagram, as you can see, there are 12 pins. 6 on each side. Bottom left is pin 1 and upper left is pin 12. D1 – D4 control which digit to be lit. Now lets go through an example. Suppose you want to display number 3 on the 4 th digit. In order to display 3, the segments A,B,G, C, and D have to be lid. So you need to apply power to pin 11, pin 7, pin5, pin4, and pin 2. Since we want to display 3 on the 4 th digit, we also need to apply power to pin 6 which controls the 4 th digit. MLX90217 The MLX90217 is a Hall Sensor manufactured by Melexis www. Melexis.com . It is designed to be used for speed sensing applications. It is activated with a bias magnet south facing the back (non-marked) side of the IC. In order to completely understand it functionality, you must read the manual For this project I show you the basic diagram that you need to know in order to build this Digital Tachometer Diagram below shows you the picture and schematic circuit that you need to build. Diagram 6
The above circuit is what measures the RPM of the engine. Whenever a magnet passes by the Hall sensor, it will trigger a plus on pin 3 as output (open collector). This output pulse will be feed into the pin 15 of the BS2 as an input. Within BS2 we will use a special function called “COUNT” to count the number of cycles (0-1-0 or 1-0-1) on pin 15 of BS2 during the period time frame and store that number in a variable. For example, let say we want to listen for number of pluses in one 1 sec on pin 15 of BS2 using the COUNT function. If in 1 sec we get 20 pluses, then we can multiply 20 X 60 which give use 1200 RPM. Our approach for building the circuit At this time we are introduced with all the hardware that we need in order to build the digital tachometer. Now lets put all these pieces together and build the complete circuit. I will start building this circuit in 2 sections. First we will build what measures the RPM and then the Display piece. We will write program for each pieces and test them individually. Once satisfied, then both circuits will be integrated into each other which will give us the complete circuit less start by building the less complex on, the one responsible for measuring the RPM. Here are the steps we will follow
Build the PRM Circuit Before continue with this section I'm assuming you have already purchased the BS2 Microcontroller and gone over chapter 1 of the book called “What's a Microcontroller” For this section we will need the following items
We need to build the circuit according to the above Digram 6. The following close up pictures show as we progress into building the circuit Digram 7 and Digram 8 Now that we completed the RPM circuit, we need to inject some blood into it... By that I mean we have to write a program to interact with our circuit. Again here I'm assuming that you have read through chapter 1 of the book that you got with the purchase of your Microcontroller. So far we have build the circuit that is responsible for measuring the RPM of a device. Since at this point, it is not attached to a LED display; we need to use the DEBUG command to display the result in your computer monitor PRM measuring Program
Table 3:
Now lets explain how this program works SpeedIn: Is a variable that is assigned to PIN 15 of BS2. Capture: Is a Constant that has a value of 1000 millisecond which is 1 sec Pluses: Is a variable (16 bites) that holds the number of pluses received by BS2 per second PRM: Is a variable (16 bites) that holds the value of pluses * 60 which shows the PRM of our device. The program starts with an infinite loop and uses a Command called “COUNT” COUNT is a BS2 function. It takes 3 parameters (pin, period, variable) It counts the number of cycle (0-1-0 or 1-0-1) on the specific pin during the period time frame and stores that number in a variable. COUNT SpeedIn, Capture, Pulses So you can see in our case, it will listen for number of pluses that the BS2 receive on PIN15 for period of 1 sec and store that value in a variable called Pulses. From the above debug screen, you can see for example the PRM = 300. Somehow we need to send this value to the LED display. One way of doing this is to manipulate the value 300 into 4 separated digits, such as 0 3 0 0. Assign 0 to digit 1 of display, assign 3 to digit 2 of display, assign 0 to digit 3 of display and assign 0 to the digit 4 of display. Later on I will show you how to do that. But for now, lets add the second circuit to our already built RPM circuit. We call the second circuit the Display circuit Building the DISPLAY CIRCUIT For this section we will need the following items
This circuit is responsible for interactions between BS2, to multiplexer, and LED display. For the circuit diagram, refer to the above diarams (4 and 5). We start by building the circuit first, and then write a PBASIC program to test the circuit Diagram 10 The MC14489 and 4 X 7 Segments display are attached to an external breadboard which is separated from the breadboard that is part of BOE. Since the above line is kind of hard to follow I'm going to map pin connections between MC14489, LED Display and BOE in the table below Table 4
This is how the final circuit will look like. All the components and wirings responsible for measuring the PRM and send the result to LED display are there. Later on we will remove the Hall sensor and solder it to a long wires and attached the wires to the unit Diagram 11 So what happen if we apply power to the unit? Well the code that measures the RPM is there, and work, but the BS2 doesn't know what to do the LED display and MC14489. Therefore nothing will happen. Now we need to write a program and download it to the BS2 in order to test our circuit. This program is only to make sure all wirings and connections are correct. Upon execution of this program we should see four 8s on the display then wait about 5 sec and display 2845. This will verify that our circuit is correct and completed. Later on we will write the final program to act as a digital tachometer. Table 5
Now make sure you have the power connected to the BOE, attached the serial or USB cable from BOE to the PC port. Open the Basic stamp editor and paste the above code into it. Click on the “Run” button. If you have wired all the connections correctly, the LED display should display “8888” for 5 sec and then display “2845”. Hey it worked I just did it Diagram 12 & 13 At this point we are done with designing the complete circuit. The only thing is left is to write our final program which it should measure the RPM and send the result to the LED display. Before doing that, let me quickly go over one more point. As you may recall, the program in table D has a variable called “rpm” this value holds the number of pluses that is received by pin15 of BS2 in one sec, multiplied by 60 which is the RPM of device you're measuring. As an example let say the RPM variable is holding a value of 1230. This indicates that your engine or whatever you measuring is running at 1230 per minute. So how do we send this value to the LED display? From table Q1 we noticed that we have 5 variables (digit1, digit2, digit3, digit4, and digit5) which will be used in Update_Segs subroutine to update the LED display. Now the problems we're having here is we need to find a way to distribute the value that is hold in rpm which is 1230 to digit1, digit2, digit3, and digit4. We can always set digit5 to 0 since we only dealing with 4 digits. One way of doing this is the following 1. First we compare the value of RPM to see if it is greater or equal 1000. Since 1230 is greater than 1000, then we will divide that number by 1000 and assign it to digit1. digit1 ß rpm / 1000 that is 1230 /1000 and since we are dealing with integer then the value of 1 is assigned to digit1. Then we need to update the value of rpm with a new value rpm <-- rpm – (digit1 x 1000) that is 1230 – (1 x 1000) = 230 so the new value of rpm is now equal to 230. 2. Now we compare the value of rpm with 100 and follow the same algorithm and assign the result to digit2 3. Next we compare the value of rpm with 10 and 1 and assign the result to digit3 and digit4. With that said let write the final program Table 6
Now as before make sure the serial or the USB cable is attached to the BOE. Copy and paste the above program into your PBASIC editor, and click “Run” button to program the Microcontroller. If everything is done correctly, you should see the LED display changed to all zeros. “0000”. Used the magnet and move it back and forth close to the Hall sensor. You should be able to see the some numbers on the LED display. Now you can take the Hall Sensor out of the BOE breadboard and solder it to a 6” or longer wires and connect the other end of wires to the breadboard. Here is the final picture of fully functional Digital Tachometer prototype Diagram 14 Here you can attach the magnet to the flywheel. Since the flywheel on this engine is made of steel, the magnet is strong enough to hold. But if you are attaching it to other than steel, maybe a drop of super glue or a piece of tape will do the job. Diagram 15 Diagram 16 If you finally decided that you want build this, I'm sure you will enjoy it as much as I did. If you have any questions, just drop me an email and I will get back to your questions or comments. Good luck
|