HE351 code for 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 yourHE351VE Variable Geometry Turbo. The whole program iscontrolled through void loop(). This is where you canadd your own code or uncomment different sections of codethat I have put together. This is covered by the GNU License*/

#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-960int 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.

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}

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

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

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

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

}

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

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

//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*/

#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-960int 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.

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

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

}

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

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

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...

Logged

AMP2 Corinthians 8:21For we take thought beforehand and aim to be honest and absolutely above suspicion, not only in the sight of the Lord but also in the sight of men.

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.

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?