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

Thread: Flex-fuel sensor output

+ Reply To Thread
Posts: 31-40 of 72
2015-03-23 14:40:04
#31
Where are you planning on mounting your unit dala?


Hopefully mine will get wired in tonight.

Last edited by D-Unit121 on 2015-03-23 at 14-46-58.
2015-03-23 16:30:49
#32
Originally Posted by D-Unit121
Where are you planning on mounting your unit dala?


Nice,

For now I have mine temporarily stashed in the glovebox compartment, along with one of these:

Unfortunately, the Uno is specified for 3.3-12V, so hooking it up directly into the +12 would fry it, since the alternator makes the voltage hit circa 14V when charging the battery. Another benefit for using 5V to power it, is that it's really easy to hook up the external 5K ohm pullup resistor to 5V, so the frequency can be sampled into the arduino.

I won't show any pictures of my messy install, but I do plan to make a better install soon.
2015-03-23 22:41:14
#33
great stuff.
2015-03-24 18:17:50
#34
I've been looking into the fuel temperature, here's how to manually decipher it:


Can anyone find info on what the Continental sensor uses for defining temperature? I found this on the MegaSquirt webpage, but it's pretty old info:

  • 1 millisecond indicates -40°C (-40°F), and
  • 5 milliseconds indicates 125°C (257°F).

Update for Arduino application coming soon
2015-03-24 19:57:29
#35
@D-Unit121 , clear your inbox!

Here's the schematic you're after:
2015-03-24 19:59:10
#36
@Dala its cleared

Thanks!
Last edited by D-Unit121 on 2015-03-24 at 20-01-09.
2015-03-24 21:22:17
#37
Jeez, this thread is getting messy. Time to add more to the mix:

I found a way to read the pulsewidth information, so now fuel temperature can be calculated


It would be nice to have the datasheet, but for now I have to do some measurements and guess the calibration.

Here's the unfinished code:
Spoiler
/*******************************************************
This program will sample a 50-150hz signal depending on ethanol
content, and output a 0-5V signal via PWM.
The LCD will display ethanol content, hz input, mv output, fuel temp

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 3 PWM

If LCD Keypad shield is used, solder jumper from Pin 8 - Pin 2,
and snip leg from pin 8 http://i.imgur.com/KdlLmye.png
********************************************************/

// include the library code:
#include //LCD plugin

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 9, 4, 5, 6, 7); //LCD Keypad Shield

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

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

static double duty; //Fuel temp calculation variables
static long highTime = 0;
static long lowTime = 0;
static long tempPulse;

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()
{
pinMode(inpPin,INPUT);
setupTimer();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Initial screen formatting
lcd.setCursor(0, 0);
lcd.print("Ethanol: %");
lcd.setCursor(0, 1);
lcd.print(" Hz mV C");
}

void loop()
{
getfueltemp(inpPin); //read fuel temp from input duty cycle

if (revTick > 0) // Avoid dividing by zero, sample in the HZ
{HZ = 62200 / revTick;} // 3456000ticks per minute, 57600 per second
else // 62200 per seconmd seems to be more accurate?
{HZ = 0;} //needs real sensor test to determine correct tickrate

//calculate ethanol percentage
if (HZ > 50) // Avoid dividing by zero
{ethanol = HZ-50;}
else
{ethanol = 0;}

if (ethanol > 100) // Avoid overflow in PWM
{ethanol = 100;}

//Screen calculations
pwm_output = 255 * (ethanol*0.01); //calculate output PWM for NEMU
voltage = ethanol*50; //calculate voltage (mV) for display

lcd.setCursor(10, 0);
lcd.print(ethanol);

lcd.setCursor(0, 1);
lcd.print(HZ);

lcd.setCursor(6, 1);
lcd.print(voltage);

lcd.setCursor(13, 1);
lcd.print(temp);

//PWM output
analogWrite(outPin, pwm_output); //write the PWM value to output pin
analogWrite(outPin2, 204); //489.9Hz test output. 20celcius from 80% duty cycle, not for actual sensor use

delay(500); //make screen more easily readable by not updating it too often

}

void getfueltemp(int inpPin){ //read fuel temp from input duty cycle
highTime = 0;
lowTime = 0;

tempPulse = pulseIn(inpPin,HIGH);
if(tempPulse>highTime){
highTime = tempPulse;
}

tempPulse = pulseIn(inpPin,LOW);
if(tempPulse>lowTime){
lowTime = tempPulse;
}

duty = (100*(highTime/(double (lowTime+highTime)))); //Calculate duty cycle
temp = (100-duty); //Calculate real temperature (celcius) NOT FINISHED
}


