Prototyping a Digital Tachometer Using Paralax Microcontroller

By: Kamran Nili

email: 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:

  1. Terminology
  2. Defined requirements
  3. Design the unit
  4. build the hardware in series of steps
  5. Write the Microcontroller program for each pieces
  6. Test each pieces
  7. Integrate all pieces together and make the final circuit.
  8. Test the final circuit on your engine or whatever device you like.

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

  • Req1: Should be able to measure RPM of up to 9999.
  • Req2: Should be able to display the result on 4 X 7- segments LED
  • Req3: Upon power up all digits should be set to 0000.
  • Req4: The LEDs should be updated once every 1 sec when pluses is detected.
  • Req5: Should be designed in a way that no wiring is required to the target device for measuring the RPM.

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

Hardware Name Descriptions No . Unit Suppliers Price
4 X 7 Segments LED Red Four Digit 7-Segment CC Display
1
Futurlec part number: 7SEG4RCC $3.00
MC14489 MC14489 5V LED Display Lamp Driver by Motorola Inc.
1
Futurlec part number: MC14489 $3.20
What's a Microcontroller, Basic Stamp Kit Microcontroller kit manufactured by Paralax Inc.
1
Radio Shack part number: 276-625 $79.99
Melexis 90217 Hall-Effect Sensor Hall-Effect sensor for speed measurement and feedback
1
Paralax Inc. part number: 605-00005 $4.25
0.01 uF 50 V Poly capacitor 0.01 uF 50V poly capacitor
1
Paralax Inc. Part number: 200-01031 $.015
5.6 K Ohm resistor 5.6 K ohm resistor
1
Radio Shack $.99
1/8" dia magnet 1/8" magnet for Hall Sensor
1
Radio Shack $1.25
BREADBOARD, 400 CONTACTS This modular IC breadboard socket includes 300 plug-in points to construct and test small circuits.
1
All Electronics Part number: PB-400 $3.00

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

  1. plug the BS2 module into the BOE
  2. Install the Stamp Editor software that comes with the package you purchased
  3. Connect the BOE to your PC with either the serial or USB cable that is part of the package
  4. Write your program in stamp editor and transfer it BS2 module

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

Basic Stamp 2 Microcontroller module (left) and Board of Education Carrier Board (right)

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

Pin Name Description
1 SOUT Transmits serial data during programming and using the DEBUG instructions
2 SIN Receives serial data during programming
3 ATN Uses the serial DTR line to gain the stamps attention for programming.
4 VSS Communications Ground (0V)

5 – 20

P0-P15 General-purpose I/O pins: each can source and sink 30 mA. However, the total of all pins should not exceed 75 mA (source or sink) if using the internal 5-volt regulator. The total per 8-pin groups (P0 – P7 or P8 – 15) should not exceed 100 mA (source or sink) if using an external 5-volt regulator.
21 VDD 5-volt DC input/output: if an unregulated voltage is applied to the VIN pin, then this pin will output 5 volts. If no voltage is applied to the VIN pin, then a regulated voltage between 4.5V and 5.5V should be applied to this pin.
22 RES Reset input/output: goes low when power supply is less than approximately 4.2 volts, causing the BASIC Stamp to reset. Can be driven low to force a reset. This pin is internally pulled high and may be left disconnected if not needed. Do not drive high.
23 VSS System ground: (same as pin 4) connects to power supply's ground (GND) terminal.
24 VIN Unregulated power in: accepts 5.5 - 12 VDC (7.5 recommended), which is then internally regulated to 5 volts. May be left unconnected if 5 volts is applied to the VDD (+5V) pin.

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

