ECUs and Tuning Discuss Engine Management, Tuning, & Programming

Arduino as ECU?

Thread Tools
 
Search this Thread
 
Old 10-20-2010, 11:42 PM
  #141  
Junior Member
Thread Starter
iTrader: (3)
 
ctxspy's Avatar
 
Join Date: Jun 2008
Location: NJ
Posts: 428
Total Cats: 0
Default

Originally Posted by bloodline
Byte sequence: 33 83 77 xx xx xx xx 04 - Sets the mixture value, the "xx xx xx xx" represents the 4byte (32bit long signed) injector open time in microseconds against the factory setting.
I'm confused by this one.. what do you mean by injector open time? are you using the 2D array for lookup of fuel value, or are you still using the 1 value as a test for now?

I started putting together a program in C#.. once it does something i'll compile it and send it over to you for testing.

Tomaj
ctxspy is offline  
Old 10-21-2010, 03:32 AM
  #142  
Junior Member
 
bloodline's Avatar
 
Join Date: Sep 2010
Location: London, England
Posts: 91
Total Cats: 0
Default

Originally Posted by ctxspy
I'm confused by this one.. what do you mean by injector open time? are you using the 2D array for lookup of fuel value, or are you still using the 1 value as a test for now?
Like most of the spec at this stage, this command might change

But regardless of the the fuel calculation (I will explain what I'm using as a test shortly), the end result is that the amount of fuel in the engine is determined by how long the injectors are open. Now the ECU will try to open the injectors for just the right amount of time to get the right amount of fuel in the engine for complete combustion (too little fuel and we start forming nitrous oxide, too much fuel and unburnt hydrocarbons get in to the exhaust). This command simply adds or subtracts the requested amount of microseconds from whatever the ECU has worked out that the injectors need to be open for... If you write a value of 1000, the injectors will be open for an extra millisecond (on top of what the ECU thinks should be) so the mixture will be rich, if you write a value of -2500, the injectors will be opened for 2.5milliseconds less than the ECU has worked out and the mixture will be lean. This is a gross adjustment and is basically like the choke on a carburettor


My fueling code at the moment assumes no loading on the engine, since it still hasn't been tested in a real engine, it is safe to say it's not going to be put in a car and driven around. This means the injector open time is a linear function of the AFM open amount (I.e. The amount of air introduced into the manifold).
So if the AFM is reading 0 volts, the injectors are open for 0 microseconds, if the AFM is reading 5volts (maximum air intake), the injectors are open for 12000microseconds (90% duty cycle at 8000RPM). It is a very simple way to do it, but should be sufficient for testing.
I started putting together a program in C#.. once it does something i'll compile it and send it over to you for testing.

Tomaj
That would be brilliant! I'll have to find a Windows machine to test it with (actually I think I have XP installed on bootcamp on my MacBook).
bloodline is offline  
Old 10-21-2010, 07:09 PM
  #143  
Junior Member
Thread Starter
iTrader: (3)
 
ctxspy's Avatar
 
Join Date: Jun 2008
Location: NJ
Posts: 428
Total Cats: 0
Default

there's monomac... since this is a simple program porting may be easy. I also may look into doing this in java (But i hate programming in java, i can't get around to liking eclipse. any better simple IDEs?)

about the fueling "delta", i dont mean to be harsh but i don't see the value in that, may as well just leave that off until we can get the full 2D lookup working.

Also regarding AFM, i think most people around here are going to be using a MAP sensor. With the MS the MAP sensor is built into the unit, but for the arduino i guess we'll need an external one. Either way, the concept is the same (i think), higher voltage = higher pressure / more air.
ctxspy is offline  
Old 10-21-2010, 08:26 PM
  #144  
Junior Member
Thread Starter
iTrader: (3)
 
ctxspy's Avatar
 
Join Date: Jun 2008
Location: NJ
Posts: 428
Total Cats: 0
Default

OK the 1st version of "Arduiciu" is ready, it basically lists the serial ports available on the computer, lists common port speeds, allows you to open the serial port, has several non functioning buttons, and one button the "Get ECU status", which hypothetically will work.

