Go Down

Topic: arduino ignition (Read 333 times) previous topic - next topic

mega-hz

Mar 21, 2018, 10:45 pm Last Edit: Mar 21, 2018, 10:46 pm by mega-hz
Hello Paul Stoffregen and all others,
 
i found your nice library FreqMeasure and have a little Problem with my projekt „Kennfeldzündung":
 
I can measure the speed of the ignition on Pin 8 and it shows me the RPM of the Motor,
 
but i need a signal (one per round) for  making a delayed output wich goes tot he ignition-coil.
 
Do you have an idea, how to catch the high/low state on pin 8 while also measuring the frequency?
 
Regards,
Wolfram.
 

 
 
My code so far:
--------------------------------------------------------
Code: [Select]

/* FreqMeasure - Example with LCD output
* http://www.pjrc.com/teensy/td_libs_FreqMeasure.html
*
* This example code is in the public domain.
*/
#include <FreqMeasure.h>
#include <LiquidCrystal.h>
 
LiquidCrystal lcd(7, A2, 9, 10, 11, 12);
#define LCD_LED_BLUE A3
#define LCD_LED_GREEN A4
#define LCD_LED_RED A5
 
void setup() {
  Serial.begin(9600);
  lcd.begin(20, 4);
  lcd.print("Freq:");
  FreqMeasure.begin();
  pinMode(LCD_LED_RED, OUTPUT);
  pinMode(LCD_LED_GREEN, OUTPUT);
  pinMode(LCD_LED_BLUE, OUTPUT);
  digitalWrite(LCD_LED_RED, LOW);
  digitalWrite(LCD_LED_GREEN, LOW);
  digitalWrite(LCD_LED_BLUE, LOW);
}
 
double sum = 0;
int count = 0;
 
void loop()
{
  if (FreqMeasure.available())
  {
    // average several reading together
    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count > 10)
    {
      float frequency = FreqMeasure.countToFrequency(sum / count);
      lcd.setCursor(0, 1);
      lcd.print(frequency);
      lcd.print(" Hz      ");
      float umin = map(frequency,0,100.0,0,6000.0);
      lcd.setCursor(0, 3);
      lcd.print(umin);
      lcd.print(" Umin      ");
      sum = 0;
      count = 0;
    }
  }
}
 


MADMAN-_-zZ

Hi Wolfram,

Just trying to understand better what you are trying to accomplish.

Are you trying to create a delayed HIGH/LOW signal every single revolution of the motor?

What kind of motor/driver are you using or what are you using to receive RPM (encoder/hall sensor)

And I can't see where PIN8 is being utilised for RPM in the example you posted.

mega-hz

pin 8 is defined in the library.
The Motor is a 2stroke bike motor and it has a contact which opens once a rpm.

depending on the measured rpm the signal of the contact should be outputted on another io more or less delayed.

this delayed output drives a power-fet wich turns the ignition-coil on/off.

MADMAN-_-zZ

Okay, I kinda think I know what your talking about, are you basically making your own CDI unit to control the ignition timing of the engine?

If so you said you are able to receive a correct rpm reading thanks to the library, are you then trying to send a HIGH signal through another Pin as the ignition signal after every revolution? can you do something like below.

Code: [Select]
void loop(){
  if (digitalRead(8) == HIGH){
    //pin 11 = FET ignition**
    digitalWrite(11, HIGH)
    delayMicroseconds(3);
    digitalWrite(11, LOW)
  }
}


Or are you trying to do something more complex then that?

mega-hz

