Looking for suggestions on a MAF project
Jim Edwards
Posts: 54
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?
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
I don't know but I'm asking for details.
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.
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
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
http://www.microsquirt.info/mafmap.htm
Robert.
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.
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.
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.
Bruce
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.