I have been reading and studying Arduino for a bit since I need means of automating my bachelor’s thesis, electronics is not my field of study. I will briefly explain it so the function of the device becomes clear.
The idea is to control one fuel injector (similar working principle of a solenoid) in a way to make counted injection numbers to obtain a fuel volume eg. Cycle 1 would have 10000 injection events that last 4ms each. Cycle 2 would have 5000 events that last 8ms each. After each injection cycle, the device will wait for 10s for the measuring device (5kg load cell) to stabilize and take a reading from it.
The power management part of the switching will be made with an IRLZ44n MOSFET.
The issue I’m facing right now after reading a bunch about interrupts, millis function, and trying different approaches is being able to emit accurate pulse widths to open the injector while also measuring the injection counts within the Arduino to precisely control the number of injection cycles performed.
After trying out different approaches, it seems like adding lines of instruction, at times, reduces the accuracy of the pulse width (currently measuring with a scope). With simple instructions, it seems like I get pretty decent pulse widths (within 2.00ms to 2.1ms). When I enable the other lines of code I had in place in order to measure frequency, period and calculate the available time, also using a virtual rpm to recreate the injection speed of a running motor, the code seems to “slow down” and make the 2ms pulse become a 2.4 ms pulse. Since I’m running many injection cycles in order to measure injected fuel mass, a small error in pulse-width would mean a big error in the total mass.
The actual question I have is:
How can I accurately demand pwm pulses with varying on/off times while also providing feedback to the Arduino in order for the device to be able to count the injection pulses and take actions based on them?
Thanks in advance for any help.