analog multiplexer, or arduino MEGA for complete car ECU ??

HELLO forum. i am in the procces , of upgrading my car from carbiratur, to fuel injection... for that propuse, i am planing to build an ECU, with Atmega chips...

for now, i am using an atmega238, to monitor the sensors, that i need to be shown on my speedometer( speed,rpm...), and it sends them to my tablet via USB serial...

the thing is, for, the ACTUAL ecu , i have the following problem... the (analog ) sensors, that need to be monitored, are more than 6... i

dont want to use many Atmega238, connected via serial, cause serial comunication would require too much "wait" time???
(is this correct??)

so , i am left with 2 options... either use and arduino MEGA, wich has enough, inputs, BUT it is way big, and i cant use it so easy, (cause i have to get the whole board)

or use, a Multiplexer !! multiplexer seems fine, but i think it has a minimum time between switching channels?? will this bootleneck the system??

i am in the procces , of upgrading my car from carburetor, to fuel injection... for that purpose, i am planing to build an ECU, with Atmega chips...

Normally, were you question along the lines of "I want to know how..." I would simply not respond, but since you are in-the-process and already have monitoring in place, I will conclude that you know about the dangers associated with high-pressure fuel injection systems and are both competent and capable in this area.

So,

for now, i am using an atmega238, to monitor the sensors, that i need to be shown on my speedometer( speed,rpm...), and it sends them to my tablet via USB serial... the thing is, for, the ACTUAL ecu , i have the following problem...
the (analog ) sensors, that need to be monitored, are more than 6...
i dont want to use many Atmega238, connected via serial, cause serial communication would require too much "wait" time???
(is this correct??)

It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second.

Also, see http://forum.arduino.cc/index.php/topic,6549.0.html on how to improve this some / with caveats.

Since you require more than 6 analog inputs and do not want to chain the uC, you need to find another uC and I suspect you wish to keep it in the Arduino-compatible family. My recommendation is the Atmega1284 40-pin. These are capable chips, have 16K of SRAM, and are easily utilized on homemade circuit boards or protoboards. I would strongly recommend purchasing at least 1 (one) pre-fab board for your development... just to save time and to have a know stable platform. I have 3 of the 1284 boards from CrossRoads, a member of this forum, and I am extremely pleased with the product. Send CrossRoads a PM if you are interested in this option.
Reference all of CrossRoads stuff: Cross Roads Electronics

Ray

PART 2

I worked with an Europa owner to baseline some example code for engine monitoring such as EGT, etc. You may find these links interesting:
http://forum.arduino.cc/index.php?PHPSESSID=ee6fa0dt4oh8m3obl305tt2676&topic=154864.0
http://forum.arduino.cc/index.php?PHPSESSID=af94eun6jsm2rlv29pu6b5ond0&topic=139907.0

The ZIP of the project files for the Europa is too large to post, but if you want 'em, just send me a PM with an email address.

Ray

If the only reason you need a bigger chip is the ADC count (and not more digital pins or code space) you could try connecting one or more external ADCs. Sparkfun sells a middle-of-the-road one here Analog to Digital Converter - MCP3002 - COM-08636 - SparkFun Electronics to give you an idea of how it would work. Despite being an outside chip, it can still be comparatively VERY fast because the ADC inside the Arduinio is quite slow. This chip can read 75,000 samples per second, but that could be moderated by how fast the Arduino can talk to it.

Depending on the application you could also find other ADC chips. Chips with more inputs, higher read frequencies, and much more than 10-bit resolution are certainly available. If you let us know exactly what you are looking at I am sure someone here could help you select one.

A multiplexer would also work, and because analog reads are already quite slow it would not degrade your performance greatly, and as others have mentioned you can go to a bigger chip as well, so you have lots of options. I would weight the budget and needed features and also try to go with the approach I understood the best.

cool. very informative responses!!

so , the way i see it, the Mux will not slow me down, cause the analogread, is anyway TOO slow...
so, why a diferent chip, and not a multiplexer??? the problem with the chip, is that i really want be able to get my hands on it, easy, where i leave....

jroorda! how would i go, using that ADC?? cause it seems like the best option at this time... can u explain to me how it works a bit more??

