Cam Angle Sensor

March 6th, 2008

 

This is a graph of the outputs from a Nissan cam angle sensor (CAS) . I will need to perform timing events on the falling edge of the wave since the cylinder reset wave length is variable. The timing trigger has 360 waves per rotation. Since the sensor is on the camshaft of a 4-stroke engine (camshafts rotate at half crank speed), there are 180 waves per engine revolution. AT 9000 RPM, that is 270 KHz (9000 / 2 * 60 / 1000). To account for fractions, we need a clock speed much higher than this (270 KHz is bare minimum). A 1 Mhz (~4x minimum) clock for the FPGA should be more than enough 99.9% of the time.

At the falling edge of each timing signal, increment a counter. Lets call this variable i. this counter is not used to calculate angle and is not limited to 360. After variable i is incremented, we check the state of the cylinder reset signal. If the signal just went high, then we initialize another counter( variable r) to 0. We will also increment variable r on the falling edge of the timing signal whenever the cylinder reset signal is high.

On the falling edge of cylinder reset, we compare the value of variable r (pulse width of the cylinder reset wave) to known values to figure out which cylinder# just reset, and set variable p to the degree at which that cylinder is at top dead center (TDC) at the first stroke divided by 2 (since the camshaft moves at half engine speed). If cylinder1 just reset, we will set variable p to 0 (0 degrees).

So now we have everything we need to time sequential fuel injection and sequential ignition. However if we timed these events to the falling edge of the timing signal, we could only adjust timing in 2 degree increments, unacceptable! I want at least 0.1 degree resolution. To remedy this situation, we need to know the RPM. This will need to be an average, and a minute is too long of a sampling time obviously. Sampling time needs to short enough for the system to detect engine acceleration quick enough. at 60rpm (1 revolution per second) there are 1000000 clocks per revolution or 2000000 clocks per complete engine cycle. One missed timing sync signal with a 1 second sample would be an error rate of approx (1 / 180) 0.5% or +- 3 rpm at 600rpm, and +- 0.01 degrees accuracy of crank rotation. Earlier I stated I wanted 0.1 degrees of resolution, which means I would need 10 Hz RPM sampling. 10 Hz on a 1 MHz clock is 100,000 clocks. So lets create variable r for rpm, and variable b for the counter. Every clock we need to increment b. Every 100,000 clocks we need to set r to the value of b, and set b to 0. We will need a counter to count to 100,000 clocks as well, lets call it variable a.

 

 

Here is some psuedo code to help illustrate:

if(++a > 100000)
{
    s = b;
    b = 0;
    t = 0;
    a = 0;
}

if(timing_pin)
{
    i++;
}
else
{
    if(i)
    {
        t++;
        p = p + (1 * 10;)

        if(cylinder_reset)
        {
            r++;
        }
        else
        {
            if(r)
            {
                if(r == 10)        // cylinder 1 tdc
                {
                    p = 0;
                }
                else if(r == 20)    // cylinder 2 tdc
                {
                    p = 540 * 10;
                }
                else if(r == 30)    // cylinder 3 tdc
                {
                    p = 180 * 10;
                }
                else if(r == 40)    // cylinder 4 tdc
                {
                    p = 360 * 10;
                }
                else            // error
                {
                }
                r = 0;
            }
        }
        e = p;
        i = 0;
    }
}

ECU Schematic

March 5th, 2008

TCM = Timing Control Module
IOM = Input / Output Module
CPM = Central Processing Module

Objective

Create a standalone Engine Control Unit (ECU) that (at the very least) performs sequential fuel injection and timing for automotive internal combustion engines with options to control auxiliary systems such as intake air control valve (IACV), air conditioning compressor clutch, vacuum solenoids, etc. The three modules communicate with each other over Ethernet.

Timing Control Module

The TCM will receive a stream of UDP packets from the CPM that contain values each individual cylinder’s fuel injector pulse width and timing value. The stream is constant and automatic. The TCM never transmits data back to the CPM. The TCM will run a field programmable gate array (FPGA) to handle the rapid timing signals generated by the crank (or cam) angle sensors. From this data, the module will know when to trigger timing and fuel events for each cylinder. The TCM is located in the engine bay, as close to the distributer as possible.

Input / Output Module

The IOM performs analog-to-digital conversions of various engine sensors, and then streams the values continuously (in round-robin fashion) to the CPM. The IOM also receives a UDP stream from the CPM with information about various digital pin states to set, DAC outputs, and PWM outputs. Its important to note that the inbound and outbound Ethernet have no relation to each other. The entire system is based purely on streaming and no requests are made. This module is based on a MCU. The IOM is located in the engine bay, as close to the central location of the engine sensors as possible.

Central Processing Module

This module receives sensor data from the IOM, crunches the numbers to determine fuel and ignition values to send to the TCM, as well as outputs to send to the IOM. It may also perform other duties such as logging data, communicating with a personal computer for configuration changes, or handling human interface devices (HID). HID’s can be anything from keyboards to graphical displays. The CPM should run some sort of ARM cpu and run linux. The CPM should be located in the cabin, but can theoretically be located anywhere.

