Welcome to the SR20 Community Forum - The Dash.
Register
SR20 forum logo

Thread: Flex-fuel sensor output

+ Reply To Thread
Posts: 11-20 of 72
2015-02-17 21:52:44
#11
Thanks for the update.

Very cool!
2015-02-21 18:49:13
#12
Got everything mounted on the car, like this:


Problem is, my input is not getting any HZ signal at all. Will have to continue investigating this once I can borrow an oscilloscope again.. When I bench tested the sensor, (5V feed although it is rated for 9-18V) I got a 30HZ signal (with water) using a pullup resistor to +5V. Why this doesn't work now has me baffled. It will probably clear up when I get my hands on an oscilloscope.

By the way, I might have an extra Atmega644P+LCD for sale if anyone wants a plug-n-play solution for 1/4 the price of zeitronix display. Just gotta get the code bulletproof first
2015-02-28 08:52:21
#13
Still didn't get my hands on an oscilloscope, but I tested the circuit with a Hz capable multimeter. Disregard my above circuit, the pullup resistor should be going to 12V instead of 5V. Like this:


Oh, and I also ordered a lower spec atmega328+LCD, for 17$! http://i.imgur.com/2Eof8bL.png
These should in theory be able to be adapted to the same task, so anyone who wants to go the same route as me will get a really affordable solution.

Stay tuned for next weekend!
2015-03-08 15:42:11
#14
Had a breakthrough in development and got the sensor to co-operate nicely with the microcontroller. Threw it into the glovebox for now.


It seems to be pretty spot on aswell. Had some regular gas in the tank, and blended it with E75.

Tried to wire it in to the ADC3 input on NEMU, but it wasn't fooled by my PWM output It changes between 0 and 5V in the logger. Guess I'll have to construct a lowpass-filter..
2015-03-11 17:52:55
#15
Since everything is going so well, I am in the process of porting the application to a standard Arduino Uno + 16x2 LCD.


Anyone who wants a flex fuel converter, can order an Uno+LCD for 15$ on ebay!

You can even use them without an actual flex fuel sensor, by using it as a fuelmode changer with the pushbuttons!


I'll release the arduinocode when i's ready, for now you can look at the completed Atmega644 code here: https://www.dropbox.com/s/nuls52r3p2rc984/Frequency.c?dl=0
2015-03-11 20:13:04
#16
I have a mega and the same lcd shield sitting here. Can't wait for the code, I have 2 different OEM freq based sensors I want to test with this.
2015-03-11 21:13:42
#17
Great work!
2015-03-12 12:11:13
#18
Completed pushbutton fuel application below, and arduino file: https://www.dropbox.com/s/p21g6f9b0zso8at/FlexFuelNoSensor.ino?dl=0

Spoiler
#include  //Use standard liquidcrystal library

/*******************************************************
Made for Arduino UNO + 16x2LCD (atmega328)

This program will select fuelmode using pushbuttons, and
output a PWM signal depending on selection.

Fuel 1 (98E5) = 1V
Fuel 2 (95E10) = 2V
Fuel 3 (E85) = 3V

Connect PWM output to NEMU Breakoutboard on ADC0-3, and tune
the "FLEX FUEL SETUP" tab accordingly. NOTE: Lowpass filter must
be used on output.
********************************************************/

// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
//select the pin used for PWM output
int ledPin = 3; //possible PWM output pins with LCD are 3, 10 and 11 (UNO)
// define values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
int fuelmode = 1; //integer for storing fuelmode value, use fuel 1 when starting
int pwm_output = 0; //integer for storing PWM value

#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5

// read the buttons
int read_LCD_buttons()

{
adc_key_in = analogRead(0); // read the value from the sensor

if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;

return btnNONE; // when everything else fails, return this
}

void setup()
{
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0); // Initial screen formatting
lcd.print("Fuelmode:");
lcd.setCursor(0,1);
lcd.print("Output:");
}

