Knowledge Base

The tachometer example tacho1.spt illustrates how the OBCA feature can be used to measure engine RPM on a diesel engine. In the example the RPM figure is displayed in 3 different ways. In a real application it might be used to maintain constant speed (with feedback to a throttle control) or to manage a startup sequence for a generator set.

Program examples are no longer installed with SPLat/PC. They are now located on our website in the File Resources area. The program file is called tacho1.spt.

The input signal for the tachometer is a proximity detector mounted close to the flywheel so the passing gear teeth produce pulses out of the detector. This is often done using a Variable Reluctance (VR) sensor, which basically consists of a coil wound on a rod magnet. The moving steel gear teeth disturb the magnetic flux, resulting in a voltage being induced in the coil. A VR sensor needs a special amplifier interface … some custom SPLat boards contain such an interface. With a regular logic input you could use a high speed industrial proximity detector. Another method of picking up engine speed is to measure the frequency of the alternator output.

The program contains a constant for the number of gear teeth. This allows the frequency measured to be converted to RPM. If there are n teeth, there will be n pulses per revolution. Hence f, the frequency measured (as pulses per second, or Hz) will be n times the number of revolutions per second. RPM is then given as

RPM = f x 60/n

The program consists of some initialization code, a “main loop” and 4 subroutines.

The initialization code simply sets up the OBCA to mode 2, which is frequency counting with a 1S timebase.

The main loop contains nothing but a single conditional subroutine call to the tachometer subroutine Tacho. The call is conditional on there being a new reading available, using the OBCA_GoSubIfRdg instruction. By structuring the program this way with a “main loop”, it is easy to add in other functions that also get called from the main loop. Providing no such function “hogs the processor” by doing a Wait or a Pause or a tight loop waiting for something to happen, the program can readily be expanded to handle a complex collection of functions.

In the Tacho subroutine we read the OBCA count and compute RPM as a simple floating point scaling calculation. The result is saved in floating point variable RPM. We then call the three display/output routines TachoToLCD, TachoToBargraph and TachoAnalogOut.

TachoToLCD takes the RPM value and displays it on the OnBoard LCD (OBLCD). You will need to Comment out the OBLCD_ instructions if you have a board that does not support the OBLCD, such as an SL99.

TachoToBargraph computes how many of the 8 LEDs (a.k.a. outputs) need to be on, then uses a Branch instruction and 8 small code segments to set the output pattern using a OutputM instructions. The LED patterns are specified in binary, e.g. %00111111. There is a test at the start of the subroutine to catch the case where the calculated number of segments exceeds 8. This is the off-scale case, and if it happens all outputs are set to blink. This test also protects us against a Branch argument exceeding the number of Targets, which would result in a runtime error.

TachoAnalogOut simply calculates an integer between 0 and 255, corresponding to 0 to 10,000 RPM, and sends it to an analog output.