my application needs are something like this : i need to "Constantly" now the value, of about 10 analog sensors..
then , the chip willl have to make descisions , acording to that values, and calculate 3-4 PWM outpouts....
the thing is, that the engine can RUN up to 8000RPM , wich gives little time, for calculations, and value upgrades... the (if the read time is so big . the engine will do MANY cycles, before the critical sensor values are upgraded... )

EDIT: the cost is not THE problem... the problem is, i want to be able to tottaly understand what i will be using.... so, why not use the arduino MEGA, then??

8000 rpm, is only 133Hz which is fairly slow electrically speaking. It depends on how many times per revolution you need to read the sensors. Even with 10 sensors you should be able to keep up with 1 read per revolution, but the rest of the code will need to be fast, but I see no reason why it couldn't be. If one read per rev. (or possibly more) is good with you the Mega is the simplest off the shelf solution.

An ADC chip is just an external analog to digital converter, not unlike the one built into the Arduino that enables the Arduino's analog inputs. ADC's are quite common and you should be able to buy them from an online vendor regardless of where you live. This is a global forum, so I won't suggest any specific vendor's until I know what part of the world we are talking about, but one shouldn't be too hard to find.

To use an external ADC you would need to route the analog signals, along with power and ground to the ADC chip. Then you would use a digital communications bus like SPI, I2C, or Serial to talk to the chip and read the analog values. There are some libraries that make coding this interaction easy, and this communication can happen quite rapidly because it is all digital.

All in all, I would probably go with the Mega for now because of its simplicity. If it turns out to be too slow you can look at adding an external ADC later.

To use an external ADC you would need to route the analog signals, along with power and ground to the ADC chip.

Unless your need in sensors take you to thermocouples. In that case, you will need to engineer completely differently than an analog device such as a photoelectric cell or thermistor.

Thermocouples are very sensitive, requiring a good amplifier with a cold-compensation reference.

The above is absolutely required for EGT use. There are other IC's out in the market that can also do a great job depending on the specific thermocouple you utilize (yea, the chip and thermocouple materials must be matched.)

... and some may suggest doing the compensation in software... yea, just because something "can" be done does not mean that it "should" be done.

Ray

cool. so, for the "best" solution , i should go with ADC (since in overall , an UNO and an ADC will take up less space and be more faster and more robust)

and the Mega solution, is ok as well. Mux seems to be out of the picture..
i will anyway need to do allot of research, both on the software needed for the ECU, and on how to work the ADC :wink: thanks allot!!

so, for the "best" solution

Well, do this. Use a spreadsheet or notebook paper and start identifying your needs...

  • Some digital I/O
  • Some Analog input

Which will use internal A/D
Which will use external A/D. For these, how will you address the chip... SPI or I2C?

Know your entire group of sensors. Put those in and map them to I/O.

When you finish, the best solution will not be a guess.

I simply like the Mega2560 because of the extra SRAM. It is easily worth the under $20 U.S. price from China.

But, I have always recommended that beginners and experts have at least one real Arduino in each class that they utilize; that is, a real UNO or a real MEGA, etc. This way, you will never have to try and decide if the problem you are having is a hardware related one. Then when the prototype is finished, move the software to the clone and it should work If your software works on a real Arduino but not on a clone... well, you know where the problem is located!!!

Ray

Example - my Notes in the file notes.h which I keep with the project code. The first part is notes about pin usage.

