My code added error checking, limp mode, etc for if one of the pedal sensors is faulty. That stuff would work on any pedal. Here's my code, you'll have to port it yourself to work with the VCU, it outputs to the variable "aps", you can probably just map it to the max torque rather than 4095 and return it if you like. I mix my pedal reading with the cruise control functions to allow acceleration during cruise, etc, so it's handled differently. Should still be usable for porting to the VCU.
The output from the pedal is in the 5V range but it must not go above 3.3V as I just used a 1K resistor in series and it never maxes out the ADC.
Code: Select all
//accelerator pedal limits
#define APSMIN 160 //160
#define APSMAX 780 //780
#define APSLOW 230 //230
#define APSHIGH 660 //715
#define APSDELTA 20 //20
int16_t aps1, aps2, apscheck, aps = 0;
uint8_t apsgood = 0;
bool limp_mode = 0;
//aps1 203-665
//aps2 318-780
void get_aps()
{
aps1 = analogRead(pin_aps1);
aps2 = (analogRead(pin_aps2) - 115);
apscheck = aps1 - aps2;
if ((apscheck >= -APSDELTA) && (apscheck <= APSDELTA) && (aps1 >= APSMIN) && (aps1 <= APSMAX) && (aps2 >= APSMIN) && (aps2 <= APSMAX)) //normal
{
apsgood = 3;
aps = map(aps1, APSLOW, APSHIGH, 0, 4095);
}
else if ((aps1 >= APSMIN) && (aps1 <= APSMAX)) //app1 still valid, limp mode
{
apsgood = 1;
limp_mode = 1;
aps = map(aps1, APSLOW, APSHIGH, 0, 4095);
}
else if ((aps2 >= APSMIN) && (aps2 <= APSMAX)) //app2 still valid, limp mode
{
apsgood = 2;
limp_mode = 1;
aps = map(aps2, APSLOW, APSHIGH, 0, 4095);
}
else //cant use the pedal
{
apsgood = 0;
aps = 0;
}
if (limp_mode) aps /= 4;
if (aps < 0)aps = 0;
if (aps > 4095)aps = 4095;
}