Don't worry, Fahrenheit unit will be included in the functioning release
2015-03-25 11:30:30
#38
D-unit has been helping me alot with the initial testing, kudos to him

On todays agenda, we need to get the RC-filter sorted out. @D-Unit121 , I need some more values from you!



By only using a first order RC filter, we won't get anywhere near a linear representation of the 0-100% signal. It will be good enough for real usage though.

D-unit, can you find out what the internal resistance of the breakout board input is? Or does John know? I would beasure it myself, but my car is still in winter storage.. Once we have that locked in, simulating a good filter will be easy.
Last edited by Dala on 2015-03-25 at 11-58-01.
2015-03-25 19:27:49
#39
Been working on a fully working temperature addition, here is a fahrenheit version:

Spoiler
/*******************************************************
This program will sample a 50-150hz signal depending on ethanol
content, and output a 0-5V signal via PWM.
The LCD will display ethanol content, hz input, mv output, fuel temp

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 3 PWM

If LCD Keypad shield is used, solder jumper from Pin 8 - Pin 2,
and snip leg from pin 8 http://i.imgur.com/KdlLmye.png
********************************************************/

// include the library code:
#include //LCD plugin

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 9, 4, 5, 6, 7); //LCD Keypad Shield

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

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


int duty; //Duty cycle (0.0-100.0)
float period; //Store period time here (eg.0.0025 s)
float temperature = 0; //Store fuel temperature here
int fahr = 0;
int cels = 0;
static long highTime = 0;
static long lowTime = 0;
static long tempPulse;

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()
{
pinMode(inpPin,INPUT);
setupTimer();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Initial screen formatting
lcd.setCursor(0, 0);
lcd.print("Ethanol: %");
lcd.setCursor(0, 1);
lcd.print(" Hz mV F");
//lcd.print(" Hz mV C"); //Use this for celsius
}

void loop()
{
getfueltemp(inpPin); //read fuel temp from input duty cycle

if (revTick > 0) // Avoid dividing by zero, sample in the HZ
{HZ = 62200 / revTick;} // 3456000ticks per minute, 57600 per second
else // 62200 per seconmd seems to be more accurate?
{HZ = 0;} //needs real sensor test to determine correct tickrate

//calculate ethanol percentage
if (HZ > 50) // Avoid dividing by zero
{ethanol = HZ-50;}
else
{ethanol = 0;}

if (ethanol > 100) // Avoid overflow in PWM
{ethanol = 100;}

//Screen calculations
pwm_output = 255 * (ethanol*0.01); //calculate output PWM for NEMU
voltage = ethanol*50; //calculate voltage (mV) for display

lcd.setCursor(10, 0);
lcd.print(ethanol);

lcd.setCursor(0, 1);
lcd.print(HZ);

lcd.setCursor(6, 1);
lcd.print(voltage);

lcd.setCursor(12, 1);
lcd.print(fahr);
//lcd.print(cels); //Use this for celsius


//PWM output
analogWrite(outPin, pwm_output); //write the PWM value to output pin
//analogWrite(outPin2, 220); //489.9Hz test output.

delay(100); //make screen more easily readable by not updating it too often

}

void getfueltemp(int inpPin){ //read fuel temp from input duty cycle
highTime = 0;
lowTime = 0;

tempPulse = pulseIn(inpPin,HIGH);
if(tempPulse>highTime){
highTime = tempPulse;
}

tempPulse = pulseIn(inpPin,LOW);
if(tempPulse>lowTime){
lowTime = tempPulse;
}

duty = ((100*(highTime/(double (lowTime+highTime))))); //Calculate duty cycle (integer extra decimal)
float T = (float(1.0/float(HZ))); //Calculate total period time
float period = float(100-duty)*T; //Calculate the active period time (100-duty)*T
float temp2 = float(10) * float(period); //Convert ms to whole number
temperature = ((40.25 * temp2)-81.25); // Calculate temperature for display (1ms = -40, 5ms = 80)
int cels = int(temperature);
cels = cels*0.1;
float fahrtemp = ((temperature*1.8)+32);
fahr = fahrtemp*0.1;

}[/SPOILER]


Now we just need to get the RC filter sorted and we can wrap this thread up!
2015-04-09 16:14:29
#40
I have a very exciting update for everyone.

I filled my tank up with ethanol a few days ago and this arduino unit is doing a great job. I wanted to wait a few days to update this thread so I could confirm that the code and hardware is stable. That being said I currently have about 3 hours of driving time on the unit.

The output voltages are going stable to my nismotronic ecu and the different ethanol content voltages are linear. The display works great also.
+ Reply To Thread
  • [Type to search users.]
  • Quick Reply
    Thread Information
    There are currently ? users browsing this thread. (? members & ? guests)
    StubUserName

    Back to top