The diagram on the right shows you the layout of Motorola MC14489 multi-character LED display/lamp driver. The MC14489 takes care of the multiplexing and display the RPM on our 4 X 7-segements LED. As far as the connection to BS2, we only need to deal with 3 of the pins (Clock, Data In, Enable)

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

  1. Build the circuit responsible for measuring the RPM
  2. Write the program to interact with the above circuit
  3. Test the Circuit and the program to make sure it functions correctly
  4. Build the circuit responsible for displaying the digits on display LED
  5. Write the program to interact with the Display circuit
  6. Test the Circuit and the program to make sure it functions correctly
  7. Integrate the PRM and Display circuit to finalized the prototype
  8. Test the prototype on your engine

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

  1. BOE with BS2 attached to it (1)
  2. MLX90217 Hall Sensor (1)
  3. 0.01 uF capacitor (1)
  4. 5.6 K ohms resistor (1)
  5. Jumper wires

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

  1. Attach the BOE to your PC or laptop using the provided cable (see Activity #4, chapter 1).
  2. Start the BASIC Stamp Editor
  3. Add the below code into the BASIC Stamp editor

Table 3:

' {$STAMP BS2}
' {$PBASIC 2.5}

' -----[ I/O Definitions ]-------------------------------------------------


SpeedIn         PIN     15                     'Receive Input from Hall Sensor


' -----[ Constants ]-------------------------------------------------------



Capture         CON     1000                   '  Num of msec to listen for input


' -----[ Variables ]-------------------------------------------------------


rpm              VAR     Word                  '  value to hold the RPM of the engine
pulses           VAR     Word                  '  input pulses from Engine


' -----[ Initialization ]--------------------------------------------------


pulses = 0
DO
      COUNT SpeedIn, Capture, Pulses
      rpm = (Pulses * 60)
      DEBUG CR, "Pulses = ", DEC pulses
      DEBUG CR, "RPM = ", DEC rpm, CR,CR


LOOP

END

		   

 

4. Now click on the run button in the BASIC editor. You will see the debug screen appears. At this time you test the program moving the magnet close to the Hall sensor. In the debug screen will see how many times you moved the magnet back and fort per sec, that number than is multiplied by 60 and gives you pluses per minute.

Digram 9

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

  1. BOE with BS2 attached to it (1)
  2. MC14489 (1)
  3. External breadboard (1)
  4. 10 K ohms resistor (1)
  5. Jumper wires
  6. 4X7-Segments LED

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

 
MC14489 LED Display BOE
PIN1 PIN10  
PIN2 PIN1  
PIN3   Vdd
PIN4 PIN2  
PIN5 PIN4  
PIN6 PIN7  
PIN7 PIN11  
PIN8   Vin (use 10 k Ohms resistor)
PIN9 PIN12  
PIN10   PIN2
PIN11   PIN0
PIN12   PIN1
PIN13 PIN9  
PIN14   Vss
PIN15 PIN8  
PIN16 PIN6  
PIN17 (not used)    
PIN18(not used)    
PIN19 PIN3  
PIN20 PIN5  

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

 
' {$STAMP BS2}
' {$PBASIC 2.5}


' -----[ I/O Definitions ]-------------------------------------------------


Clock           PIN     0                         '  shift clock (MC14489 pin 11)
SerData         PIN     1                         '  serial data (MC14489 pin 12)
Enable          PIN     2                         '  enable (MC14489 pin 10)


' -----[ Constants ]-------------------------------------------------------


Blank           CON     $0                        '  Special Decode characters for MC14489


' -----[ Variables ]-------------------------------------------------------


config           VAR     Byte                    ' decode configuration for MC14489
dpCtrl           VAR     Nib                     ' decimal point control for MC14489
digit5           VAR     Nib                     ' segs - digit 5 (this one is not used)
digit4           VAR     Nib
digit3           VAR     Nib
digit2           VAR     Nib
digit1           VAR     Nib                     ' segs - digit 1


' -----[ Initialization ]--------------------------------------------------


Reset:
  HIGH Enable                                    '  disable MC14489
  digit1  = 0
  digit2  = 0
  digit3  = 0
  digit4  = 0
  digit5  = 0                                    '  Always 0 (not used)

  config = Blank
  GOSUB Update_Cfg
  config = %1                                    '  To setup for digits only (see
                                                 '  MC14489 documentation
  dpCtrl = %1000                                 '  Set the display to bright
ResetEnd:

   digit1 = 8
   digit2 = 8
   digit3 = 8
   digit4 = 8
   digit5 = 8

   GOSUB Update_Segs                             '  show message
   GOSUB Update_Cfg                              '  display on

   PAUSE 5000

   digit1 = 2
   digit2 = 8
   digit3 = 4
   digit4 = 5
   digit5 = 8
   GOSUB Update_Segs                            ' show message
   GOSUB Update_Cfg                             ' display on
 END


' Update MC14489 configuration register
Update_Cfg:
  LOW Enable                                    ' enable MC14489
  SHIFTOUT SerData, Clock, MSBFIRST, [config]   ' send config register
  HIGH Enable                                   ' disable MC14489
RETURN


' Update MC14489 segments registers

Update_Segs:
  LOW Enable
  SHIFTOUT SerData, Clock, MSBFIRST, [dpCtrl\4,
             digit5\4, digit4\4, digit3\4, digit2\4, digit1\4]
  HIGH Enable
RETURN

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

 
' ------------------------------------------------------------------------------------------------
'
'   File...... ModelEngineRPM.BS2
'   Purpose... To measure the RPM of model engine using stamp2
'              MicroController
'   Author.... Kamran Nili
'   E-mail.... knili@yahoo.com
'   Started... Nov 06, 2005
'   Updated... Nov 06, 2005
'
' -----------------------------------------------------------------------------------------------

' {$STAMP BS2}
' {$PBASIC 2.5}

' -----[ I/O Definitions ]-------------------------------------------------

Clock           PIN     0                       ' shift clock (MC14489 pin 11)
SerData         PIN     1                       ' serial data (MC14489 pin 12)
Enable          PIN     2                       ' enable (MC14489 pin 10)
SpeedIn         PIN     15                      ' Receive Input from Hall Sensor
pulses          VAR     Word                    ' input pulses from Engine

' -----[ Constants ]-------------------------------------------------------

Blank           CON     $0                      ' Special Decode characters for MC14489

Capture         CON     1000                    ' Num of msec to listen for inpput

' -----[ Variables ]-------------------------------------------------------
config           VAR     Byte                    ' decode configuration for MC14489
dpCtrl           VAR     Nib                     ' decimal point control for MC14489
digit5           VAR     Nib                     ' segs - digit 5 (this one is not used)
digit4           VAR     Nib
digit3           VAR     Nib
digit2           VAR     Nib
digit1           VAR     Nib                     ' segs - digit 1
rpm              VAR     Word                    ' value to hold the RPM of the engine
value            VAR     Word
LookDownResult   VAR     Word                    ' Index value
counter          VAR     Word

' -----[ Initialization ]--------------------------------------------------

Reset:
  HIGH Enable                                    ' disable MC14489
  rpm     = 0
  digit1  = 0
  digit2  = 0
  digit3  = 0
  digit4  = 0
  digit5  = 0                                    ' Always 0 (not used)

  config = Blank
  GOSUB Update_Cfg
  config = %1                                    ' To setup for digits only (see
                                                 ' MC14489 documentation
  dpCtrl = %1000                                 ' Set the display to bright
ResetEnd:
pulses = 0
counter = 0
DO

      COUNT SpeedIn, Capture, Pulses
      rpm = (Pulses * 60)
      digit1  = 0
      digit2  = 0
      digit3  = 0
      digit4  = 0
      digit5  = 0

    DO
      IF rpm = 0 THEN EXIT
      LOOKDOWN rpm, >=[1000, 100, 10, 1], LookDownResult
      IF (LookDownResult = 0) THEN
         value =  rpm /1000
         rpm = rpm - (value * 1000)
         Digit1 = value
      ELSEIF (LookDownResult = 1) THEN
         value =  rpm /100
         rpm = rpm - (value * 100)
         Digit2 = value
      ELSEIF (LookDownResult = 2) THEN
         value =  rpm /10
         rpm = rpm - (value * 10)
         Digit3 = value
      ELSEIF (LookDownResult = 3) THEN
         value =  rpm
         rpm = rpm - value
         Digit4 = value
     ENDIF
     IF  (LookDownResult = 3) THEN EXIT
   LOOP

   GOSUB Update_Segs                           ' show message
   GOSUB Update_Cfg                            ' display on

LOOP

' Update MC14489 configuration register
Update_Cfg:
  LOW Enable                                    ' enable MC14489
  SHIFTOUT SerData, Clock, MSBFIRST, [config]   ' send config register
  HIGH Enable                                   ' disable MC14489
RETURN


' Update MC14489 segments registers

Update_Segs:
  LOW Enable
  SHIFTOUT SerData, Clock, MSBFIRST, [dpCtrl\4,
             digit5\4, digit4\4, digit3\4, digit2\4, digit1\4]
  HIGH Enable
RETURN

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