/*
Input and Output

Each of the 54 digital pins on the Mega can be used as an input or output, 
using pinMode(), digitalWrite(), and digitalRead() functions. They operate at 5 volts. 
Each pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor 
(disconnected by default) of 20-50 kOhms. In addition, some pins have specialized functions:

    Serial: 0 (RX) and 1 (TX); Pins 0 and 1 are also connected to the corresponding pins of the ATmega16U2 USB-to-TTL Serial chip.
    Serial 1: 19 (RX) and 18 (TX); 
    Serial 2: 17 (RX) and 16 (TX); 
    Serial 3: 15 (RX) and 14 (TX). Used to receive (RX) and transmit (TX) TTL serial data. 

    External Interrupts: 2 (interrupt 0), 3 (interrupt 1), 18 (interrupt 5), 19 (interrupt 4), 
    20 (interrupt 3), and 21 (interrupt 2). These pins can be configured to trigger an interrupt on a low value, 
    a rising or falling edge, or a change in value. See the attachInterrupt() function for details.

    PWM: 2 to 13 and 44 to 46. Provide 8-bit PWM output with the analogWrite() function.

    SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS). These pins support SPI communication using the SPI library. 
    The SPI pins are also broken out on the ICSP header, which is physically compatible with the Uno, Duemilanove and Diecimila.

    LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH value, 
    the LED is on, when the pin is LOW, it's off.

    TWI: 20 (SDA) and 21 (SCL). Support TWI communication using the Wire library. 
    Note that these pins are not in the same location as the TWI pins on the Duemilanove or Diecimila. 

The Mega2560 has 16 analog inputs, each of which provide 10 bits of resolution (i.e. 1024 different values). 
By default they measure from ground to 5 volts, though is it possible to change the upper end of their range 
using the AREF pin and analogReference() function.

There are a couple of other pins on the board:

    AREF. Reference voltage for the analog inputs. Used with analogReference().

    Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset button to shields which block the one on the board. 

Communication

The Arduino Mega2560 has a number of facilities for communicating with a computer, another Arduino, or other microcontrollers. 
The ATmega2560 provides four hardware UARTs for TTL (5V) serial communication. 
An ATmega16U2 (ATmega 8U2 on the revision 1 and revision 2 boards) on the board channels one of these over USB and provides a 
virtual com port to software on the computer (Windows machines will need a .inf file, but OSX and Linux machines will recognize 
the board as a COM port automatically. The Arduino software includes a serial monitor which allows simple textual data to be sent 
to and from the board. The RX and TX LEDs on the board will flash when data is being transmitted via the ATmega8U2/ATmega16U2 chip 
and USB connection to the computer (but not for serial communication on pins 0 and 1).

A SoftwareSerial library allows for serial communication on any of the Mega2560's digital pins.

The ATmega2560 also supports TWI and SPI communication. The Arduino software includes a Wire library to simplify use of the TWI bus; 
see the documentation for details. For SPI communication, use the SPI library. 
_______________________________________________DISPLAY Format _________________________________________________________________
1 2 3    4 5 6 7 8 9 1 1 1 1 1 1 1
                     0 1 2 3 4 5 6
Fuel       Oil     CHT     EGT
Remaining  Temp    Front   Left
X X X      X X X   X X X   X X X X
X X X      X X X   X X X   X X X X
Water      Oil     CHT     EGT
Temp       Pres    Rear    Right
1 2 3    4 5 6 7 8 9 1 1 1 1 1 1 1
                     0 1 2 3 4 5 6
_______________________________________________ AXE133Y OLED _________________________________________________________________
http://arduino.cc/playground/Main/AXE133Y
 
AXE133Y library for Arduino
by SmudgerD - May 2012 - www.stompville.co.uk
Functions

        writeByte()        Ex: OLED.writeByte(244); //display a Greek capital Omega character (Ohms)
        splash()           This function clears the display and shows the library version on the top line
        displayShow()      Ex: OLED.displayShow(false); //hide (turns off) the display
        cursorShow()       Ex: OLED.cursorShow(true); //shows the cursor
        cursorBlink()      Ex: OLED.cursorBlink(true); //shows the cursor and makes it blink 
                               OLED.cursorBlink(false); //shows a solid cursor
        clearScreen()      Ex: OLED.clearScreen();  //clear screen, home cursor and switch off cursor
        cursorHome()       Ex: OLED.cursorHome(1);  //move cursor to cursor position 0 on line 1
        cursorLeft()       Ex: OLED.cursorLeft(3); //move cursor three positions to the left
        cursorRight()      Ex: OLED.cursorRight(2); //move cursor two character to the right
        cursorPosition()   Ex: OLED.cursorPosition(2,0); //move the cursor to the first position on the second line
                               OLED.cursorPosition(1,64); //this has the same effect as the example above
        printMessage()     Ex: OLED.printMessage(1); //this will display the message "www.picaxe.com"
        print()            Ex: OLED.print("Hello World!");
                           Ex: OLED.print(String(charArray));
        outputWrite()      Ex: OLED.outputWrite(0b111); //sets all outputs high
                               OLED.outputWrite(0b100); //sets output C.2 high and the others low
                                      int currentStatus = 0b000;
                               OLED.outputWrite(currentStatus); //all outputs low/off
                                      currentStatus != 0b010; //set C.1 to one
                               OLED.outputWrite(currentStatus); //currentStatus = 0b010
                                      currentStatus != 0b001; //set C.0 to one
                               OLED.outputWrite(currentStatus); //currentStatus = 0b011
                                      currentStatus &=0b110; //set C.0 to zero
                               OLED.outputWrite(currentStatus); //currentStatus = 0b010
                                      currentStatus ^=0b100; //toggle C.2
                               OLED.outputWrite(currentStatus); //currentStatus = 0b110
        backspace()        Ex: OLED.backspace(3); //backspace three chars
        printFloat()       Ex: OLED.printFloat(3.14159,5,4); //this will display "3.14156"
                               OLED.printFloat(3.14,4,1);    //this will display " 3.1"
                               OLED.printFloat(3.14e6,5,0); //this will display "3140000"

_______________________________________________ Log File on USB/Comm: _________________________________________________________________
Europa Instruments coming online...
3:45:20  12/31/12
Exhaust Gas #1 Temp = 21.81
EG1=69
Exhaust Gas #2 Temp = 22.00
EG2=70
CHT1 (analog): 544
CHT #1 Temp = 68
CHT #1 Temp = 68
CHT2 (analog): 377
CHT #2 Temp = 68
Gasoline (analog): 367
GFL = 255
Oil Temp (analog): 364
Oil Temp = 255
Water Temp (analog): 355
Water Temp = 255
Oil Pressure (analog): 355
Oil Pressure = 255
Free RAM = 6065

IR keycode received: 80
Menu request received on IR link
Serial receive buffer 1 cleared
Entering DS1307 set menu
Day Of Month has been set to: 6
Month has been set to: 1
Year has been set to: 13

3:45:54  1/6/13

IR keycode received: 80
Menu request received on IR link
Serial receive buffer 1 cleared
Entering DS1307 set menu
Seconds have been set to: 40
Minutes have been set to: 34
Hours have been set to: 8


(repeat...)


// DS1307 Clock stuff 

  // Stops the DS1307, but it has the side effect of setting seconds to 0
  // Probably only want to use this for testing
  void stopDs1307()
  {
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0);
  Wire.write(0x80);
  Wire.endTransmission();
  }

*/

