Programmable Ignition
well i'll start saying im totally new arduino. still havnt got in mail yet, while waiting thought start writing program.
not have old car put in, 1 day will. assuming going holden 308. idea replace dizzy 1 off vn ive seen on website. way hall effect sensor, no mecanical or vaccume advance. timing advance done program. (havnt got far yet anyway). idea ditch dizzy , run seperate coils each spark plug. mean running crank sensor require either sensor input indicate when cylinder 1 reaches tdc, or pin. im thinking id go running dizzy first. (but put pulsetime variables in idea of using crank sensor 1 day.)
so definetly work in progress. if ive done wrong or inefficent, please let me know!
not have old car put in, 1 day will. assuming going holden 308. idea replace dizzy 1 off vn ive seen on website. way hall effect sensor, no mecanical or vaccume advance. timing advance done program. (havnt got far yet anyway). idea ditch dizzy , run seperate coils each spark plug. mean running crank sensor require either sensor input indicate when cylinder 1 reaches tdc, or pin. im thinking id go running dizzy first. (but put pulsetime variables in idea of using crank sensor 1 day.)
so definetly work in progress. if ive done wrong or inefficent, please let me know!

code: [select]
int inpin = 3; //pin connected trigger hall effect sensor
int outpin = 12; //pin conected 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; // advance time. calculated rpm/map etc
unsigned long firetime; // time fire next spark compared micro()
int dwell = 250; // dwell time in us
void setup()
{
rpmcalc = 180000000/cylinders; // put hear save doing every loop. shortened this: 10000000/(cylinders/2)*60 go rpm. * 15 part of wma calculation (8+4+2+1)
pinmode(inpin, input);
pinmode(outpin, output);
attachinterrupt(1, halltrigger, rising ); //interrupt on hall effect input going high. 1 means use pin 3
}//end of setup
void loop()
{
//rpm calc. uses average of pulse times, logarithmic weighted moving average (newest time twice imprtant time before etc)
rpm = rpmcalc / ((pulsetime1 * 8)+(pulsetime2 * 4) +(pulsetime3 * 2)+ pulsetime4);
// no use 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 unsigned long max value of 4,294,967,295 need work out when 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
in absence of directives contrary, numeric literals interpreted ints.
do see "directives contrary"? don't. think 180000000 fit in int? don't. tacking ul on end (a directive contrary) useful.
however, think without arduino test on, or car test with, wasting time.
as exercise in programming, fine. so, i'll continue suggestions. adopt them or not, see fit.
i read comments precede block of code, since explain block of code performs not intuitive. read comments follow line of code, since state obvious. why point out? because don't read comments, have no idea inpin , outpin for. if had read comments, wouldn't remember later inpin , outpin for. and, why should i? name hallpin, instead of inpin, , name coilpin, instead of outpin, tell me, when reading rest of code, pins when referenced later.
see? why don't read inline comments. here, though, name numcylinders better, in opinion.
what absolute minimum , maximum limits on advance? can't imagine value greater 65535 degrees being meaningful. really, can't imagine value greater 255 degrees being meaningful.
the point? unsigned long way larger needed store values ever stored in variable. why matter? because have little memory in store variables. using 4 bytes, when 1 sufficient waste of 75%.
halltimenew , halltimeold local variables. unlike global variables, local variables not initialized. so, halltimenew contain random junk, copied halltimeold.
as aside, halltimeold , halltimenew easier read.
now, use random junk , "now" compute hope meaningful value. won't.
there no comments describe trying here, why there 4 values shuffled around various pulsetimex values are. (pulsetimex easier read.)
code: [select]
rpmcalc = 180000000/cylinders; // put hear save doing every loop. shortened this: 10000000/(cylinders/2)*60 go rpm. * 15 part of wma calculation (8+4+2+1)
do see "directives contrary"? don't. think 180000000 fit in int? don't. tacking ul on end (a directive contrary) useful.
however, think without arduino test on, or car test with, wasting time.
as exercise in programming, fine. so, i'll continue suggestions. adopt them or not, see fit.
code: [select]
int inpin = 3; //pin connected trigger hall effect sensor
int outpin = 12; //pin conected coil driving circuiti read comments precede block of code, since explain block of code performs not intuitive. read comments follow line of code, since state obvious. why point out? because don't read comments, have no idea inpin , outpin for. if had read comments, wouldn't remember later inpin , outpin for. and, why should i? name hallpin, instead of inpin, , name coilpin, instead of outpin, tell me, when reading rest of code, pins when referenced later.
code: [select]
int cylinders = 8; //number of cylynder of enginesee? why don't read inline comments. here, though, name numcylinders better, in opinion.
code: [select]
unsigned long advance = 14; // advance time. calculated rpm/map etc what absolute minimum , maximum limits on advance? can't imagine value greater 65535 degrees being meaningful. really, can't imagine value greater 255 degrees being meaningful.
the point? unsigned long way larger needed store values ever stored in variable. why matter? because have little memory in store variables. using 4 bytes, when 1 sufficient waste of 75%.
code: [select]
unsigned long halltimenew;
unsigned long halltimeold;
// micros unsigned long max value of 4,294,967,295 need work out when rolls over
halltimeold = halltimenew;halltimenew , halltimeold local variables. unlike global variables, local variables not initialized. so, halltimenew contain random junk, copied halltimeold.
as aside, halltimeold , halltimenew easier read.
code: [select]
pulsetime1 = halltimenew - halltimeold; //calclulate latest pulse timenow, use random junk , "now" compute hope meaningful value. won't.
there no comments describe trying here, why there 4 values shuffled around various pulsetimex values are. (pulsetimex easier read.)
Arduino Forum > Using Arduino > Project Guidance > Programmable Ignition
arduino
Comments
Post a Comment