Main Menu

HE351 code for me78569

Started by me78569, June 11, 2015, 09:38:57 AM

me78569

Alright, I have my code tabbed but this should reflect what I am working with.  I haven't had a chance to really narrow down the issue much, so don't spend too much time digging until I figure out the issue better.

Issue:  With the pot active I get a rapid cycling from 0 to desired position.  When the truck is sitting at 0 psi without the pot active it sits right at the commanded position.   I very well could have a wiring issue in the pot that is causing issues.

This afternoon I am going to connect the spare pots to the boost and drive sensors and test what happens when psi raises above 0 to verify that the issue is limited to the pot functions.  I will also test the EB code and verify that I am not having issues there also.

I will update the thread once I do some of the basic testing to verify the issue and try to narrow it down.


/*This code is to help get you started controlling your
HE351VE Variable Geometry Turbo. The whole program is
controlled through void loop(). This is where you can
add your own code or uncomment different sections of code
that I have put together. This is covered by the GNU License*/

#include <SPI.h>
#include <can.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

// Defines for setting up the CAN Bus
#define mode NORMAL // define CAN mode
#define bitrate 250 // define CAN speed (bitrate)
MCP CAN1(10); //Create CAN Channel
//J1939 message; // Create message object to use J1939 message structure
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

// Pin Assignments on UNO
#define BoostPressurePin A0
#define ExhaustPressurePin A1
#define PotentiometerPin A2
#define ThrottlePositionPin A3
#define Switch 2
#define EBSwitch 12


#define NumEntries 14
// The first number is the boost sensor reading, and the second number is the desired vein position
// remember usable vien position range from 140-960
int BoostMap[NumEntries][2] = {{10,235},{11.5,244},{13,253},{14.5,280},
{16,308},{17.5,308},{19,363},{20.5,390},{22,418},{23.5,459},{25,500},{26.5,550},
{28,600},{29.5,650}};  //,{31,700},{32.5,750},{34,800},{35.5,850},{37,900},{38.5,950},{40,970}}; DPManage takes care of the veins after 30psi. 


  // Variables to read sensors
  int MaxExhaustPressure = 50; //Set desired max exhuast back pressure
  int ExPrsBuffer = 10; //set the point at which the system starts to manage IE: maxehaustpressure - exprsbuffer
  byte EBCalibrate = 2;
  int PotentiometerValue = 0;
  int ExhaustPressure = 0;
  int BoostPressure = 0;
  int ThrottlePosition = 0;
  boolean SwitchPosition = false;
  boolean EBSwitchPosition = false;
//  const int analogDelay = 1;

  // Value to Send Position
  int DesiredPosition = 0;

  // Variables to use within Code
  int JumpSize = 50;
  int MinVeinPos = 235;

  //Variables for LCD
  long LCDLastUpdate = 0;
  int Line1Last = 0;
  int LCDUpdateRate = 200;
 
// Exhaustpressure Average variables
  const int ExtnumReadings = 4;      // number of reads to do.
  int Extreadings[ExtnumReadings];      // the readings from the analog input
  int Extindex = 0;                  // the index of the current reading
  int Exttotal = 0;                  // the running total
  int Extaverage = 0;                // the average
 
  //  Boostpressure Average variables
  const int BstnumReadings = 4;      // number of reads to do.
  int Bstreadings[BstnumReadings];      // the readings from the analog input
  int Bstindex = 0;                  // the index of the current reading
  int Bsttotal = 0;                  // the running total
  int Bstaverage = 0;                // the average


