Pages: [1]   Go Down
Author Topic: Electronic ignition advance  (Read 1753 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 0
Posts: 268
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone,
i have a big problem with my software: i'm making a programmable ignition advance system with arduino UNO and i want to read the RPM (the frequency) of the input square signal and select a delay value previously saved in a table, to apply as delay to my input signal.
The reading of the input freq is maked by the freq/counter interrupt routin on pin3 found in internet.
So what is the correct method to apply the delay on the output signal?

I tried with the micros() function but the trace of the output signal isn't stable on oscilloscope. it seems the delay is variable.

Please help me.

Thanks in advance!
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26196
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

All hands on the ouija board.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Sr. Member
****
Karma: 0
Posts: 268
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What?
Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 This will explain.

http://arduino.cc/forum/index.php/topic,97455.0.html
Logged


Offline Offline
Sr. Member
****
Karma: 0
Posts: 268
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not an expert of programming but i can understand the code.
Is an entire day that i try to modify the code and search in all the web the solution but i don't found nothing or only piecies.

I need an help from you!
Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


  In the link above, you should have found a part about posting your code. Without your code, we have to call to the spirits using a triangle and a board, to find your problem.
Logged


Offline Offline
Sr. Member
****
Karma: 0
Posts: 268
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this is the code:

Code:

#include "FreqPeriodCounter.h"


#define PUIN 3
#define PUOUT 4

float m[6]={0, 0, 0, 0, 0, 0}; // y=m*x+q
float q[6]={0, 0, 0, 0, 0, 0};
int i=0;

unsigned long prec=0;
int delta_t; // in microseconds
int freq; // hertz



const byte counterPin=PUIN;
const byte counterInterrupt=1;
FreqPeriodCounter counter(counterPin, micros, 0);

void setup()
{
 
 
  attachInterrupt(counterInterrupt, counterISR, CHANGE);

 
  pinMode(PUIN,INPUT); // input signal
  pinMode(PUOUT,OUTPUT); // output signal
  digitalWrite(PUOUT, LOW);

   
  //  configuration 2000rpm 0°, 4000rpm 3°, 6000rpm 5.5°, 8000rpm 7.5°, 10000rpm 10°
    delta_t_opt[0]=0;delta_t_opt[1]=125;delta_t_opt[2]=152;delta_t_opt[3]=156;delta_t_opt[4]=160;
    freq_max[0]=33;freq_max[1]=67;freq_max[2]=101;freq_max[3]=133;freq_max[4]=167;
   
    for(i=0; i<5; i++)
    {
      m[i+1]=(float)(((delta_t_opt[i+1]-delta_t_opt[i])*1.0)/((freq_max[i+1]-freq_max[i])*1.0));
    }
    m[0]=(float)((delta_t_opt[0]*1.0)/(1.0*freq_max[0]));
   
    for(i=0; i<5; i++)
    {
      q[i]=(float)((delta_t_opt[i]*1.0)-m[i+1]*freq_max[i]);
    }
   
   
}

void loop(void)
{
       
          val=digitalRead(PUIN);
         
         if(counter.ready()) {freq=counter.hertz();}
           
          if(freq<freq_max[0]) //make the semi-lines in every frq range and y=m*x+q -> delta_t=m[]*freq+q[]
          {
            delta_t=(int)(m[0]*freq+0.5);
          }
          if(freq>=freq_max[0] && freq<freq_max[1])
          {
            delta_t=(int)((m[1]*freq+q[0])+0.5);   
          }
          if(freq>=freq_max[1] && freq<freq_max[2])
          {
            delta_t=(int)((m[2]*freq+q[1])+0.5);
          }         
          if(freq>=freq_max[2] && freq<freq_max[3])
          {
            delta_t=(int)((m[3]*freq+q[2])+0.5);
          }         
          if(freq>=freq_max[3] && freq<freq_max[4])
          {
            delta_t=(int)((m[4]*freq+q[3])+0.5);
          }         
          if(freq>=freq_max[4] && freq<freq_max[5])
          {
            delta_t=(int)((m[5]*freq+q[4])+0.5);
          }
         
         
          if(micros()-prec>=(unsigned long)(delta_t)) //wait until the delay and then make the out signal
            {
              digitalWrite(PUOUT,val);
              prec=micros();
            }   
             
     

}

void counterISR() // for the freq counter
{
  counter.poll();
}

Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12631
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I must admit I'm too lazy to try to figure out all that arithmetic you're doing.

It looks rather more complex than I was expecting for something that basically just outputs a PWM signal phase-locked to an input square wave.

I thought you might handle the problem in several stages.

Count and time the pulses to maintain an average RPM value.
Regularly look at the current RPM and load and choose your required advance angle and dwell angle and from that work out the timing of your output pulse relative to the input pulse.

Have a very simple loop which detects the input transition marking the start of your timing cycle, determines when the next output event is relative to that, and performs the output event when it's due.

Since you're doing rather a lot of arithmetic every time round the loop, you're adding in a substantial delay before you can test whether it's time to output your pulse. I'd defer all that to a quiet time - for example after you have performed an output action and hence know that you won't need to perform another action for a while.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: