Shop OBEX P1 Docs P2 Docs Learn Events
Newbie - CAR MAF Project — Parallax Forums

Newbie - CAR MAF Project

jbalatjbalat Posts: 96
edited 2009-07-28 00:05 in BASIC Stamp
Hi, Im new to Stamp. I have a kit but havent even plugged it in yet.

Please let me know how hard this would be to do so I know if it is worth the pain of learning all about this stamp stuff ?



I need to modify the CARS MAF (Mass Airflow Signal) to the computer for a HHO installation I am testing.

It is a perfect square wave signal at 3.8v Peak to Peak

At 600 rpm the frequency is 36 Hz
at 2500 rpm it is 111 Hz

Voltage stays constant

I need to modify the frequency by a factor ie. 80 % (or whatever I decide or dial in)
eg. 29Hz at 600 rpm and 89Hz at 2500rpm


The link to the HHO forum is here with more details of my little project
http://www.fuel-saver.org/Thread-HHO-woes?pid=29192#pid29192


Thanks in advance !!!!
John B

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-30 05:35
    The Stamp can only do one thing at a time, so it can measure the input frequency or it can output a pulse, but not both at the same time. With a little bit of external hardware (like a 555 timer with a digital pot to control the frequency and a flip-flop to divide by 2 to get a symmetric square wave) the Stamp can measure the input frequency or pulse width and control the digital pot to output the new frequency. It can also read some thumbwheels that set the adjustment factor and provide some feedback on a small LCD.

    A Propeller would be able to do it all by itself since it has 8 separate processors on the chip. One would constantly measure the input frequency. One would generate the output square wave applying the adjustment factor to the measured input frequency. One could scan the thumbwheels to provide the adjustment factor, and one could produce a video output for a small TV screen with monitoring information (like the input frequency, adjustment factor, and output frequency). The Propeller's supply voltage is normally 3.3. It can operate as high as 3.6V, but 3.8V is too close to the absolute maximum permitted supply voltage, so you'd need the Propeller's output to drive an external transistor which would switch the 3.8V signal.
  • jbalatjbalat Posts: 96
    edited 2009-06-30 09:38
    The unit I have access to is a BS2P anf the board of education..

    So the stamp can only do one thing at a time..

    Can I assume with some clever programming you could switch to the input and store the value of the frequency then switch to the output to spit out the modified frequency..

    The processor is many times quicker than my maximum frequency of maybe 150 Hz. A small time delay would not matter too much even if it were half a second or so ?

    I will have a read about the propeller system when I get a chance.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-30 13:36
    Here's another idea, again based on the notion of offloading one of two tasks to an auxiliary processor ...

    Use the PWMPAL to generate the output pulses: www.parallax.com/Store/Accessories/MotorServoControllers/tabid/160/CategoryID/35/List/0/Level/a/ProductID/67/Default.aspx?SortField=ProductName%2cProductName

    With the PWMPAL, the Stamp can set the on and off time of the output. The Stamp would use its PULSIN statement to measure the width of the input square wave and use that to compute the frequency (assuming that you have a true square wave).

    The problem with "switch to the input" is that, without some kind of external square wave generator, the frequency output pulses would stop while the Stamp is counting input pulses or measuring the pulse width. From your original description, it seemed like you need an ongoing pulse train. It's not allowed to stop and start and "dance about".
  • jbalatjbalat Posts: 96
    edited 2009-07-01 02:04
    Thats right, the signal is square and must be continuous.

    Hi mike, my electronics skills are pretty limited.. The more I can do on the programming side the better.

    If you think its a better option to buy the propeller kit then let me know.. If the car accepts a 3.6v signal then I assume the propeller can regulate it to 3.6v ? Does the propelloer use a Basic language ?

    I want the completed unit to look like a simple breadboard, the chip and a digital pot for adjustment..

    Not sure which bits I need to purchase. Very happy if you can point me in the right direction for development and then the final standalone unit that I will install in the car
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-01 03:40
    The PWMPAL can do a nice job generating a continuous 5V square wave signal which can be "stepped down" using a simple voltage divider to 3.8V. I assume you have the "Board of Education" and a BS2 Stamp. The PWMPAL plugs into the Board of Education's Stamp socket and the Stamp plugs into the PWMPAL. I would get a 500 Ohm potentiometer for the voltage divider, connect the fixed ends between one of the PWMPAL's output channels (I/O pins 12 to 15 and ground. Your signal output will be between the tap (slider) of the potentiometer and ground and you'll adjust the potentiometer until the output voltage is what you want. If you want it pretty accurate, get a 10-turn potentiometer.

    Download the PWMPAL documentation and the Nuts and Volts Column both with links on the PWMPAL product page, then have a look at them.
    Download the Basic Stamp Syntax and Reference Manual from Parallax's Stamp Documentation Download page and look at the chapter on the PULSIN statement (to measure the width of the input pulses from which you calculate the frequency).

    You can use the Board of Education for the final product by glueing the wiring and parts on the breadboard so vehicle vibration won't loosen them. Alternatively, after you debug the hardware and software, you can buy a Super Carrier Board which is very close to the layout of the Board of Education and move the parts over from the Board of Education, but have them soldered into place.

    You might look into using a 12-key keypad and a MemKey encoder. This would let you easily enter numbers as well as some control characters

    Look at the documentation on the product pages: www.parallax.com/tabid/768/txtSearch/memkey/List/0/SortField/4/Default.aspx

    There are also some articles on using keypads with other kinds of encoding.
    Browse the Nuts and Volts Columns index: www.parallax.com/tabid/272/Default.aspx

    Consider a simple LCD for a status display: www.parallax.com/Store/Accessories/Displays/tabid/159/CategoryID/34/List/0/Level/a/ProductID/50/Default.aspx?SortField=ProductName%2cProductName
  • jbalatjbalat Posts: 96
    edited 2009-07-02 00:11
    I have downloaded the info and I will try to read it tonight

    Since its going in the car I was just going to set it up with an oscilliscope and install it permanently with a surface mounted digital pot. So I wanted just a bare bones solution at minimal cost.

    The BS2P and board of education is something I can play with but I will need to replace if it goes in the car so..

    ... If I buy the PWMPal with a Basic2 Stamp and super carrier board should I be ok ?

    Are there any distributors in Australia ?

    Thanks again for your input

    John B
  • SandgroperSandgroper Posts: 62
    edited 2009-07-03 14:45
    You might try RT Nollet.· http://www.nollet.com.au
  • jbalatjbalat Posts: 96
    edited 2009-07-05 00:53
    Will get a quote thanks..

    Hey I just figured out a way to do it without a pwmpal..but going ahead with pwmpal anyway since it will come in handy for a PWM to regulate the HHO cell temperature in the future..

    Sinse pulsin,pulsout require the program to wait we cant afford to do this so..

    ...inside a loop
    measure input state high or low.. If high then count number of highs, if low count number of lows
    upon an input state change set the maxoutputhighs as 120% (equiv to 80% of freq) of the high count and similarly for output low counts
    When in highstate output a high until maxhighcount is reached

    This way you are outputting a high or low in the clock speed of the stamp. May need a small capacitor to smooth the voltage as it does a quick input check..
    Actual period or timing is not important since the output will only be running at 1 to 1.5 waves behind the input at all times !!

    UPDATE 8-JUL
    Wow that was quick, got the Stamp bits from Ron.. Will have a play soon

    Post Edited (jbalat) : 7/8/2009 7:58:19 AM GMT
  • jbalatjbalat Posts: 96
    edited 2009-07-11 10:12
    Hi just wondering if it is possible to measure the incoming pulse with the PWMPal rather than withthe PULSIN statement ?

    Not sure if PULSIN will work out the duty cycle ?
  • jbalatjbalat Posts: 96
    edited 2009-07-21 13:19
    mafstamp1.jpg
    All done and ready to fit on the car
    Added a pot for 50% to 99% adjustment factor -> freq out = factor * freq in
    also a bypass switch should anything go wrong
    and had to use a 2.5kohm pot for my voltage divider (actually 2k resistor and 500 Ohm trimpot) to get the right output voltage 3.9v

    Ready to fit to car.. Fingers crossed..

    Still dont know hot to use the pwm input channels.. If anyone has any better documentation on the pwmpal then please point me in the right direction.
  • jbalatjbalat Posts: 96
    edited 2009-07-25 12:11
    Test 1 failed miserably. Engine light came on and car went into safe mode.
    When trying to check the output I got nothing, then a single pulse, then a real low freq pulse. then a series of extremely high freq pulses. The stamp was possesed....

    Trying a more simpler program without the pwmpal

    This was my code...

    ' PULSIN2.BS2
    ' This program counts the incoming pulse
    ' and outputs the pulse with a lower frequency
    ' using the PWM Pal Motor 1
    ' It also adjusts the amount of offset
    ' maximum at the lofactor frequency
    ' and no offset at the hifactor frequency
    ' The factor is set by a pot on Pin 9 which
    ' can vary from 50% to 99%

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    '
    [noparse][[/noparse] I/O Definitions ]

    PpPin PIN 0 ' PWMPAL Serial I/O
    Pulse PIN 7 ' pulse input pin

    '
    [noparse][[/noparse] Constants BS2 Only ]
    W CON 2 ' -- 2.0 us per unit
    F CON 0 ' -- 0 fractional units
    T9600 CON 84
    T19K2 CON 32
    T38K4 CON 6
    PpBaud CON T38K4
    MotorNum CON 1 ' PWMPAL motor output PIN 12

    '
    [noparse][[/noparse] Variables ]
    time VAR Word
    freqIN VAR Word 'Frequency of incoming pulse
    mfactor VAR Word 'Maximum Output factor 0-100
    rfactor VAR Word 'Adjusted Output factor for freq 0-100
    OnTime VAR Word 'On/Off time 25us units
    prevOnTime VAR Word 'compare with current on time
    status VAR Byte 'motor control status
    lofactor VAR Word 'lo frequency for max mfactor% Offset
    hifactor VAR Word 'hi frequency for 100% - No Offset
    potValue VAR Word 'Pot
    potCounter VAR Byte 'Only check pot every 100 cycles

    '
    [noparse][[/noparse] Initialization ]
    mFactor = 70 '50 to 100 % Grab from RCTIME Later on
    rFactor = 90 'adjusted factor
    OnTime = 556
    prevOnTime = 555
    loFactor = 33 'minimum frequency for mFactor
    hiFactor = 300 'maximum frequency after this rFactor=100
    potCounter = 99

    Setup:
    SEROUT 0, PpBaud, [noparse][[/noparse]"!PWMM0"] ' reset all pwm pins
    PAUSE 10
    SEROUT PpPin, PpBaud, [noparse][[/noparse]"!PWMSP", %00010001] ' set phase, counter 1 enabled
    SEROUT PpPin, PpBaud, [noparse][[/noparse]"!PWMSS", %00010000] ' enable PWM1 software control

    Main:
    'RCTIME Read Pot on Pin9 - adjustment 50% to 99% for freq
    potCounter = potCounter + 1
    IF potCounter > 5 THEN ' only check every 5 cycles
    HIGH 9
    RCTIME 9, 1, potValue ' measure RC discharge time
    potValue = 50 + ( potValue / 16 ) MIN 50 MAX 99
    potCounter = 0
    mfactor = potValue ' mfactor is the adjustment
    ENDIF

    'Measure incoming pulse from MAF Sensor Pin 12
    PULSIN Pulse, 0, time ' measure positive pulse
    IF (time > 0) THEN ' if not 0
    'DEBUG HOME,
    ' DEC time, " units ", CLREOL ' display raw input

    'DEBUG CR,
    ' DEC potValue, " pot value "

    time = (time * W) + (time ** F) ' adjust for Stamp
    'DEBUG CR,
    ' DEC time, " us " ' display microseconds

    freqIN = 1000 /(2 * time / 1000) ' Only on Time calculated (x2)
    'DEBUG CR,
    ' DEC freqIN , " Hz Input " ' display Total Input freq

    OnTime = time / 25

    SELECT freqIN
    CASE <= loFactor
    rFactor = mFactor 'use full mfactor below lo value

    CASE >= hiFactor
    rFactor = 100 'use no factor above high value

    'Offset mFactor less for higher frequencies - high rpm
    CASE ELSE
    rFactor = (100 - mFactor) * (freqIN - loFactor)
    rFactor = rFactor / (hiFactor - loFactor) 'Calculate resulting factor
    rFactor = rFactor + mFactor
    ENDSELECT

    OnTime = OnTime * 100 / rFactor
    'DEBUG CR,
    ' DEC (rfactor * freqIN / 100) , " Hz Output " ' display Total Output freq
    'DEBUG CR,
    ' DEC mfactor , " mFactor " ,
    ' DEC rFactor , " adjusted " ' display factors

    IF prevOnTime <> Ontime THEN GOSUB SetPWM


    ELSE
    'DEBUG CLS, "Out of Range" ' else error message
    ENDIF
    PAUSE 1
    GOTO Main

    'Subroutine to set new Frequency
    SetPWM:
    'DEBUG CR, "CHANGE FREQ ", DEC OnTime , " "
    'Set for 50% duty cycle
    SEROUT PpPin, PpBaud, [noparse][[/noparse]"!PWMM1", OnTime.BYTE0, OnTime.BYTE1, OnTime.BYTE0, OnTime.BYTE1]
    prevOnTime = OnTime
    RETURN

    END
  • jbalatjbalat Posts: 96
    edited 2009-07-28 00:05
    Anyone able to help with this problem.. Now that the output wave is looking better I dont know how to feed it back to the ECU since I think the ECU is sending 5v one way to power the sensor and the sensor is sending the pulse back to the ecu on the same wire ?
    www.fuel-saver.org/Thread-ECU-behaviour?pid=29457#pid29457
Sign In or Register to comment.