this is the gms very first start it has a kind of automatic handling of the injector timing to reach the rpm we set by the analog/digital accelerator
still missing linking the acceleration with the max time of the injector but already would work with one injector
missing the output for the other solenoids for air and exhaust
i guess the order for injection should be first air than hydrogen than exhaust or reverse this way there is aways air or exhaust on the line between the hydrogen output making it safe for not having back fire in the cell (for the case of using the 3 injectors design)
i´m using an analog input interrupt as the rpm counter and the injector triger goes into the digital interrupt (the analog interrupts dont interrupts the external interrupts digital pin one and 2)
there are two ranges of adaption when you change the rpm one that is faster when the difference in rpm is greater than 50 rpm and one that is fine when the rpm is within 5 rpm difference... (it will always happen some difference)
i had to reintegrate the timer to use the millis to better count the rpm but its ok because its working very nicely now since appears that as the signal trigger to the injector comes from the interrupt it dont have any delays or inconsistency in the pulse!
it turns out that if i want to use the arduino nano it will require a safe logic to determine each injector will be firing
the nano having only two interrups can deal only with two injectors trigger directly for more only adding logics
an arduino mega has 4 interrupts or esp 32 could do everything we want and probably faster
i have a few spare and i plan to get a code for it too as esp32 have as many interrupt as needed
the only side effect is that is 3,3v logic so it require some resistors to work safe with 5 volts logic basically or those level converters not by far a problem
the esp 32 is multicore aparently too
so as you see i´m doing some advance on the GMS
whos gona test? i dont have a working engine.. nor money to get injectors or other stuff (trying to work on that but is not being easy and probably if the money come my time will go because i´m probably starting a new company that deals with refrigeration systems , when i get funds it will explode! but my investors certainly wont let me work anyelse project for while so i´m focusing now)
if some of you could maybe do a nice donations i could get some of the parts and try doing the tests needed, now i´m 33 and after 13 years working on this i got a lot of energy and knowledge from this time spend but at the same time i didnt focused in making money consistently so at this point of my life i have no money spare.. all i have is a fiat uno 2003 lend from my dad, my test equipments, and work on the streets selling homemade beer to live... also fix some equiments and do some other jobs that appears but is hard getting the end of the month, if werent for my parents surely i could not be here today writing this now. So if any of you feel the value of what we are constructing here, the knowledge that we are developing here feel free to help and be an active part on this at this very special moment because i still have energy and yet time to invest. All this components i have here to work with except for the ones 2 or 3 people send to me i got over the years at the moments that i had some money spare so i converted to components spare becuase i know that when i didnt have the money because spend elsewhere i would not be able to do anything latter with no components.
the link for the donations is in thru this pages and i wont be repeating it everywhere first to not get the risk of losing what i write eventually because there are certain links that simply make everything i wrote disappear and to not disturb the discussion. So if you please want to donate go back thru this pages, read the content and if you feel you can please help... every dollar or euro is more than 4 reais.... and everything we buy from outside here cost up to 4 times what cost for you there not taking account the conversion! So if you want to send me injectors, or whatever you have that you feel it could help me just give me a message and i send you the address coordinates for the mail.
unsigned long newtime=0;
// inputs
int accel = A0; // analog/digital accelerator signal
int pressure = A1;
int clocksignal = 3; // //input interrupt 1 / pin 3
int injector = 13; // injector output
int rpmreadpin= A2;
unsigned int rpmread = 0;
int rpmset = 0; // rpm determined by analog/digital accelerator
String state;
float injectiontime = 5; //ms injection timming
float timeincrement = 0.001;
float timedecrement = 0.001;
int mininjectiontime = 1;
float maxinjectiontime=10;
int maxrpmset=6000;
int minrpmset=1000;
int stable=50;
int finestable=5;
float finetimeincrement = 0.00001;
float finetimedecrement = 0.00001;
volatile unsigned int newPos;
volatile unsigned int count=0; // analog2 interrupt rotine counter rpm read signal
bool rpmstate=0;
bool lastrpmstate=1;
volatile int clockcount;
int lastclockcount;
int avecount;
int average1;
int average2;
int average3;
int average4;
void setup() {
DDRB |= 0B00100000; // pinMode(injector, OUTPUT); pin 13
Serial.begin(9600);
pinMode(clocksignal, INPUT_PULLUP);//d3
pinMode(rpmreadpin, INPUT);//A2
//cli();
//TIMSK0 &= ~(1 << TOIE0); // disble timer
//sei();
PCICR |= (1 << PCIE1); // This enables Pin Change Interrupt 1 that covers the Analog input pins or Port C.
PCMSK1 |= (1 << PCINT10) | (1 << PCINT11); // This enables the interrupt for pin 2 and 3 of Port C.
attachInterrupt(1, INJECTION, RISING);
}
ISR(PCINT1_vect) {
count++;
}
void loop() {
rpmset=constrain((analogRead(accel)*6),minrpmset ,maxrpmset); // rpm determined by analog/digital accelerator
if (rpmset > (rpmread + stable)) {
state="Accelerating" ; // injection time increase
injectiontime=constrain((injectiontime+timeincrement),1,10);
} else if ( rpmset < (rpmread-stable)) {
state="Deaccelerating"; // injection time reduce
injectiontime=constrain((injectiontime-timedecrement),mininjectiontime,maxinjectiontime);
} else {
state="Stable";
if (rpmset > (rpmread + finestable)) {
state="fineAccelerating" ; // injection time increase
injectiontime=constrain((injectiontime+timeincrement),1,10);
} else if ( rpmset < (rpmread-finestable)) {
state="fineDeaccelerating"; // injection time reduce
injectiontime=constrain((injectiontime-timedecrement),mininjectiontime,maxinjectiontime);
}
}
if (millis() > newtime+500 ){
newtime=millis();
rpmread=count*12;
avecount++;
if (avecount == 1)average1=rpmread;
if (avecount == 2 )average2=rpmread;
if (avecount == 3 )average3=rpmread;
if (avecount == 4 ){
average4=rpmread;
avecount=0;
}
rpmread=(average1+average2+average3+average4)/4;
printcallback() ;
count=0;
}
}
void INJECTION() { //interrupt routine
PORTB |= 0B00100000; //digitalWrite(injector, HIGH);
delayMicroseconds(injectiontime*1000);
PORTB &= 0B11011111; // digitalWrite(injector, LOW);
}
void printcallback() {
Serial.print("Accelerator ");
Serial.print(rpmset);
Serial.println(" RPM SET");
Serial.print("Injection Time ");
Serial.print(injectiontime);
//Serial.print(injectiontime);
Serial.println(" miliseconds");
Serial.print(rpmread);
Serial.println(" RPM Measured ");
Serial.println(state);
}