Hello.
I have not hade the time enought to work on my code a lot, but today I did. I have tried to get rid of the unnecessary calculations and I made an attempt to use crankshaft time instead of rpm. I did make an curve in excell for the cranktime also to get a better understanding. Please have a look at my code and excell sheet.
I have some questions.
First, I have read that calculation with global variables take a lot of memory. I have to use them in my interrupt service routines and interrupts, but in my loop I could move that value to an local variable and use that in my calculations in the loop. Is that a good idea?
The ignition advance time could be coded with about 10 calculation instructions. It could also be coded without calculations, but a lot of if instructions instead (one for every 100rpm for example). What way is the best? What takes most time, and what is most safe/realiable?
Here is one version:
if (halfrev>= 100000 ) { cranktime = 0 ; } // 300
if ((halfrev>= 85714 ) & (halfrev< 100000)){ cranktime = 85476 ;} // 350
if ((halfrev>= 80000 ) & (halfrev< 85714 )){ cranktime = 78667 ;} // 375
if ((halfrev>= 77922 ) & (halfrev< 80000 )){ cranktime = 74025 ;} // 385
if ((halfrev>= 76923 ) & (halfrev< 77922 )){ cranktime = 72222 ;} // 390
if ((halfrev>= 75000 ) & (halfrev< 76923 )){ cranktime = 70000 ;} // 400
if ((halfrev>= 70588 ) & (halfrev< 75000 )){ cranktime = 65921 ;} // 425
if ((halfrev>= 66667 ) & (halfrev< 70588 )){ cranktime = 62333 ;} // 450
if ((halfrev>= 60000 ) & (halfrev< 66667 )){ cranktime = 56267 ;} // 500
if ((halfrev>= 50000 ) & (halfrev< 60000 )){ cranktime = 47222 ;} // 600
if ((halfrev>= 42857 ) & (halfrev< 50000 )){ cranktime = 40476 ;} // 700
if ((halfrev>= 37500 ) & (halfrev< 42857 )){ cranktime = 35417 ;} // 800
if ((halfrev>= 33333 ) & (halfrev< 37500 )){ cranktime = 31481 ;} // 900
if ((halfrev>= 30000 ) & (halfrev< 33333 )){ cranktime = 28333 ;} // 1000
if ((halfrev>= 28571 ) & (halfrev< 30000 )){ cranktime = 26904 ;} // 1050
if ((halfrev>= 27272 ) & (halfrev< 28577 )){ cranktime = 25454 ;} // 1100
if ((halfrev>= 25000 ) & (halfrev< 27272 )){ cranktime = 23152 ;} // 1200
if ((halfrev>= 23076 ) & (halfrev< 25000 )){ cranktime = 21217 ;} // 1300
if ((halfrev>= 21428 ) & (halfrev< 23076 )){ cranktime = 19523 ;} // 1400
if ((halfrev>= 20000 ) & (halfrev< 21428 )){ cranktime = 18056 ;} // 1500
if ((halfrev>= 18750 ) & (halfrev< 20000 )){ cranktime = 16770 ;} // 1600
if ((halfrev>= 17645 ) & (halfrev< 18750 )){ cranktime = 15686 ;} // 1700
if ((halfrev>= 16666 ) & (halfrev< 17647 )){ cranktime = 14759 ;} // 1800
if ((halfrev>= 15789 ) & (halfrev< 16666 )){ cranktime = 13912 ;} // 1900
if ((halfrev>= 15000 ) & (halfrev< 15789 )){ cranktime = 13166 ;} // 2000
if ((halfrev>= 14285 ) & (halfrev< 15000 )){ cranktime = 12460 ;} // 2100
if ((halfrev>= 13636 ) & (halfrev< 14285 )){ cranktime = 11818 ;} // 2200
if ((halfrev>= 13043 ) & (halfrev< 13636 )){ cranktime = 11231 ;} // 2300
if ((halfrev>= 12500 ) & (halfrev< 13043 )){ cranktime = 10715 ;} // 2400
if ((halfrev>= 12000 ) & (halfrev< 12500 )){ cranktime = 10233 ;} // 2500
if ((halfrev>= 11538 ) & (halfrev< 12000 )){ cranktime = 9807 ;} // 2600
if ((halfrev>= 11111 ) & (halfrev< 11538 )){ cranktime = 9382 ;} // 2700
if ((halfrev>= 10909 ) & (halfrev< 11111 )){ cranktime = 9151 ;} // 2750
if ((halfrev>= 10344 ) & (halfrev< 10909 )){ cranktime = 8597 ;} // 2900
if ((halfrev>= 10000 ) & (halfrev< 10344 )){ cranktime = 8288 ;} // 3000
if ((halfrev>= 9677 ) & (halfrev< 10000 )){ cranktime = 8005 ;} // 3100
if ((halfrev>= 9375 ) & (halfrev< 9675 )){ cranktime = 7750 ;} // 3200
if ((halfrev>= 9090 ) & (halfrev< 9375 )){ cranktime = 7510 ;} // 3300
if ((halfrev>= 8823 ) & (halfrev< 9090 )){ cranktime = 7284 ;} // 3400
if ((halfrev>= 8571 ) & (halfrev< 8823 )){ cranktime = 7071 ;} // 3500
if ((halfrev>= 8333 ) & (halfrev< 8571 )){ cranktime = 6870 ;} // 3600
if ((halfrev>= 8108 ) & (halfrev< 8333 )){ cranktime = 6680 ;} // 3700
if ((halfrev>= 7894 ) & (halfrev< 8108 )){ cranktime = 6500 ;} // 3800
if ((halfrev>= 7692 ) & (halfrev< 7894 )){ cranktime = 6329 ;} // 3900
if ((halfrev>= 7500 ) & (halfrev< 7692 )){ cranktime = 6166 ;} // 4000
if ((halfrev>= 7317 ) & (halfrev< 7500 )){ cranktime = 7195 ;} // 4100
And here is an other wersion (the one I use for the moment):
//Following calculations are based on a excell sheet with the advance curve attached.
halfrev= halfrevGlobal; //Transfer global variable value to a lokal for less memory usage ?.
if ((halfrev<= 100000)& (halfrev>= 75000 )){ //Advance from -3 to 9 @ 300-399 rpm
cranktime=(halfrev+600/1000)-dwellTime;}
if ((halfrev<= 75000 ) & (halfrev> 50000 )){ ///Advance from 9 to 7 @ 400-599 rpm
cranktime=(halfrev+456/1000)-dwellTime;}
if ((halfrev<= 50000 ) & (halfrev> 42857 )){ ///Advance from 7 to 7 @ 600-699 rpm
cranktime=(halfrev+472/1000)-dwellTime;}
if ((halfrev<= 42857 ) & (halfrev> 27273 )){ ///Advance from 7 to 9 @ 700-1199 rpm
cranktime=(halfrev+482/1000)-dwellTime;}
if ((halfrev<= 27273 ) & (halfrev> 17647 )){ ///Advance from 9 to 17 @ 1100-1699 rpm
cranktime=(halfrev+507/1000)-dwellTime;}
if ((halfrev<= 17647 ) & (halfrev> 10909 )){ ///Advance from 17 to 26 @ 1700-2749 rpm
cranktime=(halfrev+485/1000)-dwellTime;}
if ((halfrev<= 10909 ) & (halfrev> 9091 )){ ///Advance from 26 to 28 @ 2750-3299 rpm
cranktime=(halfrev+447/1000)-dwellTime;}
if ((halfrev<= 9091 ) & (halfrev> 7500 )){ ///Advance from 28 to 29 @ 3300-3999 rpm
cranktime=(halfrev+427/1000)-dwellTime;}
if ((halfrev<= 7500 ) & (halfrev> 7317 )){ ///Advance from 29 to 0 @ 4000-4100 rpm (rev limitation)
cranktime=(halfrev-281/1000)-dwellTime;}
Wich way is the best for my application?
I have attached the new code and
Do be careful not to take the input voltages below ground. Over time
this can stress the input protection circuitry, causing premature failure.
IDo you have any advice how to address this? Using a 330ohm resistor maybe?
One last thing, I believe the dwell time is suppose to be the time that
the coil is being charged before the flyback.
Yes, that I know and I have that in my calculations and code.
Also make sure you driving transistors are rated for at lest 1Kv when
they turn off.
I am using an Bosch VAG coilpack whit built in transistor logic (igniter). I hope that will turn out fine because MegaJolt uses them also.
Have a nice day!
Arduino_EIS_160131.ino (8.12 KB)