Well I'll start by saying Im totally new to arduino. Still havnt got it in the mail yet, so while i was waiting I thought I would start writing a program.
Not that i have a old car to put it in, but one day i will. Assuming its going to be a Holden 308. so the idea is to replace the dizzy with one off a VN as ive seen on another website. that way its just a hall effect sensor, with no mecanical or vaccume advance. Timing advance would be done by the program. (havnt got that far yet anyway). Another idea is to ditch the dizzy all together and run seperate coils for each spark plug. that would also mean running a crank sensor which would require either another sensor input to indicate when cylinder 1 reaches TDC, or an extra pin. Im thinking id go for running with a dizzy first. (but i put the pulsetime variables in with the idea of using a crank sensor one day.)
so this is definetly a work in progress. If ive done something obviously wrong or inefficent, please let me know!
int InPin = 3; //Pin connected to trigger from hall effect sensor
int OutPin = 12; //Pin conected to coil driving circuit
volatile unsigned long pulsetime1; //Time delay of latest pulse
volatile unsigned long pulsetime2; // time delay of pulse before that
volatile unsigned long pulsetime3; // time delay of pulse before that
volatile unsigned long pulsetime4; // time delay of pulse before that
volatile unsigned long halltimenew;
volatile unsigned long halltimeold;
int rpm;
int cylinders = 8; //number of cylynder of engine
long rpmcalc;
unsigned long advance = 14; // this is the advance time. will be calculated eventually from rpm/map etc
unsigned long firetime; // the time to fire next spark compared to micro()
int dwell = 250; // dwell time in uS
void setup()
{
rpmcalc = 180000000/cylinders; // put this hear to save doing it every loop. shortened this: 10000000/(cylinders/2)*60 to go from uS to rpm. also * 15 as part of the wma calculation (8+4+2+1)
pinMode(InPin, INPUT);
pinMode(OutPin, OUTPUT);
attachInterrupt(1, halltrigger, RISING ); //interrupt on hall effect input going high. the 1 means that it will use pin 3
}//END OF SETUP
void loop()
{
//RPM calc. uses average of pulse times, logarithmic weighted moving average (newest time is twice as imprtant as time before etc)
rpm = rpmcalc / ((pulsetime1 * 8)+(pulsetime2 * 4) +(pulsetime3 * 2)+ pulsetime4);
// no use for rpm yet
firetime=halltimenew+pulsetime1-advance;
if (firetime >= micros()) ;
{
digitalWrite (OutPin, HIGH);
delayMicroseconds (dwell);
digitalWrite (OutPin, LOW);
firetime=0;
}
}//end of loop
void halltrigger(){
unsigned long halltimenew;
unsigned long halltimeold;
// micros is a unsigned long with max value of 4,294,967,295 will need to work out what to do when it rolls over
halltimeold = halltimenew;
halltimenew = micros(); //get time of HALL GOING HIGH
pulsetime4 = pulsetime3;
pulsetime3 = pulsetime2;
pulsetime2 = pulsetime1;
pulsetime1 = halltimenew - halltimeold; //calclulate latest pulse time
}//end of halltrigger
Programable_ignition.ino (2.05 KB)