4000 pulse per mile output question for speedometer gauge

Hi again, I am having another difficult time finding examples of what I want to achieve with the next stage of this project. I found one or 2 examples on Youtube, but no code to review.

Goal: Output the correct pulse per mile signal to drive a factory speedometer based on current MPH input value that the Arduino has stored.

The MPH input value is read from the engine control module (ECM) canbus (already have sorted out) and is stored as a int.

Clint

Sorry for the lack of details. The factory speedometer / Instrument cluster is from a 2006 BMW x5. With coding/programming, I changed the settings from Canbus input to analog input to drive the speedometer. This has been done on one of my other BMW's.
On another engine swap I've done is a 1999 5 series bmw, did the same coding to turn the speedometer to analog input, and wired the speedometer signal from the ECM directly to the cluster connector per wire diagrams and works exactly as it should.

this new project, the ECM (2019 GM Silverado e92a) does not have a MPH output wire, everything is canbus. I am lacking how to make this signal output

clint

4000 pulses per mile means that at 1mph, there would be 4000 pulses per hour which is a pulse every 0.9s.

At 100mph, it would mean a pulse every 0.009s or 9ms which is a frequency of 111Hz.

My immediate thought was to use the tone() function, but that has a lowest frequency of 31Hz, at least on many types of Arduino.

What type of arduino are you using?

@PaulRB I only have Nanos and a regular Uno. I was thinking of picking up a Mega 2560 PRO MINI as this project expands.
thanks,
clint

I think toneAC() can go down to 1Hz.
Leo..

Is this different than blinking a LED, very fast, using micros() ? What kind of pulse is sent by the original sensor ? Is the pulse ON time constant ?

Maybe it is different. Using "blink" or "blink without delay" techniques creates the pulses in software. At higher road speeds, the pulses might be produced inaccurately when the code is also performing other tasks such as communicating with the ECM over CANBUS. With careful coding, it might be possible to produce the pulses accurately, I don't know, I'm not very familiar with CANBUS libraries.

Using one of the various tone libraries instead of the built-in tone() function means that the pulses are generated in hardware (and possibly some software in an interrupt routine). This way, producing accurate pulses won't be disturbed by other tasks like reading CANBUS.

The standard built-in arduino tone() function uses one of the 8-bit timers which causes that limitation of 31Hz minimum frequency. But other available tone libraries (tone, toneac...) use, or can use, a 16-bit timer which can produce a wider range of frequencies.

Thanks for the info and recommendations on tone. I'm going to plan connecting an oscilloscope and observe the actual signal next weekend.
clint

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.