///////////////////////will run once at startup//////////////////////////////////////////// 
  void setup()
{
  // Initialize Serial communications with computer to use serial monitor
  Serial.begin(115200);
  lcd.begin(20,4);         // initialize the lcd for 20 chars 4 lines and turn on backlight
  //Set CAN mode and speed
  CAN1.begin(mode, bitrate);

  // Setup Switch
  pinMode(Switch, INPUT_PULLUP); //configure switch to use internal pullup resistor
  pinMode(EBSwitch, INPUT_PULLUP); //configure EBswitch to use internal pullup resistor
  //Running exhaust average
    for (int ExtthisReading = 0; ExtthisReading < ExtnumReadings; ExtthisReading++)
    Extreadings[ExtthisReading] = 0;
  //Running Boost averag
    for (int BstthisReading = 0; BstthisReading < BstnumReadings; BstthisReading++)
    Bstreadings[BstthisReading] = 0;
   
//-------- Write characters on the display ----------------
// NOTE: Cursor Position: CHAR, LINE) start at 0 
  lcd.setCursor(2,0); //Start at character 4 on line 0
  lcd.print("Starting HE351VE");
  lcd.setCursor(5,1);
  lcd.print("Controller");
  lcd.setCursor(4,2);
  lcd.print("Will Display ");
  lcd.setCursor(0,3); 
  lcd.print("Boost,Drive,Position");
  delay(4000);
  lcd.clear();
  lcd.setCursor(4,0); //Start at character 4 on line 0
  lcd.print("Cycling Vein");
  lcd.setCursor(6,1);
  lcd.print("Position");
  lcd.setCursor(3,3);
  lcd.print("Wait To Start!");
  delay(2000);
  lcd.clear();
  SendTurboPosition (140);
  lcd.clear();
  lcd.setCursor(4,0); //Start at character 4 on line 0
  lcd.print("Cycling Vein");
  lcd.setCursor(6,1);
  lcd.print("Position");
  lcd.setCursor(3,3);
  lcd.print("Wait To Start!");
  delay(500);
  SendTurboPosition (140);
  lcd.clear();
  lcd.setCursor(4,0); //Start at character 4 on line 0
  lcd.print("Cycling Vein");
  lcd.setCursor(6,1);
  lcd.print("Position");
  lcd.setCursor(3,3);
  lcd.print("Wait To Start!");
  delay(500);
  SendTurboPosition (140);
  lcd.clear();
  lcd.setCursor(4,0); //Start at character 4 on line 0
  lcd.print("Cycling Vein");
  lcd.setCursor(6,1);
  lcd.print("Position");
  lcd.setCursor(3,3);
  lcd.print("Wait To Start!");
  delay(500);
  lcd.clear();
  lcd.setCursor(8,2);
  lcd.print("Done!");
  delay(1000);
  lcd.clear();

}


/////////////////// Main loops that chooses what to do.////////////////////////////////////////////
void loop()
  {
    // Read Sensors
    // Uncomment the Sensors that you have connected
    // There functions will need to be calibrated to the sensor.
    PotentiometerValue = ReadPotentiometer();
    ExhaustPressure = ReadExhaustPressure();   
    BoostPressure = ReadBoostPressure();   
    ThrottlePosition = ReadThrottlePosition();
    SwitchPosition = digitalRead(Switch);
    EBSwitchPosition = digitalRead(EBSwitch);


    {

    if ( SwitchPosition == HIGH && EBSwitchPosition == HIGH && BoostPressure >= 30)
      DPManage (); //set vein position based on boostmap
       
    else if (SwitchPosition != HIGH) // && ThrottlePosition < 30) //Disabled TPS input for testing
      PotManage ();  //vein position is pot value

    else if (EBSwitchPosition != HIGH && SwitchPosition == HIGH) // && ThrottlePosition < 1.5 )  //Disabled TPS input for testing
      EBManage (); //If below %1.5 then engage Exhaust brake and regulate the exhaust pressure.
               
    else DesiredPosition = BoostVeinPosCalc( BoostPressure );
    }

    // Set the Turbo Position
    SendTurboPosition( DesiredPosition );
    UpdateLCD();
    // Delay for Processor
    delay(2);
   
  }


////////////////////////////////Read Sensors//////////////////////////////////////////////
//Define the sensor type and range. (Namefromabove, 0v, 5v, 0v=minpos,5v=maxposition)

int ReadBoostPressure(){    //Works good but seems to be slower.
  Bsttotal = Bsttotal - Bstreadings[Bstindex]; // subtract the last reading:       
  Bstreadings[Bstindex] = analogRead(BoostPressurePin); // read from the sensor:
  Bsttotal= Bsttotal + Bstreadings[Bstindex];   // add the reading to the total:   
  Bstindex = Bstindex + 1;    // advance to the next position in the array:                 
  if (Bstindex >= BstnumReadings)    // if we're at the end of the array...         
    Bstindex = 0;    // ...wrap around to the beginning:                       
  Bstaverage = Bsttotal >> 2; // / BstnumReadings;    // calculate the average:     
  return map( Bstaverage, 83, 920, 0, 100); // Last two values are the psi range of the chosen sensor
  delay(1);        // delay in between reads for stability
}

int ReadExhaustPressure(){    //Works good but seems to be slower.
  Exttotal = Exttotal - Extreadings[Extindex]; // subtract the last reading:       
  Extreadings[Extindex] = analogRead(ExhaustPressurePin); // read from the sensor:
  Exttotal = Exttotal + Extreadings[Extindex];   // add the reading to the total:   
  Extindex = Extindex + 1;    // advance to the next position in the array:                 
  if (Extindex >= ExtnumReadings)    // if we're at the end of the array...         
    Extindex = 0;    // ...wrap around to the beginning:                       
  Extaverage = Exttotal >>2; // / ExtnumReadings;    // calculate the average:     
  return map( Extaverage, 83, 920, 0, 100); // Last two values are the psi range of the chosen sensor
  delay(1);        // delay in between reads for stability
}