void loop()
{
lcd.setCursor(10,0); // move to the begining of the second line
lcd_key = read_LCD_buttons(); // read the buttons

switch (lcd_key)
// depending on which button was pushed, we add or subtract fuelmode
{
case btnRIGHT:{
fuelmode = fuelmode + 1;
delay(200);
break;
}
case btnLEFT:{
fuelmode = fuelmode - 1;
delay(200);
break;
}
case btnUP:{
fuelmode = fuelmode + 1;
delay(200);
break;
}
case btnDOWN:{
fuelmode = fuelmode - 1;
delay(200);
break;
}
}
if (fuelmode < 1){ //avoid negative fuelmode values
fuelmode = 1;
}
if (fuelmode > 3){ //avoid overflow fuelmode values
fuelmode = 3;
}
if (fuelmode == 1){ //Display the selected fuelmodes
lcd.print("98E5 "); //First fuel mode = 98oct
pwm_output = 55; //PWM duty cycle 55/255 equals 1V
lcd.setCursor(10,1);
lcd.print("1V");
}
if (fuelmode == 2){
lcd.print("95E10"); //Second fuel mode = 95oct
pwm_output = 105; //PWM duty cycle 105/255 equals 2V
lcd.setCursor(10,1);
lcd.print("2V");
}
if (fuelmode == 3){
lcd.print("E85 "); //Third fuel mode = E85
pwm_output = 155; //PWM duty cycle 155/255 equals 3V
lcd.setCursor(10,1);
lcd.print("3V");
}
analogWrite(ledPin, pwm_output); // Fianlly, write the PWM value
}


Now I have to make the real sensor application
Last edited by Dala on 2015-03-12 at 12-13-14.
2015-03-13 20:59:38
#19
Very nice! looks good on my mega with the same display.
2015-03-13 21:57:23
#20
I completed the real sensor converter application, but I ran into a problem with the LCD.

The LCD is hardwired to pin 8, which happens to be pin PB0, which is the ICP1 pin. This is the "Input Capture Pin", which I have based the whole program on.

So, my application only works without the LCD for now. I will try to sample the frequency with another pin, but that will take more time since I can't approach the problem with the same timer methods.

So for now, barebone flexfuel converter application:


/*******************************************************
This program will sample a 50-150hz signal depending on ethanol
content, and output a 0-5V signal via PWM.

Connect PWM output to NEMU Breakoutboard on ADC0-3, and tune
the "FLEX FUEL SETUP" tab accordingly. NOTE: Lowpass filter to
be used on output.

Input pin 8 (PB0) ICP1 on Atmega328
Output pin 11
********************************************************/

int inpPin = 8; //define input pin to 8
int outPin = 11; //define PWM output, possible pins with LCD are 3, 10 and 11 (UNO)


//Define global variables
volatile uint16_t revTick; //Ticks per revolution
uint8_t pwm_output = 0; //integer for storing PWM value (0-255 value)
uint16_t HZ; //unsigned 16bit integer for storing HZ input
int ethanol = 0; //Store ethanol percentage here


void setupTimer() // setup timer1
{
TCCR1A = 0; // normal mode
TCCR1B = 132; // (10000100) Falling edge trigger, Timer = CPU Clock/256, noise cancellation on
TCCR1C = 0; // normal mode
TIMSK1 = 33; // (00100001) Input capture and overflow interupts enabled

TCNT1 = 0; // start from 0
}

ISR(TIMER1_CAPT_vect) // PULSE DETECTED! (interrupt automatically triggered, not called by main program)
{
revTick = ICR1; // save duration of last revolution
TCNT1 = 0; // restart timer for next revolution
}

ISR(TIMER1_OVF_vect) // counter overflow/timeout
{ revTick = 0; } // Ticks per second = 0


void setup()
{
setupTimer();
}

void loop()
{

if (revTick > 0) // Avoid dividing by zero
{HZ = 57600 / revTick;} // 3456000ticks per minute, 57600 per second
else
{HZ = 0;}

//calculate ethanol percentage
if (HZ > 50) // Avoid dividing by zero
{ethanol = HZ-50;}
else
{ethanol = 0;}
//Screen calculations
pwm_output = 255 * (ethanol*0.01); //calculate output PWM for NEMU

//PWM output
analogWrite(outPin, pwm_output); //write the PWM value to pin

}


NOTE: this is untested, I will get the final LCD version tested before releasing the code.

Oh, and the lowpass filter should be constructed with a 4.7kOhm resistor, and a 1-10uF condensator. I am still about to confirm this though!
Last edited by Dala on 2015-03-13 at 22-01-52.
+ Reply To Thread
  • [Type to search users.]
  • Quick Reply
    Thread Information
    There are currently ? users browsing this thread. (? members & ? guests)
    StubUserName

    Back to top