that could work:
Code: [Select]
  if (digitalRead(8) == HIGH){
    //pin 11 = FET ignition**

    delayMicroseconds(delay); // delay value depending on rpm

    digitalWrite(11, HIGH)
    delayMicroseconds(10);     // defined on-time of coil
    digitalWrite(11, LOW)

but, it must have priority to not miss a pulse, would irq may work?
the mesurement routine must wait if a pulse appears.

mega-hz

i will try this first:

Code: [Select]
/* FreqMeasure - Example with LCD output
 * http://www.pjrc.com/teensy/td_libs_FreqMeasure.html
 *
 * This example code is in the public domain.
 */
#include <FreqMeasure.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, A2, 9, 10, 11, 12);
#define LCD_LED_BLUE A3
#define LCD_LED_GREEN A4
#define LCD_LED_RED A5
#define FET 13
float zuenddelay = 8000.0;

void setup() {
  Serial.begin(9600);
  lcd.begin(20, 4);
  lcd.print("Freq:");
  FreqMeasure.begin();
  pinMode(LCD_LED_RED, OUTPUT);
  pinMode(LCD_LED_GREEN, OUTPUT);
  pinMode(LCD_LED_BLUE, OUTPUT);
  pinMode(FET, OUTPUT);
  digitalWrite(LCD_LED_RED, LOW);
  digitalWrite(LCD_LED_GREEN, LOW);
  digitalWrite(LCD_LED_BLUE, LOW);
}

double sum = 0;
int count = 0;

void loop()
{
  if (FreqMeasure.available())
  {
    // average several reading together
    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count > 10)
    {
      int frequency = FreqMeasure.countToFrequency(sum / count);
      lcd.setCursor(0, 1);
      lcd.print(frequency);
      lcd.print(" Hz      ");
      int umin = map(frequency, 0, 100, 0, 6000);
      zuenddelay = map(frequency, 0, 100, 8000.0, 0.0);
      lcd.setCursor(0, 2);
      lcd.print(umin);
      lcd.print(" Umin ");
      sum = 0;
      count = 0;
    }
  }
  if (digitalRead(8) == HIGH)
  {
    delayMicroseconds(zuenddelay); // delay value depending on rpm
    digitalWrite(FET, HIGH);
    delayMicroseconds(10);     // defined on-time of coil
    digitalWrite(FET, LOW);
    lcd.setCursor(10, 3);
    lcd.print(zuenddelay/1000);
    lcd.print(" mS ");
  }
}
// kontakt im irq, nur wenn nicht geschlossen messen!!

MADMAN-_-zZ

Let me know how it goes!

mega-hz

yep!

i will try it with an irq, see tonight the results on the scope...
for using the irq d2 and d8 must be tied together.

Code: [Select]
/* FreqMeasure - Example with LCD output
 * http://www.pjrc.com/teensy/td_libs_FreqMeasure.html
 *
 * This example code is in the public domain.
 */
#include <FreqMeasure.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, A2, 9, 10, 11, 12);
#define LCD_LED_BLUE A3
#define LCD_LED_GREEN A4
#define LCD_LED_RED A5
#define FET 13
#define KONTAKT 2     // D2 & D8 together

float zuenddelay = 8000.0;

void setup() {
  Serial.begin(9600);
  lcd.begin(20, 4);
  lcd.print("Freq:");
  FreqMeasure.begin();
  pinMode(LCD_LED_RED, OUTPUT);
  pinMode(LCD_LED_GREEN, OUTPUT);
  pinMode(LCD_LED_BLUE, OUTPUT);
  pinMode(FET, OUTPUT);
  digitalWrite(LCD_LED_RED, LOW);
  digitalWrite(LCD_LED_GREEN, LOW);
  digitalWrite(LCD_LED_BLUE, LOW);
  attachInterrupt(0, kontakt, RISING);
}

double sum = 0;
int count = 0;

void loop()
{
  if (FreqMeasure.available())
  {
    // average several reading together
    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count > 10)
    {
      int frequency = FreqMeasure.countToFrequency(sum / count);
      lcd.setCursor(0, 1);
      lcd.print(frequency);
      lcd.print(" Hz      ");
      int umin = map(frequency, 0, 100, 0, 6000);
      zuenddelay = map(frequency, 0, 100, 16000.0, 0.0);
      lcd.setCursor(0, 2);
      lcd.print(umin);
      lcd.print(" Umin ");
      lcd.setCursor(10, 3);
      lcd.print(zuenddelay / 1000);
      lcd.print(" mS ");
      sum = 0;
      count = 0;
    }
  }
}
void kontakt()
{
  delayMicroseconds(zuenddelay); // delay value depending on rpm
  digitalWrite(FET, HIGH);
  delayMicroseconds(1000);     // defined on-time of coil
  digitalWrite(FET, LOW);
}
// kontakt im irq, nur wenn nicht geschlossen messen!!

mega-hz

it seems to take a while before i can test it on the bike,
first i have to do some repairs on the motor...

Go Up