Newbie to coding, how to read and store a pulsed ground?

Hi all,

I haven’t done any major programming in more than a decade, and I’m nearly starting from scratch. I have a project I’d like to complete but don’t yet have the knowledge to do it, and was wondering if I could get a push in the right direction.

What I’d like to do is measure my VSS, and depending on whether my vehicle is above or below a certain speed, to vary the output of another pin. Over at InsightCentral, a member named Mudder wrote the following code:

int QBATTpin=10;
int ACTTRQpin=11;
int MOTFSApin=12;
int MOTFSBpin=13;

char frameorder={“ba”};

void setup() {
pinMode(MOTFSApin,OUTPUT); //clock
pinMode(MOTFSBpin,OUTPUT); //data
pinMode(QBATTpin,OUTPUT); //2kHz PWM, 10%=empty, 90%=full
pinMode(ACTTRQpin,OUTPUT); //2kHz PWM, assist>50%, regen<50%

Serial.begin(115200);

analogWrite(ACTTRQpin,127); //50% duty tells ECU “IMA not delivering torque”
analogWrite(QBATTpin,30); //12% duty tells ECU battery is nearly empty.
//Note: ECU will Autostop (i.e. stall) if QBATT indicates battery is charged
}

void loop()
{
for(int ii=0;ii<sizeof(frameorder);ii++)
{ Serial.println("");
bitbang_MOTFSB_frame(frameorder[ii]);
}
}

void bitbang_MOTFSB_frame(char nn)
{
if(nn==‘a’)
{
bangbit(1);
bangbit(1);
bangbit(1);
bangbit(1);
bangbit(1);
bangbit(1);
bangbit(1);
bangbit(1);
bangbit(1);
bangbit(0);
Serial.print(“A”);
}
else if (nn==‘b’)
{
bangbit(0);
bangbit(0);
bangbit(0);
bangbit(0);
bangbit(0);
bangbit(0);
bangbit(0);
bangbit(0);
bangbit(0);
bangbit(0);
Serial.print(“B”);
}
}

void bangbit(bool jj)
{
digitalWrite(MOTFSApin,LOW); //clock low
digitalWrite(MOTFSBpin,jj); //set data
delay(20); //20 ms
digitalWrite(MOTFSApin,HIGH); //clock high
delay(20);
}

Basically, I want to read a VSS signal and, when my speed is above X, instead of “analogWrite(QBATTpin,30)” I’d like it to instead output “analogWrite(QBATTpin,128)”. If anyone is curious I can explain why.

The first place I started reading was over at Ecomodder.com. There’s the MPGuino project, which uses an Arduino to read vehicle speed sensor (VSS) pulses and injector pulses, and display miles per gallon. I can see they have a 50k ohm resistor and then the VSS signal connects to analog pin 0, and I thought I might glance at their code to see how they read the VSS signal and store it, but I’m in over my head.

Here are two versions of the MPGuino code, both made publicly available:

Can anyone help? How might I count VSS pulses, store that value, and then use it to determine what to output?

Thanks,
Ecky

What exactly is VSS - what is causing the pulses?
What is the HIGH and LOW pulse voltage?
What is the slowest and fastest pulse rate?

I control the speed of a small DC motor using code like in this link to detect the speed. It assumes there is an attachInterrupt() command in setup()

...R

I believe the VSS signal is intermittent grounding to a voltage source. I haven’t yet measured what the voltage is, but from reading online I understand it can be anywhere from millivolts to ~5v. Frequency is probably going to be ballpark around 100hz at 100mph.

Here’s a thread on the topic which contain relevant information, though my goal is different:

I thought that if I could make sense of the MPGuino code I linked to in my OP, I could just copy the relevant portions (or at least get an idea of what I need to do), but sadly I can’t.

Ecky:
I haven't yet measured what the voltage is, but from reading online I understand it can be anywhere from millivolts to ~5v.

You need to be certain the voltage is always between 0 and 5v or it may damage the Arduino (assuming a 5v Arduino)

Frequency is probably going to be ballpark around 100hz at 100mph.

1 Hz / mph seems a very low rate

...R

I'll double check the voltage. I don't have an oscilloscope so I can't verify frequency. However, I know for a fact the VSS is typically hooked up to an arduino in ecomodder's MPGuino build, with a 50k ohm resistor, and it works. I just can't make sense of the code.

8000 pulses per mile is typical of most vehicles, older ones anyway. It's a physical gear turning which causes a ground every time it passes. Typically speeds less than 5mph don't show properly, which is why most older speedometers didn't have a zero.