
Originally Posted by
manitou
your selective snippets of code are insufficient. They do not show variable declarations, how timing is managed ... can you not paste in your full sketch (or a working subset that demonstrates the problem). on this forum go to Advanced and use the # (code tags) to encapsulate your pasted sketch. indentation will be retained if you use the code tags. jpg's of your code makes it hard for others to run/test your sketch.
In going from UNO to T3.2, int's are 32 bits, and the MCU runs 6 times as fast, ...
Setup and loop:
Code:
//====================
//Variables
//====================
//Pins
const byte RoadspeedPin = 2;
const byte Solenoid1Pin = 3;
const byte Solenoid2Pin = 4;
const byte Solenoid3Pin = 5;
const byte BrakePin = A1;
const byte ThrottlePin = A0; //Digital 20 - 3.3v
//Calculation Constants
//=====================
//Multipliers
const float speedoMulti = 0.00580486; //MPH Slope Multiplier
const float throttleMulti = 0.064601; //Throttle Slope Multiplier
//Shift Adjustments
const int accelLimit = 128; //Roughly 3 MPH
//Shift Points
const int shiftPoint1 = 512;
const int shiftPoint2 = 1024;
const int shiftPoint3 = 2048;
const int tcLockPoint = 1728; //40 MPH
//Throttle Min-Max
const int throttleMin = 0;
const int throttleMax = 100;
//Brake Min-Max
const int brakeMin = 0;
const int brakeMax = 100;
//Brake Switch Constant Adjustments
const int brakeSensitivity = 84; //0-100%
const unsigned long brakeDelayAdj = 2000; //Wait 2 seconds
const unsigned long debounceDelay = 100; //100 MS debounce delay for brake switch
//Non-Static Variables
//====================
//Switch Debouncing
unsigned long lastDebounceTime = 0; //Last time switch was toggled
//Outputs
boolean Solenoid1 = false;
boolean Solenoid2 = false;
boolean Solenoid3 = false;
//Outputs from Functions
float MPH = 0.0; //Roadspeed in Miles Per Hour for Serial Data
byte ActiveGear = 4; //Start in 4th gear for safety
boolean TorqueConverter = 0; //Status of torque converter - starts unlocked
//Inputs
int Throttle = 0; //0-100%
boolean BrakeSwitch = 0; //0-100%
unsigned long Roadspeed = 0; //Total Pulses
//Real Time Adjustments
unsigned int shiftPoint1Adj = shiftPoint1;
unsigned int shiftPoint2Adj = shiftPoint2;
unsigned int shiftPoint3Adj = shiftPoint3;
unsigned int tcLockPointAdj = tcLockPoint;
int accelerationModifier = 0; //If Acceleration is positive or negative, this value is modified by a constant to change up and down shift points
float ThrottleModifier = 0; //As the throttle changes from 0-100, this value is modified by a constant non-linear function to change up and down shift points
//Differential Calculation
//State Change Variables
boolean pulseState = false;
boolean roadspeedState = 0; //Is the roadspeed sensor state HIGH or LOW?
boolean lastRoadspeedState = 0; //What was the last state of the roadspeed sensor?
boolean sensorState = false;
boolean lastSensorState = false;
//Pulse Differential
unsigned long cycleTimeCurrent = 0;
unsigned long cycleTimeLast = 0;
unsigned long cycleTime = 0;
//Acceleration Differential
int RoadspeedPrevious = 0; //0-100 MPH
int RoadspeedDifferential = 0; //Positive or Negative Integer for acceleration logic
//Total Differential Calculation
unsigned long RoadspeedTotalCurrent = 0;
unsigned long RoadspeedTotalPrevious = 0;
//Brake Switch
int brakeRead = 0;
boolean brakeOn = 0;
boolean brakeOnLast = 0;
boolean brakeDelay = 0;
unsigned long brakeTimer = 0;
//Timing
elapsedMillis sinceUpdateStates;
//Timing Delays
const int sampleTimeValues = 250; //Refresh Delay in Milliseconds
void setup()
{
//Set Input Pin States
pinMode(RoadspeedPin, INPUT);
//Set Output Pin States
pinMode(Solenoid1Pin, OUTPUT);
pinMode(Solenoid2Pin, OUTPUT);
pinMode(Solenoid3Pin, OUTPUT);
//Begin Serial
Serial.begin(115200);
}
void loop()
{
//Instantaneous Response Functions
roadspeedReadAlt(); //Poll Roadspeed Sensor Pin and count pulses
brakeControl(); //Poll Brake Switch Pin and apply debouncing and delay
if (sinceUpdateValues >= sampleTimeValues)
{
//Differentials
//Roadspeed Differential
Roadspeed = RoadspeedTotalCurrent - RoadspeedTotalPrevious;
RoadspeedTotalPrevious = RoadspeedTotalCurrent;
//Roadspeed Accceleration
RoadspeedDifferential = Roadspeed - RoadspeedPrevious;
RoadspeedPrevious = Roadspeed;
MPH = speedoMulti * Roadspeed;
//Main Ordered Functions
throttleControl();
checkAcceleration();
ShiftPositionUpdate();
ShiftGearUpdate();
TorqueConverterUpdate();
setShiftSolenoids();
//activateShiftSolenoids();
//SerialOutput();
//Reset Data Timer Differential
sinceUpdateValues = 0;
}
}
Relevant sensor code:
Code:
void roadspeedReadAlt()
{
//Read sensor
sensorState = digitalReadFast(RoadspeedPin);
//When the first high pulse is encountered, set the pulse state to high.
if (sensorState != lastSensorState)
{
lastSensorState = sensorState;
// if the state has changed, increment the counter
if (sensorState == HIGH)
{
RoadspeedTotalCurrent++;
}
}
}
//NOT CURRENTLY USED
void roadspeedRead()
{
//Count Sensor Pulses
sensorState = digitalReadFast(RoadspeedPin);
if (sensorState == HIGH && pulseState == false)
{
pulseState = true;
RoadspeedTotalCurrent++;
}
else if (sensorState == LOW)
{
pulseState = false;
}