Shop OBEX P1 Docs P2 Docs Learn Events
Looking for suggestions on a MAF project — Parallax Forums

Looking for suggestions on a MAF project

Jim EdwardsJim Edwards Posts: 54
edited 2012-01-02 17:07 in Propeller 1
MAF = Mass Airflow sensor that produces a signal whose frequency is dependent on the mass of airflow into an engine.

Inputs:
MAFIN - Mass airflow signal as described above. I do believe this is a simple squarewave but it's period is the most important property and it might actually have a duty cycle not exactly equal to 50%.
CLAMP - If CLAMP == 0, output another squarewave MAFOUT whose period is equal to MAFIN. If CLAMP == 1, clamp the period of the MAFOUT squarewave at the last measured period of MAFIN and hold that until CLAMP changes back to 0.

Outputs:
MAFOUT - As described above, this is the modified MAF signal and it will be provided to a stock engine management unit. We have a piggyback ECU that will take over control of the engine when CLAMP == 1 and want the stock engine management unit to think the MAF has been clamped as discussed above. Don't ask me why, I have a tuner friend that is doing this and that's how he wants it to work.

I can do this easily by sampling MAFIN and exactly replicating it for MAFOUT when CLAMP == 0. At the same time I can measure the time MAFIN is in a high and low state using the clock counts and keep track of that so that when CLAMP changes to 1, I can then generate a MAFOUT that is same as the last measured period (and in this case with the same duty cycle since I'm keeping track of both the high and low times).

There is one other slight complication, when CLAMP changes I don't want to just abruptly transition MAFOUT. If CLAMP changes from 0 to 1, I will wait until MAFIN hits a positive edge and then start generating a MAFOUT that is clamped to the last measured period. If CLAMP changes from 1 to 0, I will wait until I have completed the period of the MAFOUT in process (i.e. it hits a positive edge) and I will hold MAFOUT at a high state until MAFIN also reaches a high state at which point MAFOUT will follow MAFIN exactly.

I don't know the actual frequency range of MAFIN but since this is an automotive application I think it is safe to assume it will be a fairly low frequency (say 5000 cycles per second or less). The obvious way for a simpleton like me to do this program is using the clock count for measurement and waitcnt for clamped MAFOUT generation, but I am wondering if there is any other more clever, efficient method that uses the counter A/B modules?

Comments

  • pedwardpedward Posts: 1,642
    edited 2011-12-28 15:00
    I have some experience in this arena (http://www.dainst.com is my site). What make of MAF is this, sounds like a Bosch or Delphi?
  • Jim EdwardsJim Edwards Posts: 54
    edited 2011-12-28 15:20
    pedward wrote: »
    I have some experience in this arena (http://www.dainst.com is my site). What make of MAF is this, sounds like a Bosch or Delphi?

    I don't know but I'm asking for details.
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-12-28 23:00
    Without knowing anything in this domain, I'd suggest to start either with reading specs of the device -if available- or with implementing the gathering-data part first, which writes the results to a log-file for analysis on a PC.

    I think the air-flow will not change that much from one measurement to the next. That might explain why you have a duty cycle which is not exactly 50%. I think the device simply makes a measurement and calculates a pulse-time - makes the next measurement and calculates the pause-time .... next pulse ... next pause ... and so on.

    But anyway ... if you say you have to keep the MAFOUT constant accuracy can not be so important and I'd simply measure one time of MAFIN only -either pulse or pause- and use this value for both pulse and pause of MAFOUT. This way you can use one counter for measuring MAFIN and one counter to generate MAFOUT.
  • pedwardpedward Posts: 1,642
    edited 2011-12-29 00:01
    The devices are analog. Typically they use some variable analog input to vary an oscillator in proportion to the measurement. This is how the Delphi/AC Delco ones work. I think the Bosch ones have a similar output, just use a different sampling technique (resistive instead of inductive).
  • idbruceidbruce Posts: 6,197
    edited 2011-12-29 04:05
    @Jim Edwards

    According to this document, at first glance it appears that the MAF sensor is similar to a MAP sensor in a manner that it outputs a determined voltage.

    http://www.autoshop101.com/forms/h34.pdf

    I must admit that I have not thoroughly studied the MAF sensor, but if it can be read like the MAP sensor, here is a snippet of code that I used for reading the vacuum of a canister to which a MAP sensor monitored. The output of the MAP sensor was sent to an ADC0831 8-bit A/D converter and action was taken according to the output of MAP.

    Hope this helps. If not, sorry.

    Bruce
    PUB MonitorVacuumSupply
      DIRA[ADC_DO]~
      OUTA[ADC_CS]~~  'Set CS high
      DIRA[ADC_CS]~~  'Then direction
     
      OUTA[ADC_CLK]~
      DIRA[ADC_CLK]~~
      DIRA[Vacuum_Pump]~~
      OUTA[Vacuum_Pump]~
    ''''''''''''''''''''''''''''''''''''''''''
      WAITCNT(CLKFREQ / 10 + CNT)
    
    ''''' Check ADC0831 to get current reservoir value '''''
      CurrentVacuum := 0
      OUTA[ADC_CS]~     'Select Chip   
      OUTA[ADC_CLK]~~   'Pulse the clock high,
      OUTA[ADC_CLK]~    'then low to start the conversion
      REPEAT 8          'Shift 8 bits into our variable
        CurrentVacuum <<= 1
        OUTA[ADC_CLK]~~
        OUTA[ADC_CLK]~
        CurrentVacuum += INA[ADC_DO]
                   
      OUTA[ADC_CS]~~    'Deselect the Chip
      REPEAT
        IF CurrentVacuum > 110
          IF OUTA[Vacuum_Pump] == 0
            OUTA[Vacuum_Pump]~~
        IF CurrentVacuum < 100
          IF OUTA[Vacuum_Pump] == 1
            OUTA[Vacuum_Pump]~
        CurrentVacuum := 0    
           
        OUTA[ADC_CS]~     'Select Chip         
        OUTA[ADC_CLK]~~   'Pulse the clock high,
        OUTA[ADC_CLK]~    'then low to start the conversion
        REPEAT 8          'Shift 8 bits into our variable
                      
          CurrentVacuum <<= 1
          OUTA[ADC_CLK]~~
          OUTA[ADC_CLK]~      
          CurrentVacuum += INA[ADC_DO]
        OUTA[ADC_CS]~~    'Deselect the Chip
    
  • Jim EdwardsJim Edwards Posts: 54
    edited 2011-12-29 06:13
    Maybe pedward can shed some more light, but my understanding is that there are different types of MAF sensors meaning they use different physical phenomenon or methods for translating the airflow mass to a generated output. However, the output of a MAF sensor (what I refer to as MAFIN for my project description above) is either a voltage or frequency that represents the airflow mass (note that this relationship is probably non-linear). For this project, MAFIN is a frequency that represents the airflow mass so I need to be measuring it's period. I am still waiting for info on the make of the MAF from my tuner friend. Really all I need to know is the voltage levels it swings between, the frequency range I am dealing with, and maybe something about what the pulses look like (i.e. duty cycle). I suspect for a frequency output type of MAF that pedward knows something about these parameters already across the common MAF makes.
  • idbruceidbruce Posts: 6,197
    edited 2011-12-29 06:26
    Jim

    Here is another general article that describes the two main types, hot-wire and hot-film. The hot-wire type could be read with the ADC, but apparently you must have the hot-film type, which outputs a variable square wave ranging from 32 to 150Hz.

    http://www.wellsve.com/sft503/Counterpoint3_2.pdf

    Bruce
  • Jim EdwardsJim Edwards Posts: 54
    edited 2011-12-29 07:23
    Thanks. That is very helpful. The other type of frequency based MAF is Karman-Vortex which is used on my Toyota supra.
  • BobbyVBobbyV Posts: 19
    edited 2011-12-29 07:28
    There is an open source fuel injection system called Mega / MicroSquirt with a website that provides tons of information about the basics of fuel injection including how different types of sensors work and their type of output. This might provide a lot of the information you are looking for.

    http://www.microsquirt.info/mafmap.htm

    Robert.
  • pedwardpedward Posts: 1,642
    edited 2011-12-29 12:15
    Since you know it's a frequency MAF, you basically have all you need to do what you are talking about. Your biggest problem is that you need to buffer the frequency, so that you are always outputting the frequency from the Propeller. This will resolve the edge issue you are referring to, so you will always be synced. Use 1 timer for capture and the other timer to produce the frequency.

    I haven't scoped these, and it's been a while since I read up on the Delco MAF sensors, but I suspect that you will have either an exact 50% duty cycle, or you will have something closer to a 90/10 or 70/30 so that the edge is properly triggered on the ECU (older systems are weird this way). If the ECU input can't handle a 50% duty cycle, then you need some external triggering logic to create the proper duty, since the Propeller can't simultaneously generate a duty and frequency from the same counter.
  • pgbpsupgbpsu Posts: 460
    edited 2011-12-29 13:47
    Hi Jim-

    For measuring frequency with the propeller you can use the counters as you guessed. The best resource is the counters app note. http://www.parallaxsemiconductor.com/sites/default/files/appnotes/AN001-P8X32ACounters-v2.0_2.pdf


    Here's some sample code that I've used to measure the input frequency and time spent high at a given refresh rate and used that info to calculate the duty cycle. I think this gives duty cycle in increments of .01% I wanted better than 1% accuracy, but didn't want to deal with floating point numbers so I scaled everything by 100. 10000 = 100%. It should be easy to check with a known input. Probably not bullet proof and no doubt posting it will reveal some unknown bugs, but it's a start.

    CON
    REFRESH_RATE      =    50  ' refresh rate in milliseconds
    INPIN                     = 5   ' prop pin to monitor
    
    PUB MAIN
    ' setup counter A for frequency and B for duty (after some calculations)
      ctra := %01010 << 26 + INPIN    ' counter A in POSedge mode
      ctrb := %11010 << 26 + INPIN    ' counter B in LOGIC A mode
      frqa := frqb := 1               ' increment 1 per pulse for A and once per clock for B waitcnt(clkfreq + cnt)
    
    ' Do other setup things here.   
    
    
    PUB MEASURE_INPUT_DUTY | highTime
    ' measure the input duty cycle using counters. 
      phsa := phsb := 0                     ' reset count registers
      PAUSE_MS(REFRESH_RATE)                ' accumulate data for 1 second.
      highTime     := phsb * constant(1000/REFRESH_RATE)         ' how much time spent high in one second?
      inFreq       := phsa * constant(1000/REFRESH_RATE)         ' read the number of edges; convert to 1 second
      inDuty       := highTime/(clkfreq/10000)     ' convert duty to percent
    
    PUB PAUSE_MS(mS)
      waitcnt(clkfreq/1000 * mS + cnt)
    
    
  • Jim EdwardsJim Edwards Posts: 54
    edited 2011-12-29 17:38
    Thanks all for you valuable info and suggestions.
  • idbruceidbruce Posts: 6,197
    edited 2012-01-02 07:37
    Hey Jim

    How about an update? How is the project going?

    Bruce
  • Jim EdwardsJim Edwards Posts: 54
    edited 2012-01-02 07:53
    idbruce wrote: »
    Hey Jim

    How about an update? How is the project going?

    Bruce

    Just found out this morning that the MAF make is Bosch. Still need to confirm it provides a frequency dependent output rather than a voltage dependent output. Over the weekend I ordered a Propeller USB Proto Board along with a Parallax Multi-Board enclosure to use for the project. To test I'm going to have to pick up a low cost frequency generator (although I could use a propeller output in the interim to generate a test signal that varies in frequency, but it's always good to have a frequency generator anyway). Given the low frequency range of this MAF signal based on the info above (30 to 150 Hz), I think I can get away with a very simple approach of detecting edge transitions and using the clock count to measure the high/low periods. I will sample the MAF input and set the MAF output to that value when CLAMP == 0; when CLAMP changes to 1 I will simply generate a waveform with the last measured high/low periods. I think given the low frequency range this will result in good enough accuracy on the approach.
  • idbruceidbruce Posts: 6,197
    edited 2012-01-02 08:05
    Well thanks for the update Jim. I was just curious how it was all working out.

    Bruce
  • sidecar-racersidecar-racer Posts: 82
    edited 2012-01-02 09:14
    Have you looked at the signal from the MAF with a scope? This would identify voltage levels, frequency, and duty cycle.
    I'm working on a datalogger for a race machine and one of the functions is to measure speed (using hall-effect sensor on disk bolts).
    One need from this is to generate a pulse that is dependant on the wheel speed but adjustable up or down to provide a corrected pulse rate for the existing speedometer so it will be correct for different gear ratios. (Speedometer is driven from primary drive sprocket) (Motorcycle engine)
    Rick
  • Jim EdwardsJim Edwards Posts: 54
    edited 2012-01-02 09:41
    Have you looked at the signal from the MAF with a scope? This would identify voltage levels, frequency, and duty cycle.
    I'm working on a datalogger for a race machine and one of the functions is to measure speed (using hall-effect sensor on disk bolts).
    One need from this is to generate a pulse that is dependant on the wheel speed but adjustable up or down to provide a corrected pulse rate for the existing speedometer so it will be correct for different gear ratios. (Speedometer is driven from primary drive sprocket) (Motorcycle engine)
    Rick

    The car this will go on is on the east coast (I'm on the west coast). My tuner friend travels around to do his work. I'm hoping to get a Bosch part # so I can try to look up the data.

    Dakota Digital has what you describe (see http://www.dakotadigital.com/index.cfm/page/ptype=product/product_id=126/category_id=287/home_id=59/mode=prod/prd126.htm ). I use one on my supra to calibrate the speedo to work with a GM 4L80E auto tranny.
  • Jim EdwardsJim Edwards Posts: 54
    edited 2012-01-02 17:07
    This is my initial pseudo code for the project, paying little attention to real parallax syntax.
    const INIT = 0, MIRROR = 1, CLAMP = 2
    state := INIT
    
    repeat 
        switch (state)
            INIT:        
                // Startup state, just mirror MAF_IN to MAF_OUT and wait to acquire first measurement of high and low counts of one cycle.
                last_val := -1
                c1 := -1        
                high_cnt := low_cnt := 0
                repeat until (high_cnt > 0) AND (low_cnt > 0)
                    outa[MAF_OUT] := cur_val := ina[MAF_IN]
                    if (cur_val == 1 AND last_val == 0)    // Rising edge detected
                        if (c1 == -1)
                            c1 := cnt
                        else
                            c3 := cnt
                            high_cnt := c2 - c1
                            low_cnt := c3 - c2
                            c1 := -1
                    elseif (cur_val == 0 AND last_val == 1)    // Falling edge detected
                        c2 := cnt
                    last_val := cur_val
                state := MIRROR
                
            MIRROR:
                // MAF_OUT will follow MAF_IN during this state. When the active low signal CLAMP turns to 0, wait until MAF_OUT reaches it's next rising edge transition
                repeat until (ina[CLAMP] == 0) AND (c1 == -1)
                    outa[MAF_OUT] := cur_val := ina[MAF_IN]
                    if (cur_val == 1 AND last_val == 0)        // Rising edge detected
                        if (c1 == -1)
                            c1 := cnt
                        else
                            c3 := cnt
                            high_cnt := c2 - c1
                            low_cnt := c3 - c2
                            c1 := -1
                    elseif (cur_val == 0 AND last_val == 1)    // Falling edge detected
                        c2 := cnt
                    last_val := cur_val
                state := CLAMP
            
            CLAMP:        
                // MAF_OUT will be clamped at the last high and low counts measured in MIRROR state. When CLAMP returns to 1, hold a low output on MAF_OUT until MAF_IN reaches it's next rising edge transition
                repeat until ina[CLAMP] == 1
                    c1 := cnt
                    repeat until ((cnt - c1) >= high_cnt
                        outa[MAF_OUT] := 1
                    c1 := cnt
                    repeat until (cnt - c1) >= low_cnt
                        outa[MAF_OUT] := 0
                        
                last_val := -1
                repeat
                    cur_val := INA[MAF_IN]
                    if (cur_val == 1 AND last_val == 0)    // Rising edge detected
                        outa[MAF_OUT] := cur_val
                        state := MIRROR
                        last_val := cur_val
                        c1 := cnt    // Ensure that MIRROR mode starts the counting process properly for high and low period
                        break
                    last_val := cur_val
    
Sign In or Register to comment.