yiap! i will do this. but it will take some time :smiley: thanks allot for the help!!

yiap! i will do this. but it will take some time smiley-grin

I have been doing software since 1973 and I can promise you, time spent planning before coding is always time well spent.

Ray

You never said exactly how many ADC channels you need but it it's less than 12 and you were worried about speed, for $50 you could upgrade to a DUE. You know you won't have speed issues with that, and if you don't need more than 12 analog inputs, you would be OK. If you are trusting, the Freaduino Due gives you 15 analog inputs. The 16th is an internal temp sensor. The only caveat is all of the DUE's are 3.3V boards but the car is 12V anyway, so whatever you want to drive with the Due would need a relay or MOSFET to up the voltage.

well, i cant know exactlu how many inputs and outpouts i need, before i do expensive research, (and before i have my actaull injection system in the car). but thank you very much for pointing DUE out. IF 12 analog inputs are enough, the, i dont see a reason why i should choose, MEGA, over DUE?? as i see, DUE ,will forgie my crapy code (as i am no pro, and it wont be efficient... )

3.3V, are indeed not a probelm, since the car anyway has 12 volt...
any change that DUE, will be more fragile, than MEGA? (since it has ARM??)

the number of analog pins, also , depend, on how am i going to read some signals... for instance , the speed, and RPM sensors, are normal hall effect sensors. so the one way to read them, would be to use Attach Interupt. (that is what i do on the diagnostic part)...
what would be more fasteR???
coverting the hall efect digital, to analog, (using an ATTINY perhaps??) and then using AnalogRead?
or just use Interupts???

[edit] : well crap. i just saw, that it can onlhy supply up to 15mA from each pin... which can be enough, but it makes the design harder... :confused: