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:
https://drive.google.com/open?id=1vbJevqJJ-8RshKbFiDaWntibZTU23Ava
https://drive.google.com/open?id=1sLAcqOm7qg0pUWcpBCSewBUzpogBV49z
Can anyone help? How might I count VSS pulses, store that value, and then use it to determine what to output?
Thanks,
Ecky