int ReadThrottlePosition(){
int ThrottleVal = analogRead( ThrottlePositionPin );
return map ( ThrottleVal, 103, 920, 0, 100); // read the value from the sensor

}
int ReadPotentiometer(){
int PotVal = analogRead( PotentiometerPin );//(tmp + analogRead( PotentiometerPin )) / 2;
return map(PotVal, 0, 1023, 0, 970); // read the value from the sensor
}


////////////////////////////////////DP manage////////////////////////////////////////
//Manages DP to try and stay at or below 50psi drive while about 30psi boost.  veins will stay between 650 and 970 position
void DPManage (){

int Difference = (ExhaustPressure-MaxExhaustPressure); //set a buffer make sure max ex press doesn't get hit.

Difference = (Difference / EBCalibrate); // I used / rather than * as the * ended up applying too fast. the turbo was "snapping" open and closed
DesiredPosition += max(Difference, -10);//This way it doesn't close the veins to fast
DesiredPosition = constrain(DesiredPosition, 650, 970);
}


/////////////////////////////EB Manage////////////////////////////////////////
//Manages the apply of the EB
void EBManage(){

int Difference = (ExhaustPressure-MaxExhaustPressure); //set a buffer make sure max ex press doesn't get hit.

Difference = (Difference / EBCalibrate); // I used / rather than * as the * ended up applying too fast. the turbo was "snapping" open and closed
DesiredPosition += max(Difference, -10);//This way it doesn't close the veins to fast
DesiredPosition = constrain(DesiredPosition, 0,235);

}


//////////////////////////Pot Manage/////////////////////////////////////////////////
//Ensure Pot doesn't cause Drive pressure to go over the maxexhaustpressure **look at more

void PotManage (){
int Rate = 11; // added to make ManageRate grow as exhaust pressure rises to max and above.
int PotBuff = 10;   //amount to buffer the vein position before maxexhaust is reached when in pot mode
int ManageRate = ((ExhaustPressure - MaxExhaustPressure)+Rate);

if (ExhaustPressure < (MaxExhaustPressure-PotBuff))
   DesiredPosition = PotentiometerValue;
   
else if (ExhaustPressure >= (MaxExhaustPressure-PotBuff))
   DesiredPosition = (PotentiometerValue +(JumpSize * ManageRate));
   DesiredPosition = constrain(DesiredPosition, 0, 970);
}


///////////////////////////Vein Position send/////////////////////////////
// Function to calculate turbo vein position
  int BoostVeinPosCalc( int BoostPressureVal )
  {
    int VeinPosition = BoostMap[0][1];
    for(byte i=0;(BoostPressureVal > BoostMap[i][0]) && (i<NumEntries); i++)
    {
      VeinPosition = BoostMap[i][1];
    }

    return VeinPosition;
  }

