Hello everyone. I am in the process of programming a tiptonic shifter for my vehicle. I am figuring out most of it while I go but I have searched and searched and now I have no idea how to make this happened.
This is the operation I currently have functioning:
output "ctrlSolenoid[2]" will be HIGH if "solenoidPin[2]" is HIGH or "TorqCnvtr_Switch_iPIN" is HIGH.
What I want to add:
I have created a boolean "blnTorqLockEnable". My goal is that when int GearOutput is changed (either by the intGear switch or Auto Pass Through Mode (blnManualShift true or false)) then "blnTorqLockEnable" would be false for "x" amount of seconds to allow the shift. Almost like a clutch in a manual car.
The section of code referenced above can be found in void GearBox starting on line 162.
// LIBRARIES ---------------------------------------------------v
#include <Bounce.h>
// -------------------------------------------------------------^
// CONFIGURATION -----------------------------------------------v
// tachometer
const int INT_FrontPulsesPerRev = 16; // Front sensor pulses per revolution
const int INT_RearPulsesPerRev = 4; // Rear sensor pulses per revolution
const unsigned long ULNG_SamplingMS = 250;
// Torque Converter Lock Momentary disengaging time in milliseconds
const unsigned long ULNG_TorqLockDisableT = 1000;
// inputs
const int FrontSensor_iPIN = 2;
const int TorqCnvtr_Switch_iPIN = 13;
// outputs
const int RearSensor_oPIN = 12;
const int btnPin[] = { A2, A1, A0 };
// Up, Down, Mode
long btnDebounces[] = { 0, 0, 0 };
// -> CurrentState, LastState
int buttonStates[3][2] = { {LOW, LOW},
{LOW, LOW},
{LOW, LOW} };
// A, B, TCC
int solenoidStates[3] = { LOW, LOW, LOW };
const int ctrlSolenoid[] = { 6, 7, 5 };
const int solenoidPin[] = { A4, A5, A3 };
long debounceDelay = 20; // the debounce time; increase if the output flickers
// gear ratios
const float FLT_GearRatios[] =
{ 0.3571, 0.6535, 1.0000, 1.3333 };
// -------------------------------------------------------------^
// VARIABLES AND OBJECTS ---------------------------------------v
unsigned long ulngTachCounter = 0;
unsigned long ulngTachTS = 0;
float fltFrontFrequency;
float fltRearFrequency;
int intGear;
int intGearNumber;
boolean blnTorqLockEnable = true;
float fltGearRatio;
unsigned long ulngTorqLockDisable = 0;
unsigned long ulngRearSensorTS = 0;
boolean blnRearSensorState = false;
unsigned long ulngRearTHalfus;
boolean blnManualShift = false;
// DEBUG
const boolean blnDBG = true;
unsigned long ulngDBGTS = 0;
// -------------------------------------------------------------^
void setup() {
Serial.begin(9600);
// Configure Pins
ConfigurePins();
// Start in Auto Shift Mode, Gear at 1st, Torque Converter Lock off
blnManualShift = false;
intGear = 1; // first gear is zero
intGearNumber = 1;
blnTorqLockEnable = true;
}
void loop() {
// Read Shifting, Auto/Man and Torque Lock Buttons, Change Gears and Manage Solenoids
GearBox();
}
void GearBox() {
for (int btn = 0; btn < 3; btn++) {
int reading = digitalRead(btnPin[btn]);
if (reading != buttonStates[btn][1]) { // last button state
btnDebounces[btn] = millis();
}
if ((millis() - btnDebounces[btn]) > debounceDelay) {
if (reading != buttonStates[btn][0]) {
buttonStates[btn][0] = reading;
// only toggle the LED if the new button state is HIGH
if (reading == HIGH) {
switch(btn) {
case 0: // Up
intGear = GearOutput();
blnManualShift = true;
intGear++;
if (intGear > 4) intGear = 4;
Serial.write("UP\n");
break;
case 1: // Down
intGear = GearOutput();
blnManualShift = true;
intGear--;
if (intGear < 1) intGear = 1;
Serial.write("DOWN\n");
break;
case 2: // Mode
blnManualShift = !blnManualShift;
Serial.write("MODE\n");
break;
}
}
}
}
buttonStates[btn][1] = reading;
}
switch (intGear) {
case 1:
digitalWrite(ctrlSolenoid[0], HIGH);
digitalWrite(ctrlSolenoid[1], LOW);
break;
case 2:
digitalWrite(ctrlSolenoid[0], HIGH);
digitalWrite(ctrlSolenoid[1], HIGH);
break;
case 3:
digitalWrite(ctrlSolenoid[0], LOW);
digitalWrite(ctrlSolenoid[1], HIGH);
break;
case 4:
digitalWrite(ctrlSolenoid[0], LOW);
digitalWrite(ctrlSolenoid[1], LOW);
break;
}
//AUTO Pass Through MODE
if (blnManualShift == false) {
digitalWrite(ctrlSolenoid[0], digitalRead(solenoidPin[0]));
digitalWrite(ctrlSolenoid[1], digitalRead(solenoidPin[1]));
intGear = GearOutput();
}
// Manage the torque lock
// while watching for gear changes
//-----------------------
// If Gear changed >> Torque Lock disabled for shifting
if (GearOutput() != intGear) {
ulngTorqLockDisable = millis();
blnTorqLockEnable = false;
}
// Torque Lock re enabled after shift
if ( msElapsed(blnTorqLockEnable) > ULNG_TorqLockDisableT ) {
blnTorqLockEnable = true;
}
// Torque lock will go HIGH if Solenoid 3 input is HIGH or if the Torque Lock switch is ON. This only if the gear has not shifted.
// If it has shifted it would be temporarily disabled using the blnTorqLockEnable variable set to true when a change of gear was detected
if (digitalRead(TorqCnvtr_Switch_iPIN) == HIGH && blnTorqLockEnable == true) {
digitalWrite(ctrlSolenoid[2], HIGH);
}
else {
digitalWrite(ctrlSolenoid[2], digitalRead(solenoidPin[2]));
}
}
// TIMING FUNCTIONS
unsigned long msElapsed(unsigned long ulngTms) {
// RETURNS THE MILLISECONDS ELLAPSED SINCE ulngTms
return millis() - ulngTms;
}
unsigned long usElapsed(unsigned long ulngTus) {
// RETURNS THE MICROSECONDS ELLAPSED SINCE ulngTus
return micros() - ulngTus;
}
// SHIFTING FUNCTIONS
int GearOutput() {
int intGearNumber;
intGearNumber = 2*digitalRead(ctrlSolenoid[1]) + digitalRead(ctrlSolenoid[0]);
switch(intGearNumber) {
case 1: // 1st Gear
return 1;
break;
case 3: // 2nd Gear
return 2;
break;
case 2: // 3rd Gear
return 3;
break;
case 0: // 4th Gear
return 4;
break;
}
}
// SETUP FUNCTION
void ConfigurePins() {
pinMode(btnPin[0], INPUT);
pinMode(btnPin[1], INPUT);
pinMode(btnPin[2], INPUT);
pinMode(ctrlSolenoid[0], OUTPUT);
pinMode(ctrlSolenoid[1], OUTPUT);
pinMode(solenoidPin[2], INPUT);
pinMode(TorqCnvtr_Switch_iPIN, INPUT);
pinMode(FrontSensor_iPIN, INPUT);
pinMode(ctrlSolenoid[2], OUTPUT);
pinMode(RearSensor_oPIN, OUTPUT);
}
Any help is much appreciated.
Kris