Building a detonation counter today

On a two-stroke racer, detonation that goes on for long enough holes the piston. So you want the carburettor and ignition timing set just short of where detonation starts, and a detonation counter is the tool that puts a number on it. In the 1990s HRC sold one as a genuine part; it is now discontinued. This page sets out how you could build one with today's parts, down to part numbers and cost.

This is a build plan. It has not been built and tested yet. The figures are estimates from published sources and calculation.

1. What it counts

In normal combustion a flame spreads out from the spark plug. Detonation is when the last of the mixture at the edge of the chamber, squeezed and heated, ignites by itself all at once before the flame reaches it. That sets off a strong pressure wave that bounces back and forth across the combustion chamber.

The wave rings at a pitch (frequency) set by the size of the chamber. A vibration sensor on the cylinder head picks it up; the counter listens only in a short window just after ignition and only at that pitch, and counts one if it is louder than usual. That is the whole idea.

The counter itself adds no power. What it does is let you safely go as far with mixture and timing as you used to be afraid to.

2. The pitch of the knock

The lowest way the wave rings around the chamber has a frequency given by this formula (Draper, 1934):

frequency = 1.841 × speed of sound ÷ (π × bore)

The speed of sound depends on the temperature of the burnt gas (roughly 800–1,000 m/s), so the answer is a range, not one value. The smaller the bore, the higher the pitch.

Knock pitch (first mode)
Usually the strongest. Centre the filter here
Second mode
Is it inside the sensor's range (3–25 kHz)?
Listening window (60° after TDC)

Range for a speed of sound of 800–1,000 m/s. Second mode uses the constant 3.054. Check the real value from recordings with the sensor fitted.

For the RS125 (NF4) with a 54 mm bore, that is about 8.7–10.9 kHz. At 12,500 rpm the crank takes only about 13 microseconds to turn 1°. You have less than a millisecond per combustion to listen, so the microcontroller has to read fast.

3. How HRC's kit worked

HRC sold detonation counters for the RS125R (06501-NX4-730) and the RS250R (06501-NX5-730). A 1999 paper by HRC engineers describes it as a tool to measure detonation as a number in order to set the carburettor and ignition timing, and says that simplifying the system made it possible to sell. From published material:

  • Sensor: a washer-shaped vibration sensor clamped under a cylinder head stud nut. RS125: M8 for the 5-stud head, M6 for the 6-stud head. The nut is tightened to its normal torque.
  • Sensitivity: a 15-position switch, 0 to F. 0 is the most sensitive.
  • Power and output: 12 V. It sends counts to the data logger as pulses. With the logger you can see where on the track, in which gear and at what throttle opening it happened.
  • Wiring: keep the amplifier at least 80 mm from the ignition coil, and route the sensor lead away from the plug lead and coil.
  • Target: in the main full-throttle sections, 1–2 counts per km. Make your own baseline for each circuit. Detonation happens mostly around peak-power rpm.
  • Today: a UK RS125 specialist lists both the counter and the sensor lead as "discontinued, sold out". The same shop sells its own replacement sensor for £230 (ex VAT).

4. Building one today: overview

What used to take a dedicated analogue circuit can now be done in software on a microcontroller that costs a few dollars.

Knock sensorKS4-P (on the head) Amplifier, protectionMCP6022 Ignition signalwire round plug lead Squares the pulse74HC14 Raspberry Pi Pico 2reads 200,000 times/slistens after ignition Light Count LogSD, GPS

5. Parts list (part numbers, cost)

JobPartPart no. / typeRough priceNote
SensorBosch Motorsport knock sensor KS4-P0 261 231 173 (RB-Kp.1 connector) / 0 261 231 188 (Jetronic connector)$39.99–67.99US shop: $39.99 bare, $67.99 with connector and mounting hardware. European shop: €64.90. Shipping extra
MicrocontrollerRaspberry Pi Pico 2RP2350about $6–1212-bit ADC; reads the vibration 200,000 times a second
Op-ampMicrochip MCP6022-I/PDIP-8, dualabout $1.50Runs on 3.3 V, rail-to-rail input and output
Protection diodeBAT54S2about $0.30Keeps the sensor and ignition inputs within the supply voltage
Schmitt trigger74HC141about $0.50Turns the ignition pickup into a clean square pulse
DisplayTM1637 4-digit LED module0.56 inchabout $2–4Read the count in the pits
Warning lightHigh-brightness LED (red) + resistor1 setabout $0.50On track, watch whether it flashes rather than the count
Logging (optional)microSD card module (SPI)1about $2Logs rpm and counts
Logging (optional)GPS module (10 Hz, u-blox M10 class)1about $20–35Puts where it happened on a track map
PowerPower bank (5 V)smallabout $15Works on racers with no battery. On a 12 V machine, a Murata OKI-78SR-5/1.5-W36-C (about $4) gives 5 V
WiringShielded cable (2-core), box, connectorssetabout $15–20Always shielded cable for the sensor