// Function to Send the Calculated Position to the Turbo
void SendTurboPosition(int TurboPosition)
{
  int FinalPosition = map( TurboPosition, 0, 1023, 999, 0);
  byte lobyte = lowByte(FinalPosition);
  byte hibyte = highByte(FinalPosition);
  unsigned long ID = 0x0CFFC600; // Random Extended Message ID
  byte length = 8; // Data length
  byte data[] = { lobyte, hibyte, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; // data message with an added counter
  CAN1.send ( ID, extID, length, data ); // Load message and send

}


///////////////////BarGraph////////////////////////////////////////////////////

void BarGraph(int Line, int oldBars, int Bars, int Value, String Name)
//Line, which line on the LCD are we changing.
//Bars, number of pixcels long the BaGraph is going to show
//oldBars, number of Bars that this Line had lastt time
//Value, what's the value we should print to the lcd
//Name, the Name we should call this Line

{
int GraphStartPoint = 11;//what cell does the graph start on on the lcd screen

if (oldBars != Bars){ // if nothing changed then skip this function
int oldBlocks = (oldBars / 5);
int blocks = (Bars / 5);
int singles = (Bars - (blocks * 5));
if(blocks > oldBlocks)
{
for(int x = oldBlocks; blocks > x; x++){
lcd.setCursor((x + GraphStartPoint), Line);
lcd.write(1023);
}}

else if(blocks < oldBlocks)
{
for(int x = oldBlocks; blocks <= x; x--){
lcd.setCursor((x + GraphStartPoint), Line);
lcd.print(" ");
//Serial.println(E1);
}}
if ((oldBars - oldBlocks) != singles) {//if the number of singles has changed display the new singles
  lcd.setCursor((blocks + GraphStartPoint),Line);
  lcd.write(singles);
}
}
  lcd.setCursor(GraphStartPoint - 4, Line);
String TurboPos = String(Value, DEC);
if(Value < 1000) TurboPos += " ";
  lcd.print(TurboPos);
  lcd.setCursor(0, Line);
  lcd.print(Name);
}


///////////////////////////////LCD/////////////////////////////////////////
void UpdateLCD(){

  if ((millis() - LCDLastUpdate) >= LCDUpdateRate){
    LCDLastUpdate = millis();
    int Line1Bars = map(DesiredPosition, 0, 1023, 0, 40);//map the value to a 0-50 value.
BarGraph(0, Line1Last, Line1Bars, DesiredPosition, "Turbo");
Line1Last = Line1Bars;
float DrivePressRatio = (ExhaustPressure / BoostPressure);
DrivePressRatio = constrain(DrivePressRatio, 0, 9.9);
String Boost = String("Boost " + String(BoostPressure, DEC) + ' ');
String Drive = String("Drive " + String(ExhaustPressure, DEC) + ' ');
String DtoBRatio = String("DtoB Ratio " + String(DrivePressRatio) + ":1");
       lcd.setCursor(0, 2);
       lcd.print(Boost);
       lcd.setCursor(10, 2);
       lcd.print(Drive);
       if (BoostPressure <= 0){
         lcd.setCursor(0, 3);
         lcd.print("DtoB Ratio 1.00:1");
       }
       else {
         lcd.setCursor(0, 3);
         lcd.print(DtoBRatio);
       }
       if (EBSwitchPosition != HIGH && SwitchPosition == HIGH)
       {
         lcd.setCursor(4, 1);
         lcd.print("!EB  Active!");
       }
       else if (SwitchPosition != HIGH && ThrottlePosition < 30)
       {
         lcd.setCursor(4, 1);
         lcd.print("!Pot Active!");
       }
       else {
         lcd.setCursor(4,1);
         lcd.print("            ");
       }
       

    }
}


2000 Dodge 2500 quad-cab 5.9 Cummins slt, homebuilt 47re revmax 3.5 messed with vb, Quad adr iquad, 4" tbe , pureflow 150 gph. he351ve in the works 100hp DFI inj

me78569




The code that benchtested well is below, but this code does not read the sensor multiple time and  average.  Also loading this code on the unit has the same issue as the above code. 

Something changed when I installed the turbo onto the truck......Just gotta figure out what that is  :-\


//HE351VE Variable Geometry Turbo. The whole program is
//controlled through void loop(). This is where you can
//add your own code or uncomment different sections of code
//that I have put together. This is covered by the GNU License*/

#include <SPI.h>
#include <can.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

// Defines for setting up the CAN Bus
#define mode NORMAL // define CAN mode
#define bitrate 250 // define CAN speed (bitrate)
MCP CAN1(10); //Create CAN Channel
//J1939 message; // Create message object to use J1939 message structure
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

// Pin Assignments on UNO
#define BoostPressurePin A0
#define ExhaustPressurePin A1
#define PotentiometerPin A2
#define ThrottlePositionPin A3
#define Switch 2
#define EBSwitch 12


#define NumEntries 14
// The first number is the boost sensor reading, and the second number is the desired vein position
// remember usable vien position range from 140-960
int BoostMap[NumEntries][2] = {{10,235},{11.5,244},{13,253},{14.5,280},
{16,308},{17.5,308},{19,363},{20.5,390},{22,418},{23.5,459},{25,500},{26.5,550},
{28,600},{29.5,650}};  //,{31,700},{32.5,750},{34,800},{35.5,850},{37,900},{38.5,950},{40,970}}; DPManage takes care of the veins after 30psi. 


//for loop
  // Variables to read sensors
  int MaxExhaustPressure = 50; //Set desired max exhuast back pressure
  int ExPrsBuffer = 10; //set the point at which the system starts to manage
  byte EBCalibrate = 2;
  int PotentiometerValue = 0;
  int ExhaustPressure = 0;
  int BoostPressure = 0;
  int ThrottlePosition = 0;
  //int LCDupdatecount = 0;
  boolean SwitchPosition = false;
  boolean EBSwitchPosition = false;


  // Value to Send Position
  int DesiredPosition = 0;

  // Variables to use within Code
  int JumpSize = 50;
  int MinVeinPos = 235;

  //Variables for LCD
  long LCDLastUpdate = 0;
  int Line1Last = 0;
  int LCDUpdateRate = 200;

//will run once at startup 
  void setup()
{
  // Initialize Serial communications with computer to use serial monitor
  Serial.begin(115200);
  lcd.begin(20,4);         // initialize the lcd for 20 chars 4 lines and turn on backlight
  //Set CAN mode and speed
  CAN1.begin(mode, bitrate);

  // Setup Switch
  pinMode(Switch, INPUT_PULLUP); //configure switch to use internal pullup resistor
  pinMode(EBSwitch, INPUT_PULLUP); //configure EBswitch to use internal pullup resistor

//-------- Write characters on the display ----------------
// NOTE: Cursor Position: CHAR, LINE) start at 0 
  lcd.setCursor(2,0); //Start at character 4 on line 0
  lcd.print("Starting HE351VE");
  lcd.setCursor(5,1);
  lcd.print("Controller");
  lcd.setCursor(4,2);
  lcd.print("Will Display ");
  lcd.setCursor(0,3); 
  lcd.print("Boost,Drive,Position");
  delay(4000);
  lcd.clear();
  lcd.setCursor(4,0); //Start at character 4 on line 0
  lcd.print("Cycling Vein");
  lcd.setCursor(6,1);
  lcd.print("Position");
  lcd.setCursor(3,3);
  lcd.print("Wait To Start!");
  delay(2000);
  lcd.clear();
  SendTurboPosition (140);
  lcd.clear();
  lcd.setCursor(4,0); //Start at character 4 on line 0
  lcd.print("Cycling Vein");
  lcd.setCursor(6,1);
  lcd.print("Position");
  lcd.setCursor(3,3);
  lcd.print("Wait To Start!");
  delay(500);
  SendTurboPosition (140);
  lcd.clear();
  lcd.setCursor(4,0); //Start at character 4 on line 0
  lcd.print("Cycling Vein");
  lcd.setCursor(6,1);
  lcd.print("Position");
  lcd.setCursor(3,3);
  lcd.print("Wait To Start!");
  delay(500);
  SendTurboPosition (140);
  lcd.clear();
  lcd.setCursor(4,0); //Start at character 4 on line 0
  lcd.print("Cycling Vein");
  lcd.setCursor(6,1);
  lcd.print("Position");
  lcd.setCursor(3,3);
  lcd.print("Wait To Start!");
  delay(500);
  lcd.clear();
  lcd.setCursor(8,2);
  lcd.print("Done!");
  delay(1000);
  lcd.clear();

}

// Main loops that choices what to do.
void loop()
  {
    // Read Sensors
    // Uncomment the Sensors that you have connected
    // There functions will need to be calibrated to the sensor.
    PotentiometerValue = ReadPotentiometer();
    ExhaustPressure = ReadExhaustPressure();   
    BoostPressure = ReadBoostPressure();   
    ThrottlePosition = ReadThrottlePosition();
    SwitchPosition = digitalRead(Switch);
    EBSwitchPosition = digitalRead(EBSwitch);


    {

    if ( SwitchPosition == HIGH && EBSwitchPosition == HIGH && BoostPressure >= 30)
      DPManage (); //set vein position based on boostmap
       
    else if (SwitchPosition != HIGH) // && ThrottlePosition < 30) //Disabled TPS input for testing
      PotManage ();  //vein position is pot value

    else if (EBSwitchPosition != HIGH && SwitchPosition == HIGH) // && ThrottlePosition < 1.5 )  //Disabled TPS input for testing
      EBManage (); //If below %1.5 then engage Exhaust brake and regulate the exhaust pressure.
               
    else DesiredPosition = BoostVeinPosCalc( BoostPressure );
    }

    // Set the Turbo Position
    SendTurboPosition( DesiredPosition );

    // Delay for Processor
    delay(2);
  }

//Read Sensors
//Define the sensor type and range. (Namefromabove, 0v, 5v, 0v=minpos,5v=maxposition)
int ReadPotentiometer(){
int PotVal = analogRead( PotentiometerPin );
return map(PotVal, 0, 1023, 0, 960); // read the value from the sensor
}
int ReadBoostPressure(){
int BoostVal = analogRead( BoostPressurePin ); // read the value from the sensor
return map( BoostVal, 83, 920, 0, 100 ); // Last two values are the psi range of the choosen sensor
}

int ReadExhaustPressure(){
int ExhaustVal = analogRead( ExhaustPressurePin ); // read the value from the sensor
return map( ExhaustVal, 83, 920, 0, 100 ); // Last two values are the psi range of the choosen sensor
}


int ReadThrottlePosition(){
int ThrottleVal = analogRead( ThrottlePositionPin );
return map ( ThrottleVal, 103, 920, 0, 100); // read the value from the sensor

}

//Manages DP to try and stay at or below 50psi drive while about 30psi boost.  veins will stay between 650 and 970 position
void DPManage (){

int Difference = (ExhaustPressure-MaxExhaustPressure); //set a buffer make sure max ex press doesn't get hit.

Difference = (Difference / EBCalibrate); // I used / rather than * as the * ended up applying too fast. the turbo was "snapping" open and closed
DesiredPosition += max(Difference, -10);//This way it doesn't close the veins to fast
DesiredPosition = constrain(DesiredPosition, 650, 970);
}

//Manages the apply of the EB
void EBManage(){

int Difference = (ExhaustPressure-MaxExhaustPressure); //set a buffer make sure max ex press doesn't get hit.

Difference = (Difference / EBCalibrate); // I used / rather than * as the * ended up applying too fast. the turbo was "snapping" open and closed
DesiredPosition += max(Difference, -10);//This way it doesn't close the veins to fast
DesiredPosition = constrain(DesiredPosition, 0,235);

}

//Ensure Pot doesn't cause Drive pressure to go over the maxexhaustpressure **look at more

void PotManage (){
int Rate = 11; // added to make ManageRate grow as exhaust pressure rises to max and above.
int PotBuff = 10;   //amount to buffer the vein position before maxexhaust is reached when in pot mode
int ManageRate = ((ExhaustPressure - MaxExhaustPressure)+Rate);

if (ExhaustPressure < (MaxExhaustPressure-PotBuff))
   DesiredPosition = PotentiometerValue;
   
else if (ExhaustPressure >= (MaxExhaustPressure-PotBuff))
   DesiredPosition = (PotentiometerValue +(JumpSize * ManageRate));
   DesiredPosition = constrain(DesiredPosition, 0, 970);
}

// Function to calculate turbo vein position
  int BoostVeinPosCalc( int BoostPressureVal )
  {
    int VeinPosition = BoostMap[0][1];
    for(byte i=0;(BoostPressureVal > BoostMap[i][0]) && (i<NumEntries); i++)
    {
      VeinPosition = BoostMap[i][1];
    }

    return VeinPosition;
  }

// Function to Send the Calculated Position to the Turbo
void SendTurboPosition(int TurboPosition)
{
  int FinalPosition = map( TurboPosition, 0, 1023, 999, 0);
  byte lobyte = lowByte(FinalPosition);
  byte hibyte = highByte(FinalPosition);
  UpdateLCD();
  unsigned long ID = 0x0CFFC600; // Random Extended Message ID
  byte length = 8; // Data length
  byte data[] = { lobyte, hibyte, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; // data message with an added counter

  CAN1.send ( ID, extID, length, data ); // Load message and send

}

//BarGraph//

void BarGraph(int Line, int oldBars, int Bars, int Value, String Name)
//Line, which line on the LCD are we changing.
//Bars, number of pixcels long the BaGraph is going to show
//oldBars, number of Bars that this Line had lastt time
//Value, what's the value we should print to the lcd
//Name, the Name we should call this Line

{
int GraphStartPoint = 11;//what cell does the graph start on on the lcd screen

if (oldBars != Bars){ // if nothing changed then skip this function
int oldBlocks = (oldBars / 5);
int blocks = (Bars / 5);
int singles = (Bars - (blocks * 5));
if(blocks > oldBlocks)
{
for(int x = oldBlocks; blocks > x; x++){
lcd.setCursor((x + GraphStartPoint), Line);
lcd.write(1023);
}}

else if(blocks < oldBlocks)
{
for(int x = oldBlocks; blocks <= x; x--){
lcd.setCursor((x + GraphStartPoint), Line);
lcd.print(" ");
//Serial.println(E1);
}}
if ((oldBars - oldBlocks) != singles) {//if the number of singles has changed display the new singles
  lcd.setCursor((blocks + GraphStartPoint),Line);
  lcd.write(singles);
}
}
  lcd.setCursor(GraphStartPoint - 4, Line);
String TurboPos = String(Value, DEC);
if(Value < 1000) TurboPos += " ";
  lcd.print(TurboPos);
  lcd.setCursor(0, Line);
  lcd.print(Name);
}
//LCD//
void UpdateLCD(){

  if ((millis() - LCDLastUpdate) >= LCDUpdateRate){
    LCDLastUpdate = millis();
    int Line1Bars = map(DesiredPosition, 0, 1023, 0, 40);//map the value to a 0-50 value.
BarGraph(0, Line1Last, Line1Bars, DesiredPosition, "Turbo");
Line1Last = Line1Bars;
//Serial.println(after-before);
float DrivePressRatio = ((ExhaustPressure*1.00) / (BoostPressure*1.00));
DrivePressRatio = constrain(DrivePressRatio, 0, 9.99);
String Boost = String("Boost " + String(BoostPressure, DEC) + ' ');
String Drive = String("Drive " + String(ExhaustPressure, DEC) + ' ');
String DtoBRatio = String("DtoB Ratio " + String(DrivePressRatio) + ":1");
       lcd.setCursor(0, 2);
       lcd.print(Boost);
       lcd.setCursor(10, 2);
       lcd.print(Drive);
       if (BoostPressure <= 0 ){
         lcd.setCursor(0, 3);
         lcd.print("DtoB Ratio 0.00:1");
       }
       else {
         lcd.setCursor(0, 3);
         lcd.print(DtoBRatio);
       }
       if (EBSwitchPosition != HIGH && SwitchPosition == HIGH && ThrottlePosition < 1)
       {
         lcd.setCursor(4, 1);
         lcd.print("!EB  Active!");
       }
       else if (SwitchPosition != HIGH && ThrottlePosition < 30)
       {
         lcd.setCursor(4, 1);
         lcd.print("!Pot Active!");
       }
       else {
         lcd.setCursor(4,1);
         lcd.print("            ");
       }
       

    }
}
2000 Dodge 2500 quad-cab 5.9 Cummins slt, homebuilt 47re revmax 3.5 messed with vb, Quad adr iquad, 4" tbe , pureflow 150 gph. he351ve in the works 100hp DFI inj

hakcenter

Can you attach the ino's so I can toss them into my editor for more easier everything? :)
TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

me78569

Here you go. 

Like I said, don't dig too deep until I start to troublshoot more.  I would hate to waste a bunch of your time because I have a bad wire somewhere or something dumb like that.
2000 Dodge 2500 quad-cab 5.9 Cummins slt, homebuilt 47re revmax 3.5 messed with vb, Quad adr iquad, 4" tbe , pureflow 150 gph. he351ve in the works 100hp DFI inj

hakcenter

#4
I see some syntax problems and brackets because they are just brackets, and then a lack of bracketing... you want me to go through it a bit and clean it up?

BTW

//////////////////////////Pot Manage/////////////////////////////////////////////////
//Ensure Pot doesn't cause Drive pressure to go over the maxexhaustpressure **look at more

void PotManage() {
int Rate = 11; // added to make ManageRate grow as exhaust pressure rises to max and above.
int PotBuff = 10;   //amount to buffer the vein position before maxexhaust is reached when in pot mode
int ManageRate = ((ExhaustPressure - MaxExhaustPressure)+Rate);

      if (ExhaustPressure < (MaxExhaustPressure-PotBuff)) { DesiredPosition = PotentiometerValue; }
else if (ExhaustPressure >= (MaxExhaustPressure-PotBuff)) {
   DesiredPosition = (PotentiometerValue +(JumpSize * ManageRate));
   DesiredPosition = constrain(DesiredPosition, 0, 970);
}
}


Doesn't have a default value... so things can fall outside of that... yes desired position doesn't change.. but still

And I'm fixing the missing bracketing...
TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

me78569

haha yea I am sure there are syntax issues.  My coding skills haven't been dusted off in well over a decade.

Don't feel like you have to fix the issues, but I will be more than willing to learn from what you do.


My issue however is %100 wiring. 

Time to build a new harness with better quality wires. 
2000 Dodge 2500 quad-cab 5.9 Cummins slt, homebuilt 47re revmax 3.5 messed with vb, Quad adr iquad, 4" tbe , pureflow 150 gph. he351ve in the works 100hp DFI inj

hakcenter

Ok, I'm going to add timers to your code, to really free up crap. And fix your syntax and spacing, its really difficult to read LOL  8)
TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

me78569

Well damn, Guess I need to send you some beer.

My code is kind of like my handwritting, I am about the only person that can read it....
2000 Dodge 2500 quad-cab 5.9 Cummins slt, homebuilt 47re revmax 3.5 messed with vb, Quad adr iquad, 4" tbe , pureflow 150 gph. he351ve in the works 100hp DFI inj

hakcenter

#8
Well now you and I should be able to read it, LOL

I added 2 timers, very similar to how I'm running code.. so make sure you add the Timer library from the libraries post, into your libraries so it will compile.

Might want to backup your current one.. even though it is posted.

LCDUpdate is ran every 200ms from the KeepTime timer,
Setting turbo position, is on its own 2ms timer, so regardless, it sends DesiredPosition to the turbo, so update DesiredPosition as required. (i've already updated your code in the areas so it should be fine)

Your ADCs roll over now, every 1ms from the KeepTime timer, an ADC is read, then next time around another, so the spacing between reads is 4ms, and I updated your rolling averages, to really roll the average, your total was never being reset, and it equaled itself, so very dangerous that way.

The position switches, are read every 100ms from the KeepTime timer. They could be put in faster ? I don't necessarily see the point, maybe 25ms at the fastest, adjust at your discretion.

And of course, all the If's have {}'s and Else's have {}'s, and they all line up to 2 spaces, etc...
TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

Bdubb'z

umhum, very nice improvement indeed!  :o

me78569

looking at it now. 

Thanks again.
2000 Dodge 2500 quad-cab 5.9 Cummins slt, homebuilt 47re revmax 3.5 messed with vb, Quad adr iquad, 4" tbe , pureflow 150 gph. he351ve in the works 100hp DFI inj

me78569

I really like what you did oddly it is VERY hard for me to read code like this haha.   I gotta relearn, but it gives me a good excuse to learn the timer stuff.  I was looking at it but it was lower on my list of things to do.

2000 Dodge 2500 quad-cab 5.9 Cummins slt, homebuilt 47re revmax 3.5 messed with vb, Quad adr iquad, 4" tbe , pureflow 150 gph. he351ve in the works 100hp DFI inj

Bdubb'z

i really like the timed analog read setup....i'm gonna have to 'poll' like that as well.

in the function though i don't see a read twice.  is it not necessary with 'polling' like this?

i'm saying polling, but hac labed it roll over.

the tabbed code is growing on me.  normally you know the code so well its no big deal to scroll, but this may be a little quicker.   i do like seeing the whole thing though, guess i'm just used to it.

me78569

#13

////////////////////////////Keep Time/////////////////////////////////////////
void keep_time() {
  timer++;
  adc_roll_over++;
  // Read Sensors
  // Uncomment the Sensors that you have connected
  // There functions will need to be calibrated to the sensor.
  if (adc_roll_over == 0) { PotentiometerValue = ReadPotentiometer(); }
  if (adc_roll_over == 1) { ExhaustPressure = ReadExhaustPressure(); }   
  if (adc_roll_over == 2) { BoostPressure = ReadBoostPressure(); }
  if (adc_roll_over == 3) { ThrottlePosition = ReadThrottlePosition(); }
  if (adc_roll_over == 4) { adc_roll_over = 0; }
  if (timer % 100) {
    SwitchPosition = digitalRead(Switch);
    EBSwitchPosition = digitalRead(EBSwitch);
  }
  if (timer % 200) { UpdateLCD; }
  if (timer == 1000) { timer = 0; }
}


So reading through this am I on the right track? 

It will effectively run each of these one at a time ( per timer event) then reset adc_roll_over back to 0 and read pot. 

It will only read the switch positions if it has run through it and the timer is at %100?    I am assuming that if the main timer is set to 2ms then 1ms would be %50? 

I think what I am reading show that it resets the timer after 1 second or 1000ms?

Lcd update at %200 or 200 MS? 


My main question is how does the timer know that you are looking for 100ms = %100 ?

Quote from: Bdubb'z on June 12, 2015, 08:31:45 AM
in the function though i don't see a read twice.  is it not necessary with 'polling' like this?

I was wondering the same thing.  I added a double analog read on the TPS and pot


Last question, for now,  I am planning on reading tps from the apps.  Since the apps already has ground and 5v to it from the truck can I splice the return wire and just have that voltage input into the arduino?   Does the arduino care where the 5v supply is from? 

2000 Dodge 2500 quad-cab 5.9 Cummins slt, homebuilt 47re revmax 3.5 messed with vb, Quad adr iquad, 4" tbe , pureflow 150 gph. he351ve in the works 100hp DFI inj

me78569

Timer section had to be changed to this to make it work

////////////////////////////Keep Time/////////////////////////////////////////
void keep_time() {
  timer++;
  adc_roll_over++;
  // Read Sensors
  // Uncomment the Sensors that you have connected
  // There functions will need to be calibrated to the sensor.
  if (adc_roll_over == 1) { PotentiometerValue = ReadPotentiometer(); } //start at 1 vs 0
  if (adc_roll_over == 2) { ExhaustPressure = ReadExhaustPressure(); }   
  if (adc_roll_over == 3) { BoostPressure = ReadBoostPressure(); }
  if (adc_roll_over == 4) { ThrottlePosition = ReadThrottlePosition(); }
  if (adc_roll_over == 5) { adc_roll_over = 0; }
  if (timer % 100) {
    SwitchPosition = digitalRead(Switch);
    EBSwitchPosition = digitalRead(EBSwitch);
  }
  if (timer % 200) { UpdateLCD(); }
  if (timer == 1000) { timer = 0; }
}
2000 Dodge 2500 quad-cab 5.9 Cummins slt, homebuilt 47re revmax 3.5 messed with vb, Quad adr iquad, 4" tbe , pureflow 150 gph. he351ve in the works 100hp DFI inj