Advantages

  1. Wiring is dramatically reduced, as such more accurate analog signal values may be delivered to the ECU for processing. Running the cables is also easier since the girth of RJ45 cables is negligible compared to the factory harness.
  2. Extremely inexpensive wiring and replacement.
  3. No cross interference between analog circuitry and digital as they are located in separate modules.
  4. Extremely easy to troubleshoot but sniffing network traffic over Ethernet with any common PC.
  5. Easier to develop and build.
  6. Powerful arm CPU can perform very complex calculations that conventional ECU’s cannot.
  7. Open source.

Disadvantages

  1. May require special ethernet cables and connectors for the harsh engine environment.
  2. Due to the divided nature, 3 Ethernet controllers are needed for communication purposes.
  3. Packet loss may be hard to identify and isolate, while causing poor engine performance.

prologue

February 28th, 2008

This category will be of my random thoughts on the subject of artificial intelligence, or more specifically, artificial neural networks.

slow progress

February 28th, 2008

After two weeks of being down, I finally got my car running again.  During the downtime, I managed to accomplish:

  1. Hard inter cooler pipes.
  2. Somewhat replace both o2 sensors.
  3. Delete all non-critical water and vacuum lines.
  4. Relocate fuel pressure regulator next to the fuel filter
  5. Delete fuel dampener
  6. Bypass EGR (exhaust gas recirculation)
  7. Replace brake booster

 Just as a bit of a preface, my car is a 1993 Twin Turbo 300zx.  Its old and parts are starting to give out.  I cannot touch a hose without it cracking a breaking.  I really need to do a full rebuild, but do not have time nor energy at the moment.

The inter cooler pipes were ordered from eBay, they are shiny cheap chinese pipe.  But hey, its a pipe, it doesn’t need to be manufactured by NASA.  I will say that even tough they are shiny, their luster could not ease my dissatisfaction for the cheap clamps (4 of which were unusable).  Luckily I had several good clamps laying around to replace them.  Chinese quality control at its finest.

I say somewhat replace the o2 sensors, because I broke a cheap advanceauto o2 sensor socket on the driver side turbo o2 sensor, which managed to partially strip the sensor in the process.  Broken willed (and socketed heh), I attempted to try my luck on the passenger side, same result… :[  o2 (oxygen) sensors are used to measure the amount of oxygen in the exhaust (after the chemical reaction) so the ECU can modify the amount of fuel injected into the motor to try to achieve the stoichiometric ratio for gasoline.  Its a closed loop feedback system, that is (on my car anyways) used only to get good gas milage.  When you floor the gas pedal, the ecu ignores the o2 sensors so they have no affect on performance.  So I just cut the wires and left them stuck in my factory downpipes.  This will give me incentive to upgrade to 3″ downpipes later :]

As asinine as it sounds, I had to remove the upper portion of the engine to replace the brake booster (what initiated this repair session).  There was not enough clearance between the shock down and the intake manifold for the brake booster to snake through.  Removing the intake manifold is a chore in and of itself.  It had obviouslly never been pulled before, and there was an abundance of unknown crap attached to it.  And if I dont know what it is, I probably dont need it.  So i strapped my cherry picker to intake manifold, and lifted until shit started breaking.  I tore 2 fuel lines, 2 egr ports, countless water lines, and a few vacuum lines.  I replaced the fuel lines (they needed to be replaced anyways, they were 15 years old), deleted / blocked off the water and vacuum ports as they went to stupid emissions crap (think of me when your kids get asthma).

I removed the fuel dampener since it cluttered my engine bay and made it harder to work on the car.  Most cars do not have them anyways, I am sure there is a super special reason why Nissan decided to install one, however its not critical for the car to run so I do not care.  I moved the fuel pressure regular besides the fuel filter for the same reason: simplicity.  I suspect the elasticity of the extra rubber fuel line will act as fuel dampener by expanding / contracting and absorbing the pressure waves in the fuel rail caused by the opening and closing of the fuel injectors at low fuel flow conditions (such as when im idling or “racing” corollas).

I bought a 48×2″ aluminum strip from Home Depot, and cut it down into 1 inch pieces and then bolted it down over the EGR ports.  Not the most elegant solution, however it should work and save me $50.

Brake booster was straight forward once I removed the intake manifold.  After 1 year of having no power brakes, I can finally stop.  There is a really good reason my right thigh is larger than my left :]

New beginning

February 28th, 2008

You may be wondering where the music went? This site was vandalized by someone who exploited a vulnerability in an open source application I had installed. They did not do much damage, all they could do was delete files the web server had write access to. Everything was backed up, however its the principal of everything. I spent countless hours programming Loki, and money on server upgrades so friends could share terabytes of music and movies for free, and this is what I get in return. And this was not an isolated incident, there are daily hack in attempts, and daily relentless hammers from persistent bots. I put a lot into this site, and got nothing out of it but grief and a thinner wallet.

Hindsight is 20/20, the only mistake I made was making the multimedia public. I do not have the time to maintain it.

/rant