I've uploaded it in a zip file, let me know if it works.
Attached Files
File Type: zip
Arduicu.zip (4.8 KB, 269 views)
ctxspy is offline  
Old 10-22-2010, 07:24 PM
  #145  
Junior Member
 
bloodline's Avatar
 
Join Date: Sep 2010
Location: London, England
Posts: 91
Total Cats: 0
Default

Originally Posted by ctxspy
there's monomac... since this is a simple program porting may be easy. I also may look into doing this in java (But i hate programming in java, i can't get around to liking eclipse. any better simple IDEs?)
I also dislike Java, I grew up on 68k Asm and C, used C++ for a few years and then after a lot of effort finally figured out Objective-C... And I tend to stick with Obj-C now... Though for low-level work C++ is better suited

about the fueling "delta", i dont mean to be harsh but i don't see the value in that, may as well just leave that off until we can get the full 2D lookup working.
For development we do need to be able to adjust all the settings, I agree that a working system should have no use for this parameter.

Also regarding AFM, i think most people around here are going to be using a MAP sensor. With the MS the MAP sensor is built into the unit, but for the arduino i guess we'll need an external one. Either way, the concept is the same (i think), higher voltage = higher pressure / more air.
As I said before, I don't want to get carried away... First goal is to make a plugin replacement for the factory ECU. Once it works, then changing the code to support the MAP sensor over the AFM, should be as simple as wiring the MAP in place of the AFM and the loading the correct pressure/fuel map in
bloodline is offline  
Old 10-22-2010, 07:26 PM
  #146  
Junior Member
 
bloodline's Avatar
 
Join Date: Sep 2010
Location: London, England
Posts: 91
Total Cats: 0
Default

Originally Posted by ctxspy
OK the 1st version of "Arduiciu" is ready, it basically lists the serial ports available on the computer, lists common port speeds, allows you to open the serial port, has several non functioning buttons, and one button the "Get ECU status", which hypothetically will work.

I've uploaded it in a zip file, let me know if it works.
Brilliant! I'll give this a go this weekend

Really excited!!!
bloodline is offline  
Old 10-22-2010, 10:30 PM
  #147  
Junior Member
Thread Starter
iTrader: (3)
 
ctxspy's Avatar
 
Join Date: Jun 2008
Location: NJ
Posts: 428
Total Cats: 0
Default

I've updated the code, it now implements all the messages defined thus far.

I've also zipped up the source code as well. The executable is in the bin/debug directory.
Attached Files
File Type: zip
Arduicu-0.0.1.zip (35.3 KB, 284 views)
ctxspy is offline  
Old 10-23-2010, 07:39 AM
  #148  
Junior Member
 
bloodline's Avatar
 
Join Date: Sep 2010
Location: London, England
Posts: 91
Total Cats: 0
Default

Originally Posted by ctxspy
I've updated the code, it now implements all the messages defined thus far.

I've also zipped up the source code as well. The executable is in the bin/debug directory.
Awesome stuff, I'm away from the keyboard today (taking the girlfriend shopping)... So I can't test anything, but I will need to define and implement the data feed. This your program will request the data, and the ECU will respond with a data structure containing all the current system setting and information, this way your app will be able to send out periodic requests (say every 50milliseconds) and be able to update that freedback to the user (perhaps with some nice gauges and dials, as I'm
Planning for the macos version)
bloodline is offline  
Old 10-25-2010, 02:48 PM
  #149  
Junior Member
 
bloodline's Avatar
 
Join Date: Sep 2010
Location: London, England
Posts: 91
Total Cats: 0
Default

Originally Posted by ctxspy
I've updated the code, it now implements all the messages defined thus far.

I've also zipped up the source code as well. The executable is in the bin/debug directory.
Seems to work! Connected to COM3 at 115200 Hopefully I'l get more time to work on my end of this soon!
bloodline is offline  
Old 10-25-2010, 06:51 PM
  #150  
Junior Member
Thread Starter
iTrader: (3)
 
ctxspy's Avatar
 
