AVR + Throttle body control

Go To Last Post
23 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello!

I have throttle body with DC motor inside.

I write some code and i can control of position throttle.

Here is video with work.

Now i use only one MOSFET for PWM.
And code for Arduino Nano:

#include 

// Layout
const int tankLevelSensor = 0; // Must be AIN
const int potSensor = 1; // Must be AIN
const int tankFillerOutput = 3; // must be PWM

//Variables
double setPoint;
double tankLevel, tankFill, potLevel;
// setPoint - the value we want our level to be.
// tankLevel - the 10 bit value of our actual tank level
// tankFill - the inflow level into the tank.

// Tuning parameters
const double Kp=5;
const double Ki=0;
const double Kd=0;

double aggKp=1, aggKi=0.2, aggKd=1;

//Load a new PID controller
PID myPID(&tankLevel, &tankFill, &setPoint, Kp, Ki, Kd, DIRECT);
const long sampleRate = 5;
// How frequently to run the PID control?

// Communication setup
const long serialPing = 500;
// Serial pingback interval in milliseconds
unsigned long now = 0;
// placehodler for current timestamp
unsigned long lastMessage = 0;
// last message timestamp.

void setup()
{
  Serial.begin(9600);
  // Open a communication channel from the Arduino
  // back to the computer over USB.
 
  //initialize the variables we're linked to
  tankLevel = analogRead(tankLevelSensor);

  //turn the PID on
  myPID.SetMode(AUTOMATIC);
  myPID.SetSampleTime(sampleRate);
 
  Serial.println("Begin"); // Hello World!
  lastMessage = millis(); // timestamp
}

void loop()
{
  tankLevel = analogRead(tankLevelSensor);
  setPoint = map(analogRead(potSensor), 0, 1023, 325, 800);
 
  double gap = abs(setPoint-tankLevel); //distance away from setpoint
  if(gap>10)
  {  //we're close to setpoint, use conservative tuning parameters
    myPID.SetTunings(Kp, Ki, Kd);
  }
  else
  {
     //we're far from setpoint, use aggressive tuning parameters
     myPID.SetTunings(aggKp, aggKi, aggKd);
  }
 
  myPID.Compute(); // this function updates the control action.
  // It reads tankLevel, and stores the output in tankFill
  analogWrite(tankFillerOutput, tankFill);
 
  now = millis();
  if(now - lastMessage > serialPing) {
    // this should execute less frequently
    // send a message back to the mother ship
    Serial.print("Setpoint = ");
    Serial.print(setPoint);
    Serial.print(" Tank Level = ");
    Serial.print(tankLevel);
    Serial.print(" Fill Rate = ");
    Serial.print(tankFill);
    Serial.print("\n");
   
    lastMessage = now;
    //update the time stamp.
  }
 
}

I wanna use H-bridge MC33931 desolded from my broken car ECU.

If i understand - ECU from car control it in 2 directions: opening and closing. In my current solution - throttle body closing only by internal spring. But in real world in car - ECU close it via inverting polarity of current.
And second problem is - hold throttle in needed position without trembling.

Tnx for reply and sorry for my bad english.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You've chosen a rather difficult project for your skill level. The code you've shown doesn't seem to relate to throttle control, but it is a start. You would want to chose something closer to what you want as in a dc servo. Then the fun part is tweaking the pid values to suit so you don't get the trembling.

The throttle control is a critical safety system. Using this on a real car with an arduino is not a good idea as it might cause you to randomly accelerate. Toyota supposedly had this problem.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Electronic throttles seem to be quite difficult to get right.

Volvo has used or still use an electronic throttle body made by Marelli. The build quality of these ETMs is order of magnitudes better than an Arduino. Ceramic board construction and the like to cope with the underbonnet environmental harshness.

The main problem with this module is that they used two mechanical feedback potmeters. The carbon tracks wear out causing erratic behaviour. There are aftermarket modification kits available that replace the potmeters with contactles Hall encoders.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thx for reply!

I know that is very risky job.
But i wanna try.

For example, Arduino is for prototype.
Later i will write code with avr-gcc and watchdog.

And my project is car for a drag.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It will need more than avr-gcc and a watchdog! Regardless, even if it is for a drag race, a stuck throttle is not fun and has seriously injured or killed many a person. Realistically, even if we gave you the code, you're going to have to tune it and understand it. Try starting with using pwm and getting it to move forward and backward. Then apply the pid control.

You might want to use the correct words 'want to' rather the 'wanna'. 'wanna' is considered to be a rather lazy way of speaking. There's also 'gunna'.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

acabby wrote:
... my project is car for a drag.
Hmm, like this?

Attachment(s): 

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
It will need more than avr-gcc and a watchdog! Regardless, even if it is for a drag race, a stuck throttle is not fun and has seriously injured or killed many a person. Realistically, even if we gave you the code, you're going to have to tune it and understand it. Try starting with using pwm and getting it to move forward and backward. Then apply the pid control.

You might want to use the correct words 'want to' rather the 'wanna'. 'wanna' is considered to be a rather lazy way of speaking. There's also 'gunna'.

Tnx for good reply!

I want to understand how to this work.
Yep, if somebody can help me, i will tune and understand it. May be - i can do working prototype.

I didnt want follow lazy way. I just want to know more and write good code, but i didnt can understand about working algoritm.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think you need more than a simple PID algorithm. I'm fairly sure there are several patents on these kind of ETMs, so it should be very interesting to dig them up and see what algorithms they use.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think regular old proportional control even will be ok. I'd wire up the pots so one goes up in volts and the other goes down, read both of them, average the last 8 or 16 readings, add em up and see if its half scale. If not, they might be out of sync. Go to limp mode using the one that still works.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
I think regular old proportional control even will be ok. I'd wire up the pots so one goes up in volts and the other goes down, read both of them, average the last 8 or 16 readings, add em up and see if its half scale. If not, they might be out of sync. Go to limp mode using the one that still works.

Can you explain me more?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tried a bit of deadband?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Vehicle electronics and software...

Timing is everything. Just yesterday I had a bit of a scary interaction with my car's computers.

I was a little bit behind schedule leaving for work so I was in a bit of a hurry. I made a bit of a high speed left turn onto an entrance ramp for an interstate road, (4 lanes, divide with a central median). I did a bit of a drift in the turn and all of a sudden lots of beepers started beeping and buzzers started buzzing and idiot lights started flashing.

I accelerated out of the drift and then accelerated further to get ahead of an 18-wheeler as I merged with traffic on the interstated, now going about 75 mph, (120 kph).

I look down and the Idiot light says "BRAKE" and the LCD panel says BRAKE, Check Brake System, Have your vehicle checked by a dealer immediately!

It alternates with Check ABS system, and Check VSC system, (I still don't know what the VSC system is.).

I have visions of tapping the brakes lightly and having one side lock up while the other side fails to engage, precipitating a high speed turn and roll over.

Fortunately, obviously, that wasn't the system's response, or I wouldn't be here to post the photo and comment on the fact that vehicle firmware requires extensive testing and validation, and then some more testing and more validation, ...

JC

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Vehicle Stability Control(VSC). Maybe it got upset that you drifted an AWD vehicle?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That makes sense.

Hard to imagine that I'm the first to do this, or that it got the system so upset.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, those kinds of systems probably have more code dedicated to run time diagnostics and plausibility checks then to run the actual algorithms. And dual microprocessors that continually check each other.

On the slightest sign of possible failure they shut down.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have custom turbo engine and i know what to do 8)

Can we close discussion about risk of electronic throttle control? I wanna try, i wanna use it and test, without errors we didnt get result.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well you wanna do some research then!

http://www.ladyada.net/make/mshi...

http://www.openservo.com/

That took me less time than it took me to write this response.

Believe me - you will shit your pants when you get a stuck open throttle. Jesus will be waving at you. At thatp oint you better know how to hit the kill switch. I've had frozen carburettor slides on a number of occasions. I've also had engines seize. They always stop when you back off! This is on 400bhp/litre normally aspirated engines.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I have throttle body with DC motor inside.

There are several members of the Forum with extensive engine control experience. I'm not one of them.

Perhaps "DC motor" tells Kartman all he needs to know about your hardware. Me, I'm left wondering is the controller a stepper motor, Servo, solenoid, plunger on a vacuum control, etc.

More information, such as a data sheet for the controller, and perhaps an image of it, would be helpful before anyone can provide any more information on connecting your H-bridge to the device.

Using the Search on the Forum will also bring up other Threads discussing H-bridge control and interfacing, which may be useful.

Lastly, the various comments above, by myself and others, weren't made to derail your Thread. They were aimed at making you truly aware that the project you are undertaking has significant risks involving injury or death to youself, and to those around you.

The need for backup systems, manual and preferably automated emergency disconnects, redundancy, and extensive testing and validation as well as other fail-safe systems would seem to apply to your project.

Doing projects is a great way to learn. It is just that people here do not want you to become a Darwin Awards winner in the process of working on your project.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Doc, the throttle bodies i've seen consist of a dc motor, gear train, a clock spring and two potentiometers working opposite. The spring is a failsafe to close the throttle. The dual pots are for redundancy as the output on one increases as the output on the other decreases so you should be able to detect a failure. The driver chips are designed so that they wont magically fail keeping the throttle open.

Acabby - to get your servo system working is relatively easy. Getting it to work reliably on the engine is the challenge. There's heat, vibration and significant electrical interference. Don't let the apparent simplicity fool you.

I thought electronic controls were outlawed in the major forms of drag racing. It's too easy to have the computer do all the work and the driver is just ballast.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

:( ....

Last Edited: Fri. May 31, 2013 - 09:46 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hopefully you wont be driving near me. The easy part is getting it to work. The hard part is getting it to work reliably. What happens if the micro decides it doesn't want to play nice one day? Never expect the micro to behave 100% of the time.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmm, the last pjt. poster isn't the OP, so there are at least 2 of you working on this ( Or it may be the OP with a new name... ). You guys are microsquirtin' down the road using a very simple implementation...and fantastic results... :roll: and the rest of you guys were worried !!

I'll bet there's no protection of the circuit from all the harshness of the environment and auto ( You really think you've duplicated the efforts of auto engineers in 3 months being raw rookies in auto-electronics ?!! )! F@!@# nuts... :?

What's up Doc JC ? Did your systems auto-clear or did you have to take it in to get a panel reset ?

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This might be a great time to summarize with several bullets how to build a board to be used in cars. Obviously, Automotive temperature range components, Coating the board to keep condensation from zapping everything, the 12V in needs those 60V transzorbs to eat a load dump if some doofus takes the battery loose with the alternator running, What kind of Rs and Cs are good in cars? Design to fail safe is important. Don't want it to lock up at full throttle.

Imagecraft compiler user