I wrote this program to run a propane injection solenoid on my forklift. It reads 3 analog inputs (throttle position sensor, manifold pressure sensor and a tuning pot) combine the values and multiply them by four to get a number between 0 and 12000 and assign this to the variable inj. An interrupt is then triggered by a hall sensor switching a 2n2222 and grounding pin 2 (the interrupt pin). The ISR then pulses pin 12 high for the duration of the value of inj in microseconds.
For bench testing all 3 of the analog input pins are tied up to 4.2V and i am using an atiny to pulse pin 2 high then low one second on one off to stand in for the hall sensor during testing. I have an LED tied to pin 12 to stand in for the injector solenoid.
My problem is that i am not getting an output signal on pin 12.
I have tried manually switching ground on and off on pin 2, checked that my analog inputs are in fact getting 4.2V and tested the LED to ensure it works.
Im not so sure about my interrupt setup as this is my first time doing this.
Any help would be appreciated.
const byte interruptPin = 2; //this is the interrupt pin hall sensor//
int mpPin = A3; //manifold pressure sensor//
int tpsPin = A4; //throttle position sensor//
int tunePin = A5; //tune pot 10k//
volatile byte inj; //this will end up being the duration of the injector pulse//
int mpValue = 0; //setting manifold variable to zero//
int tpsValue = 0; //setting throttle positon sensor value to zero//
int tuneValue = 0; //setting tune value sensor variable to zero//
int injValue = 0; //setting injection variable to zero//
void setup(){
pinMode (12, OUTPUT); //this is the pin that fires the injector//
pinMode(interruptPin, INPUT_PULLUP); //set the interrupt pin to high pull up //
attachInterrupt(digitalPinToInterrupt(interruptPin), shot, FALLING); //set the interrupt to trigger shot isr on low//
}
void loop() {
tpsValue = analogRead(tpsPin); //read the throttle positon sensor//
mpValue = analogRead(mpPin);//read the manifold pressure sensor//
tuneValue = analogRead(tunePin); //read the tune sensor//
injValue = (tpsValue + mpValue + tuneValue) * 4; // add the three sensors together and assign the value to inj//
noInterrupts();
inj = injValue;
interrupts();
}
void shot () {
digitalWrite, 12, HIGH; // initilize injector powerup//
delayMicroseconds(inj); //delay the calculated value in microseconds//
digitalWrite, 12, LOW; //shut down the injector//
}