Join Date: Jun 2008
Location: NJ
Posts: 428
Total Cats: 0
Default

excellent. Now give me a datafeed and i can start playing around!

I'll need to get an arduino i think so i can really play w/the ECU source too.. How hard is it to get that side working?
ctxspy is offline  
Old 10-26-2010, 03:17 AM
  #151  
Junior Member
 
bloodline's Avatar
 
Join Date: Sep 2010
Location: London, England
Posts: 91
Total Cats: 0
Default

Originally Posted by ctxspy
excellent. Now give me a datafeed and i can start playing around!
Coming up ASAP!

I'll need to get an arduino i think so i can really play w/the ECU source too.. How hard is it to get that side working?
As the thread starter, I'm actually surprised you don't have one already

Very simple to get going. Buy the Arduino Uno, download the Arduino software (you can do this first if you prefer), copy and paste my ECU code into te Arduino IDE, plug Uno into your computer, hit upload... Done

This has to be the simplest way to get into Microcontroller development.

A word of warning, my code does require a CAS signal to run, otherwise it will just wait at the sync section of code. If you have a real CAS you can connect up then that would be perfect... Or you could use a second microcontroller to generate the CAS signal as I currently do.

Last edited by bloodline; 10-26-2010 at 03:35 AM.
bloodline is offline  
Old 10-27-2010, 11:16 PM
  #152  
Junior Member
Thread Starter
iTrader: (3)
 
ctxspy's Avatar
 
Join Date: Jun 2008
Location: NJ
Posts: 428
Total Cats: 0
Default

I found this (among others).. Apparently by searching for "arduino piggyback" and other terms i was able to find other interesting projects.

http://thedeltaecho.wordpress.com/20...ublic-release/

It seems there are a few people out there already experimenting with arduinos as ECUs in various forms.

I've e-mailed the guy working on this project to see how he's doing and whether he thinks there's any possibility of making a more generic system.

Tomaj
ctxspy is offline  
Old 10-28-2010, 07:36 AM
  #153  
Junior Member
 
bloodline's Avatar
 
Join Date: Sep 2010
Location: London, England
Posts: 91
Total Cats: 0
Default

Originally Posted by ctxspy
I found this (among others).. Apparently by searching for "arduino piggyback" and other terms i was able to find other interesting projects.

http://thedeltaecho.wordpress.com/20...ublic-release/

It seems there are a few people out there already experimenting with arduinos as ECUs in various forms.

I've e-mailed the guy working on this project to see how he's doing and whether he thinks there's any possibility of making a more generic system.

Tomaj

Wow, I never managed to find any arduino ECU projects, my google skills are weak

This guy seems to be quite far ahead already, I will make sure his licence is compatible with mine and then read over his code.

