DIY Test Equipment

Monthly project competitions, chances to earn prizes, you decide project themes, your ideas, your projects, turn ideas into projects.

Back to The Project14 homepage

Project14 Home
Monthly Themes
Monthly Theme Poll

 

Introduction

This project is to build a handheld test tool, to measure how fast things are turning. It could have uses in vehicle diagnostics, or for checking how fast a drill is spinning. It could also be used in math/physics experiments to see how fast wheels or other parts are revolving. Basically if any machine is spinning you can measure its rotational speed in revolutions per minute (RPM) or revolutions per second (Hz).

The short (60 second) video here shows it in action:

 

It is low-cost (<$25) and easy-to-build, so it could be ideal as a beginner 'learning electronics/learning to solder' project. All parts and details are published in this blog post.

tach-top-view-switched-on.jpg

 

How does it work?

The principle is really simple; an infrared LED shines light on the target object. Reflections get sensed by a single photodiode 'eye'. Provided there is a reflective portion of the target object and a non-reflective portion (as an example, a piece of white tape could be stuck on a dark colored object, or a piece of black tape on a light colored object) then the reflected light occurs in pulses directly related to the number of revolutions per minute. The pulses are counted by a microcontroller every second and shown on a LCD display.

tach-opto-view.jpg

 

Working with the Microcontroller

This project uses a Texas Instruments MSP430 series microcontrollerMSP430 series microcontroller. A microcontroller in a nutshell is a computer-on-a-chip. it contains a microprocessor, memory, storage (often in the form of Flash memory) and lots of input/output (I/O) pins. Software is written and compiled/built into an executable file on a PC, and then programmed into the Flash memory.

In order to program the microcontroller integrated circuit (IC), a cheap development board development board is used. It has a 20-pin DIP socket so it is perfect for plugging in a microcontroller, programming it, removing it and then fitting it into your own projects.

msp-exp430g2-dev-board.jpg

 

To get started, plug in the development board into the PC using the supplied USB cable. Next, google ‘CCS Cloud’ and register at the TI website and the web browser will show a development environment. All coding and compiling can be done in the web browser, and there is no need to download and install any development software.

Go to File->New CCS Project and give the project any name (e.g. tachometer) and for the Device field select MSP430Gxxx Family and MSP430G2553.

ccs-step1.png

 

You’ll see that the CCS Cloud environment has created a file for you called main.c and it has a basic main function already inside in the editor pane. It will look like this:

ccs-step2.png

 

As a test, click File->Save and then click on the Hammer icon which is used to build the code into an executable file. The text in the Output pane will indicate Finished building: tachometer.This proves that the compiler is functioning. In order to download the code into the microcontroller plugged on the development board, all you need to do is click on the Run icon. The first time you do this it may download and install a little helper program to perform the transfer, and subsequently you don’t need to install anything to the PC.

ccs-step3.png

 

The program doesn’t do anything, so you may wish to experiment and blink the LED on the development board. To do this, type the following code into the Editor pane:

#include <msp430.h>

#define LED1_ON P1OUT |= BIT0
#define LED1_OFF P1OUT &= ~BIT0

/*
* main.c
*/
int main(void) {
    WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
  P1DIR |= BIT0;

  while(1)
  {
     LED1_ON;
     _delay_cycles(60000);
     LED1_OFF;
     _delay_cycles(30000);
  }

  return 0;
}

 

It should look like this:

ccs-step4.png

 

Select File->Save then click the Hammer icon, confirm the Output pane successfully says Finished building: tachometer.hex, and then click the Run icon.

 

After a short pause the code gets transferred into the development board microcontroller, and the red LED should flash rapidly as the code was written to do. The executable file is written into non-volatile Flash memory, so if you unplug the USB cable and then re-insert it, the LED will start flashing again.

 

Now that hopefully you are comfortable with writing code and building it and installing it onto the microcontroller, the tachometer code can be installed. Go to github and copy the code there and paste it into the CCS Cloud browser editor pane so that it replaces the original code. Same as before, click on File->Save and then the Hammer icon, and again confirm that the output says Finished Building: tachometer.hex. Note that if there are any errors, there will be red error messages in the Output pane and they will need to be corrected. There should be no issue with the current code however.

 

Click on Run and the code will be installed into the microcontroller. Unplug the USB cable and then using a flat blade screwdriver carefully lever out the programmed microcontroller from the development board. It will be installed in the Cyclops-1000 circuit board!

 

Building the Circuit

There are different ways to build the circuit; for example using isolated pad proto board, or using a printed circuit board (PCB). To build it on a PCB, the computer aided design (CAD) files are sent to a PCB manufacturer; the typical cost is $20 for 10 boards. One PCB manufacturer is iTead, but others offer similar prices and results too. To use iTead, search for their PCB prototyping service, and purchase their 2-layer 10x10cm board option. Then go into your iTead account order and click on 'View Order' and there will be a button to upload the CAD files. The PCB CAD zip file for this project can be downloaded from github and uploaded to iTead as a zip file. That’s it! The PCBs should arrive within a week or two.

tacho-pcb-top.png

 

I initially built mine on isolated pad proto board. To start off, the power supply circuit is built. It can be verified by plugging in a battery and using a multimeter to confirm 5V and 3.3V outputs are functioning.

tacho-supply-schematic.png

 

Next, the optical portion of the circuit is constructed. It consists of an infrared LED, and a photodiode circuit that amplifies the received signal and then provides a high/low logic output. The output is inverted and converted to a 3.3V logic signal using the Q1 transistor.

 

To test this circuit with a multimeter, placing white card to cause a reflection should result in the signal output from Q1 to change from high (3.3V) to low (0V). Careful adjustment of the angle of the LED should allow for a reliable distance of about 10cm from the target using a white card target.