Rough total: about $90–130 for the essential parts, about $110–170 with logging. The sensor is the most expensive part. Allow another $5–10 for resistors, capacitors, board and other small parts.

Prices are rough figures from online shops in November 2026, before shipping. Check part numbers against the maker's documents before you buy.

6. Choosing and mounting the sensor

Recommended: Bosch Motorsport KS4-P

A motorsport version of the knock sensor used on car engines. It has a hole through the middle and is fixed with an M8 bolt. Bosch publishes its characteristics, so you can calculate with them.

  • Frequency range: 3–25 kHz (covers the 54 mm bore's knock pitch and the higher pitch of a 50cc)
  • Sensitivity: 26 ± 8 mV/g at 5 kHz; within ±10% from 5 to 15 kHz; 20–50% higher from 15 to 20 kHz
  • Sensor resonance: 30 kHz (well above the knock pitch)
  • Operating temperature: −40 to 150°C
  • Mounting: M8 bolt, 20 ± 5 N·m. The contact face must be flat and clean
  • Weight 48 g, height 18 mm
  • Part numbers: 0 261 231 173 (RB-Kp.1 connector), 0 261 231 188 (Jetronic connector). One US shop also sells a kit with the connector and mounting studs (M8x1.25 and M12x1.25)

Where to mount it

  • On a head stud, like HRC's: a 5-stud head uses M8, so clamping the sensor under a nut is the closest match. But the KS4-P is 18 mm tall, so check there is enough thread on the stud, and decide how to deal with the difference between the head nut torque and the sensor's 20 N·m. Never mount it in a way that changes how the head is clamped.
  • Make a boss on the head: tap an M8 hole in a flat area of the head, or make a bracket clamped by a head bolt. A thin bracket rings by itself and causes false counts, so keep it thick and short.
  • Either way, close to the combustion chamber and the plug picks up the knock best.

Will a cheaper sensor do?

Replacement car sensors (Bosch numbers starting 0 261 231 …, and others) cost about $15–35. Inside they are much the same piezo element and may well work, but most have no published frequency response, so we suggest the KS4-P for your first one. Spark-plug-washer pressure sensors are research instruments and cost hundreds of dollars or more.

7. Circuit

Sensor input

  • Tie the sensor output to 1.65 V (half the supply) through 1 MΩ. Together with the sensor's own capacitance (about 1,150 pF) this rolls off slow vibration below about 140 Hz.
  • Add 10 kΩ and a BAT54S at the input so static or ignition noise cannot push the microcontroller input beyond its supply.
  • Amplify ×2 to ×11 with the MCP6022 (set with a trimmer). Then 1 kΩ and 4.7 nF cut everything above about 34 kHz (anti-aliasing).
  • Into the Pico 2's ADC input (GP26).

Ignition signal

  • Wind 5–10 turns of thin insulated wire round the plug lead (over its insulation; never bare).
  • Limit the voltage with 100 kΩ and a BAT54S, square it with a 74HC14 and feed it to an interrupt input (GP15).
  • So it triggers once per spark, the software ignores further pulses for 2 ms.

Power and noise

  • Feed 5 V from a power bank into the Pico 2's VSYS. On a 12 V machine, drop it to 5 V with an OKI-78SR-5/1.5-W36-C.
  • As HRC advises, keep the box at least 80 mm from the ignition coil. Use shielded cable for the sensor and ground the shield at the box end only.

8. Software: when to listen, and for what

The idea: listen only just after ignition, only at the knock pitch, and compare with what is normal.

  1. Record all the time: the ADC reads the vibration 200,000 times a second into a ring buffer (DMA). The CPU does not have to touch it.
  2. Note the time of each spark: the ignition interrupt records the time and the interval since the last spark (= rpm). That tells you how many microseconds 1° takes.
  3. Set the windows: with the ignition timing (degrees before TDC) set in advance, listen from 5° to 65° after TDC (the knock window); the quiet time before the spark is the background window.
  4. Pick out the pitch: run the samples through a band-pass filter centred on the frequency from the calculator.
  5. Compare: compare the energy in the window (sum of squares) with the median of the last 32 combustions. If it is more than the set multiple, count one.
  6. Report: flash the warning light for 0.2 s, add one to the count and log it.
// band-pass filter coefficients (centre f0, Q = 2), fs = 200000
float w0 = 2 * PI * f0 / fs, al = sin(w0) / (2 * 2.0);
float b0 = al / (1 + al), b2 = -al / (1 + al);
float a1 = -2 * cos(w0) / (1 + al), a2 = (1 - al) / (1 + al);

// one combustion: vibration energy in the window
float knock_energy(const int16_t *s, int n) {
  float x1 = 0, x2 = 0, y1 = 0, y2 = 0, e = 0;
  for (int i = 0; i < n; i++) {
    float x = s[i] - 2048;                        // 12-bit, mid-scale = 0
    float y = b0 * x + b2 * x2 - a1 * y1 - a2 * y2;
    x2 = x1; x1 = x; y2 = y1; y1 = y;
    e += y * y;
  }
  return e / n;
}

// decision: sensitivity 0-F (0 = most sensitive)
bool is_knock(float e, float median32, int level) {
  float k = 1.5f + 0.5f * level;                  // 1.5x to 9x
  return e > k * median32;
}

Example window: 60° at 12,500 rpm is 0.8 ms, about 160 samples, with about 8 cycles of the knock wave in it. The starting multiple is a guess; set it from recordings on the bike.

9. Setting up and using it

  1. On the bench: bolt the sensor to a block of metal and tap it lightly with a small hammer. If the waveform shows on the PC, the wiring is good.
  2. With the engine running: just record at first, and plot the vibration energy in the knock window against rpm. That shows what normal sounds like.
  3. Set the sensitivity: as in HRC's procedure, start at the sensitive end (0); if the light stays on while running normally, move towards the less sensitive end, until it normally stays off in the power band under load.
  4. Ride and count: divide the count in the full-throttle sections by the distance to get counts per km. HRC's target is 1–2 per km.
  5. Use it for setting: if the count is high, go up a main jet (richer) or retard the ignition. If it stays at 0, there is still room to go further. Change one thing at a time.

HRC's material lists causes of detonation beyond the main jet: the jet needle, pilot jet, power jet, plug heat range, coolant temperature and oil.

10. Why it can miscount

Counts when there is no detonation

  • Worn crank or con-rod bearings letting the piston slap (also in HRC's material)
  • Electrical noise from the ignition coil and plug lead
  • A loose sensor, the sensor or counter box itself vibrating, or damaged wiring
  • A thin bracket ringing by itself

Misses real detonation

  • The sensor is not tight enough, or its contact face is not flat
  • The filter centre is off the real knock pitch (look at a recording and re-centre it)
  • Sensitivity turned down too far

Most seizures come from a mixture that is too lean or from cooling, which is a different thing from detonation. A count of 0 does not mean the engine cannot seize.

11. Does it work on a 50cc?

Yes. There is no limit on engine size. These things change:

ExampleBoreKnock pitch (first mode)In KS4-P range (3–25 kHz)?
50cc40 mmabout 11.7–14.7 kHzYes
125cc (NF4)54 mmabout 8.7–10.9 kHzYes
250cc twin (per cylinder)54 mmabout 8.7–10.9 kHzYes
250cc single66.4 mmabout 7.1–8.8 kHzYes
  • Higher pitch: the smaller the bore, the higher it is. Just set the filter centre with the calculator above.
  • Higher rpm: the window gets shorter, but 200,000 readings a second is plenty.
  • Mounting: small heads often use M6 studs. The KS4-P takes M8, so make a boss or a bracket.
  • Two or more cylinders: fit one sensor per cylinder and judge each against its own spark. The Pico 2 has three ADC inputs, so this layout covers up to three cylinders.

12. Build order

  1. Connect just the sensor and the Pico 2, tap it, and look at the waveform on a PC
  2. Fit it to the engine and record the vibration (this is where you find the real knock pitch)
  3. Add the ignition signal and cut out the listening window
  4. Add the filter and the decision, then the warning light and the count display
  5. Log to SD with GPS and put where it happened on a track map

Sources: HRC, "Setting with the detonation counter" (RS125R/RS250R, in Japanese); Soda and Sato, "Detonation Counter for Production Racing Motorcycle" (SAE 1999-01-3324); a UK RS125 specialist's description of the HRC kit; Bosch Motorsport KS4-P product information. Knock frequencies are calculated with Draper's formula.

Feedback and error reports

MotoRaceLab improves every day thanks to our readers' feedback. The editors read everything we receive, and changes we make are announced in the Changelog. If you wish, we will list your nickname on our Contributors page.

Type
Sent automatically
Page
Part of the page
Device

We do not ask for your e-mail or real name, and we do not store IP addresses.