I've already started my v0.6 codebase (only plotted on paper at the moment) with yet another significant change, moving away from the "busy wait" that I used to sync in the v0.5 code, to using interrupts. This will make my serial code work better, at the moment is isn't really working very well at all... It seems to be crashing your app now :(

-Edit- If you want to get into Arduino devlopment, I notice that you can get cheap Arduino clones on EBay, the "Seeduino" seems to get good reviews too (make sure you get one with the AVRMega328 CPU and running at 16Mhz, or my code won't work)
bloodline is offline  
Old 10-28-2010, 09:45 AM
  #154  
Newb
 
Mitch_1979's Avatar
 
Join Date: Oct 2010
Posts: 4
Total Cats: 0
Default

Hello Miata enthusiasts...

I'm the author of the 2JZduino project and theDeltaEcho wordpress site linked to above.
ctxspy send me an e-mail to bring my attention here.

In brief, I've had preliminary success running an Arduino-based project as a piggyback on a 2JZ-GE (the 3L inline 6 used in the Lexus IS300, Toyota Altezza, Toyota Supra [non turbo]). It currently intercepts and delays crank sensor pulses (delays ignition timing), intercepts and scales injector signals (fuel mixture), and simulates narrowband O2 sensor output based on wideband O2 sensor input (programmable closed-loop AFR).

For more info I'll defer to my blog for now.

Anyway, if it turns out there is a project here to develop a more advanced Arduino-ECU I'd be happy to be involved in any way that's helpful.

I'll admit I haven't had time to read this thread in detail (just quickly perused it) but I will do that later today.

-Mitch

[Edit: P.S. I did see some early discussion in this thread about whether an Arduino was fast enough to handle engine control... this analysis and simulation was an early part of my work for 2JZDuino. See here...
http://thedeltaecho.wordpress.com/20...or-capability/ ]

Last edited by Mitch_1979; 10-28-2010 at 09:48 AM. Reason: P.S. added
Mitch_1979 is offline  
Old 10-30-2010, 08:29 AM
  #155  
Junior Member
 
bloodline's Avatar
 
Join Date: Sep 2010
Location: London, England
Posts: 91
Total Cats: 0
Default

Originally Posted by Mitch_1979
Hello Miata enthusiasts...

I'm the author of the 2JZduino project and theDeltaEcho wordpress site linked to above.
ctxspy send me an e-mail to bring my attention here.

In brief, I've had preliminary success running an Arduino-based project as a piggyback on a 2JZ-GE (the 3L inline 6 used in the Lexus IS300, Toyota Altezza, Toyota Supra [non turbo]). It currently intercepts and delays crank sensor pulses (delays ignition timing), intercepts and scales injector signals (fuel mixture), and simulates narrowband O2 sensor output based on wideband O2 sensor input (programmable closed-loop AFR).

For more info I'll defer to my blog for now.

Anyway, if it turns out there is a project here to develop a more advanced Arduino-ECU I'd be happy to be involved in any way that's helpful.

I'll admit I haven't had time to read this thread in detail (just quickly perused it) but I will do that later today.

-Mitch

[Edit: P.S. I did see some early discussion in this thread about whether an Arduino was fast enough to handle engine control... this analysis and simulation was an early part of my work for 2JZDuino. See here...
http://thedeltaecho.wordpress.com/20...or-capability/ ]
Hi Mitch,

I have been working on this Arduino ECU project for a while, the this thread is getting a bit large and unfriendly. But I have got quite far now, you can find my latest code at sourceforge, under the project title of MiataBrain

I had a few obstacles to overcome using the Arduino, but I think I have solved all the major issues with the time critical and structural components of the code.

All that needs to be added now is the fuel calculation/table, I'm using a linear advance (that follows the factory settings) on the spark timing for now... but that can easily be replaced.

The two functions that need to be completed are (and really need to be tested in a real engine to get right):

sparkTime() // which returns the advance based on the engine state.
setInjFlowTime() // which returns the time the injector needs to be open based on the engine state.

I know that you are not working on a Mazda MX5, but you might be able to adapt the code, though it is hardcoded to the MX5 CAS...
bloodline is offline  
Old 10-30-2010, 09:54 AM
  #156  
Junior Member
 
bloodline's Avatar
 
Join Date: Sep 2010
Location: London, England
Posts: 91
Total Cats: 0
Default

Originally Posted by ctxspy
I found this (among others).. Apparently by searching for "arduino piggyback" and other terms i was able to find other interesting projects.

http://thedeltaecho.wordpress.com/20...ublic-release/

It seems there are a few people out there already experimenting with arduinos as ECUs in various forms.

I've e-mailed the guy working on this project to see how he's doing and whether he thinks there's any possibility of making a more generic system.

Tomaj
Apologies, I have adjusted the serial spec again

The command: 33 63 65 04 to request all data has been shortened to 63 65 04... the 33 command identifier byte was unnecessary and complicated/slowed the receive code on the arduino...

The ardunio will now respond to that request with 13 byte response (this will change as we need it to).

The first 4 bytes are a long unsigned value, the number of microseconds per half revolution of the crank... from this it is trivial to establish the RPM of the engine.

The second 4 bytes are the injector flow time, that is to say the duty cycle of the injectors in microseconds.

The third 4 bytes are the number of rotation ticks (512 per revolution) advance of the spark. At the moment I have it programmed that the spark always tries to advance the spark so that the spark fires about 1600 microseconds before TDC. The packet is terminated with a 06 as required by the spec.

Not sure what else we need at this time, but I'm sure we will think of something.

Make sure you flush you serial receive buffer before sending any commands or requests. The Arduino sends some random garbage during startup (and possibly other times, if any debug code is left in), so if you are not expecting any data from the arduino, reject anything as rubbish.



I have moved my code to version 0.6 now (available at https://sourceforge.net/projects/mia...ataBrain_v0.6/ ), which is fully interrupt based, timing is now accurate to 16 microseconds (or about half a degree of revolution at 8000RPM).
bloodline is offline  
Old 11-03-2010, 10:52 AM
  #157  
Newb
 
Mitch_1979's Avatar
 
Join Date: Oct 2010
Posts: 4
Total Cats: 0
Default

Hi bloodline,

I just finished looking through your code. There are some nice simplicities in how you've built structs and variables... makes it rather nice to read compared to my project.

A couple of thoughts that came to mind as I went through it. They are timing related though and I haven't worked through how much more leniant the Miata engine is on timing (the 2ZJ has a 34 tooth crank wheel requiring Arduino to respond every 5 degrees). Anyway...

From "MiataBrain_v0_62.pde":

setup(), line 265: Is it possible for a Crank signal to occur during Serial.println("") and that it gets missed or the synchronization doesn't happen as expected?

aquireAnalog(), line 358: I'm sure you know analogRead() will suspend program flow until the ADC completes. The 4 sequential reads I think should probably consume about 1-2 ms. At redline this is on the order 90deg. I don't think you can afford to miss fuel injection by that much. The approach I took for ADC was to use an interrupt handler for ADC.complete, which processes the result, sets the next channel, kicks off the next ADC, and returns. This also affords a much larger ADC prescaler which seemed necessary because of the signal impedances I was metering.

datalink(), line 291: similar comments to above, running dataLink serially to your injector control logic I'd be wary of missing critical injector events by a substantial margin... but maybe that's what you intend to handle with the ring buffer TODO.


Maybe these thoughts will help. Cool project though, and I appreciate the cleanliness of the code. I'm actually considering now that a standalone might be more feasible on an Arduino than a piggyback for ECU (less logic load in a standalone).

-Mitch
Mitch_1979 is offline  
Old 11-03-2010, 01:12 PM
  #158  
Junior Member
 
bloodline's Avatar
 
Join Date: Sep 2010
Location: London, England
Posts: 91
Total Cats: 0
Default

Originally Posted by Mitch_1979
Hi bloodline,

I just finished looking through your code. There are some nice simplicities in how you've built structs and variables... makes it rather nice to read compared to my project.
I really appreciate the code review, working alone means that I often get stuck in odd little traps that might not be the best or most efficient way (which explains why I'm already on v0.62 hahahah)...

A couple of thoughts that came to mind as I went through it. They are timing related though and I haven't worked through how much more leniant the Miata engine is on timing (the 2ZJ has a 34 tooth crank wheel requiring Arduino to respond every 5 degrees). Anyway...
The Miata is quite a crude (in a good way) machine, I've seen these engines take a real beating and a lot of abuse and still perform like new.

If you trawl back through this thread you can see the timing diagrams I built with the help of the members here, from that I was able to make the code. Basically, the Miata engine only has two timing pulses per crank revolution (actually I did toy with a more elaborate timing system that used the cam pulse as well, but it didn't improve timings in my tests).


From "MiataBrain_v0_62.pde":

setup(), line 265: Is it possible for a Crank signal to occur during Serial.println("") and that it gets missed or the synchronization doesn't happen as expected?
The cam pulse is so long, and the starting revolution speed is so slow missing the sync is never an issue... I have even had my simulator running at 8000rpm and it still syncs fine. I should note that even if the sync is lost it will be restored after 1 cam revolution, as the code resyncs every time.

aquireAnalog(), line 358: I'm sure you know analogRead() will suspend program flow until the ADC completes. The 4 sequential reads I think should probably consume about 1-2 ms. At redline this is on the order 90deg. I don't think you can afford to miss fuel injection by that much. The approach I took for ADC was to use an interrupt handler for ADC.complete, which processes the result, sets the next channel, kicks off the next ADC, and returns. This also affords a much larger ADC prescaler which seemed necessary because of the signal impedances I was metering.
I really wanted the code to be, 100% standard Ardunio... so that it could be ported to another arduino compatible board based on a different CPU architecture (I note here the wonderful, Maple Leaf Ardunio).

But in tests I found the Analog read function to block (as you point out) for upto 200 microseconds. My solution (which went against my original goal), was to set the prescaler at 1Mhz (21 microseconds per acquisition)... You are quire right that in a real engine, I might need a slower capture time... my solution would be to amplify and condition the signal with external hardware (a simple transistor and low pass filter should do, or even an op-amp...).

I have an interrupt based analog read function... but I fear that it might make the code a little too hard for beginners/less advanced programmers to read. Part of my design goal is for this code to be simple for anyone to have a go at using

I think you are probably right about this, and we will have to see how a real engine handles it...

datalink(), line 291: similar comments to above, running dataLink serially to your injector control logic I'd be wary of missing critical injector events by a substantial margin... but maybe that's what you intend to handle with the ring buffer TODO.
Yup, my serial code is a bit complex, but the result is that it only costs 2 microseconds per main loop cycle to send... one character is sent per main loop cycle. The communication protocol has been designed to ensure that there is minimal load on the system.

Maybe these thoughts will help. Cool project though, and I appreciate the cleanliness of the code. I'm actually considering now that a standalone might be more feasible on an Arduino than a piggyback for ECU (less logic load in a standalone).

-Mitch
Your thought are very helpful. I really welcome any constructive criticism.

I have though about your timing system, with the 34 tooth wheel... I think actually it would be rather easy to modify my code to use that... also with that resolution, timing would be much tighter

The required modification would be in the crankPulseInterrupt() function, where all I need to do is check for a high or low signal... for your timing wheel, that would need to be a bit more complex, and count the number of pulses (and call the correct function accordingly) and also the RPM calculation could be moved there (which would be nice)... everything thing else would remain the same.
bloodline is offline  
Old 11-03-2010, 08:52 PM
  #159  
Junior Member
Thread Starter
iTrader: (3)
 
ctxspy's Avatar
 
Join Date: Jun 2008
Location: NJ
Posts: 428
Total Cats: 0
Default

Hey Mitch, good to see you posting here.

Sorry i haven't gotten back to your e-mail, been preoccupied with getting my car running on my MS2.

I'll probably be getting an arduino as a christmas gift, so then i'll be more active in this project.

Mitch, bloodline, now that you've each seen the other's code, any ideas on how to proceed? Is there an opportunity to create a cooperative team project here?
ctxspy is offline  
Old 11-04-2010, 05:04 AM
  #160  
Junior Member
 
bloodline's Avatar
 
Join Date: Sep 2010
Location: London, England
Posts: 91
Total Cats: 0
Default

Originally Posted by ctxspy
Hey Mitch, good to see you posting here.

Sorry i haven't gotten back to your e-mail, been preoccupied with getting my car running on my MS2.

I'll probably be getting an arduino as a christmas gift, so then i'll be more active in this project.
This will be really great! If you need any assistance setting stuff up, let me know. I'm not a very good teacher, but I will try my best and you already have experience with software development so I think everything will be fine!
Mitch, bloodline, now that you've each seen the other's code, any ideas on how to proceed? Is there an opportunity to create a cooperative team project here?
I think Mitch would be most welcome if he could fin any use for the code for his own engine!

I also think he is spot on about the need for asynchronous analogue reads... And would be delighted if he could build a new analogue section
I have an osciliscope hooked up to the injector signals and it is clear that the duty cycle is larger than it should be :(


If either of you want to join the sourceforge project, please send me a request and I will add you.

For my part, I want to optimize the code a bit more (and probably move it to an OOP design, as my earlier mbed port uses, to make the code cleaner).
bloodline is offline  


Quick Reply: Arduino as ECU?



All times are GMT -4. The time now is 06:42 PM.