tacho-opto-schematic.png

 

The output from Q1 is connected to the microcontroller. The microcontroller circuit consists of a 20-pin DIP socket for the MSP430 series microcontroller, a reset circuit (R6 and C6), a 32.768kHz crystal, a supply decoupling capacitor (C7) and two pull-up resistors (R4 and R5) which together establish an I2C serial bus.

tacho-uc-schematic.png

 

The microcontroller that was programmed earlier can be plugged into the 20-pin socket once the entire circuit has been soldered.

tach-uc-pwr-view.jpg

 

The final part of the circuit is to attach the LCD display.

tacho-lcd-schematic.png

 

And that’s it! The circuit is very simple. Plug the microcontroller in, connect a 9V battery and everything should work. The LCD display will prompt you to point it at a rotating object and the display will automatically indicate the RPM value and the number of rotations per second too (in Hz).

 

Any questions, please feel free to discuss in the comments section below. Also, if you do improve the hardware or software it would be great to hear about it.

 

PCB Version

The PCB has a couple of optional features, in particular there is space for a push-button. It could be useful to implement new functions for example min/max display of speed where the speed is varying over time, or a ‘high-res’ mode where very high granularity is needed for the RPM measurement, or a 'counter' mode which just counts number of rotations forever until it is reset.

 

The PCB version is quicker to build and there is less chance of error during assembly.

 

Final Test and Assembly

The project functions to speeds beyond practical limits for rotating objects. To prove this, I pulsed an LED at known frequencies and pointed it at the sensor. It worked to beyond 15,000 pulses per second which is close to 1 million RPM. The entire project fits in a handheld casehandheld case; a window will need to be cut for the display, the optical parts and the power switch. Alternatively a 3D printer could be used to create something suitable.

tach-enclosure.jpg

 

The window was cut to be larger than the text display area, so that the text would be visible from an angle too.

rpm-bits.jpg

The window was fitted with a neutral density filter. This was glued on the inside of the case. For the push-button, I deliberately drilled a bigger hole so that a plastic cap that I had lying around (it wasn't designed for the specific push-button that I used) could fit. Other cylinder shaped plastic pieces could be used.

rpm-glue.jpg

It turned out that I didn't need to glue the cap to the push-button; it just sits on top loosely, and is fitted with a lip (I used a grommet) around it so that it won't drop out of the case. Since there is a lot of light bleed from the sides of the LCD, I cut a black piece of card to act as a surround and lightly glued it down (I used 'glue dots' so that it can be easily removed if necessary).

rpm-card.jpg

Here are some final photos of the assembled device:

rpm-case-side.jpg

rpm-case-top.jpg

 

How does the Software work?

The software is straightforward. It is examined in detail here.

tach-software-implementation.png

 

To examine it, look at the function called main(). The software sets up the crystal oscillator, and then sets a hardware timer inside the MSP430 chip to repeat every second. When the timer reaches one second the hardware will automatically call an interrupt routine. The main function also sets up another different interrupt to occur each time a falling edge signal occurs on the microcontroller. The edge interrupt pin is connected to the optical circuit.

 

The rest of the main function just loops forever, waiting for a fresh edge sum to be available, and printing it to the LCD.

 

Whenever the edge interrupt occurs, a counter is incremented. Whenever the 1-second event occurs the counter value is published in a global variable called edge_sum and then the counter value is reset.

 

Therefore the global variable edge_sum contains the total number of transitions that occurred every second. This value is multiplied by 60 to get an RPM value.

 

Summary

This project has shown how to build an RPM measurement device (tachometer) at low cost, and how to program the microcontroller and make modifications to the code. With the PCB this is a really easy beginners project and provides a tool for measuring the rotational speed of all sorts of machines.

 

Parts List

Note: A quantity of two parts is needed for some line items! Refer to the first column to see how many references there are to that part, to determine the quantity.

 

Ref
ValueDescription
C1, C7100n100n100nF ceramic capacitor
C2, C31u1u1uF ceramic capacitor
C4, C510u10u10uF electrolytic capacitor
C61n1n1nF ceramic capacitor
D1SD5620-001SD5620-001Honeywell SD5620 optoschmitt detector
D2IR LEDIR LED850nm infrared LED Vishay  VSLY5850VSLY5850
J2DIL headerDIL headeroptional - SMD 10WAY DIL header 1.27mm pitch
LCD12x16 Text LCD2x16 Text LCDMCCOG21605B6W-BNMLWIMCCOG21605B6W-BNMLWILCD
Q1BC547BC547BC547 transistor NPN
R11k1k1k resistor
R222k22k22k resistor
R347R47R47 ohm resistor
R4, R52.2k2.2k2.2k resistor
R647k47k47k resistor
R7180R180R180 ohm resistor
R8330R330Roptional - 330 ohm resistor
SW1Slide SwitchSlide Switchslide switch  OS102011MA1QN1OS102011MA1QN1
SW2Push SwitchPush Switchtactile switch 6.5mm x 4.5mm pin spacing Omron  B3F-1070B3F-1070
U1R-78E5.0-0.5R-78E5.0-0.5Recom R-78E series 5V 500mA DC-DC converter
U2MCP1702-3302EMCP1702-3302E3.3V LDO voltage regulator
U3MSP430G2553MSP430G2553MSP430 series microcontroller  MSP430G2553IN20MSP430G2553IN20
X132.768kHz32.768kHz32.768kHz crystal wire ended, 12.5 pF
MSP-EXP430G2MSP-EXP430G2MSP430 development board
DIP socketDIP socketDIP socket 20-way
EnclosureEnclosure117x79x24mm case with battery holder
PP3 battery clipPP3 battery clip9V battery clip
Proto boardProto boardoptional - 160x100mm perf pad board