Author Topic: Need to generate precise pulses; what device/micro?  (Read 3175 times)

0 Members and 2 Guests are viewing this topic.

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 403
  • Country: us
Need to generate precise pulses; what device/micro?
« on: February 02, 2026, 07:01:08 pm »
Greetings all,

I am working on a project that involves a 32cc 4-cycle engine. I want to ultimately run this engine on electronic ignition and electronic fuel injection. How I do this is not important at the moment, but this presents a problem that I dont know how to approach yet.

I need to generate control signals for the ignition and fuel injector at precise points relative to a hall/inductive sensor. The complication is that I need to control the pulse width of the fuel injector signal, and the exact timing of the ignition signal.

The max engine speed will be around 3600 rpm, so 60 rotations per second, and 30 cycles per second. That is about 16.6 ms per rotation and 33ms per cycle. I dont know how long the injector pulse will need to be, the injector is meant for more than 32cc, so the pulse might be pretty short. For the ignition I want dynamically adjustable timing, for example at idle the spark is at 5 deg before TDC and at 3600rpm the spark is at 30 deg. The relation between spark and  the sensor is dependent on both engine speed and desired ignition advance.

So after that long-winded explanation of what I am trying to acheive, what microcontrollers or processors have the capability to generate precise synchronous signals like this? At first I wanted to use a raspberry pi pico, because it is familiar and cheap, but I am concerned about its ability to do this while also running a bunch of other stuff. Could I run a bunch of timers and interrupts on the second core? I have never really leveraged the second core on a pico.
 

Online jbb

  • Super Contributor
  • ***
  • Posts: 1335
  • Country: nz
Re: Need to generate precise pulses; what device/micro?
« Reply #1 on: February 02, 2026, 07:09:05 pm »
Maybe there’s an open-source Engine Control Unit (ECU) project? Someone might have already done some setup for you
 

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 403
  • Country: us
Re: Need to generate precise pulses; what device/micro?
« Reply #2 on: February 02, 2026, 07:21:43 pm »
That is true, I need to look into that more. Actually I think somebody has made an ECM with and arduino, not sure how that works. 
 

Offline free_electron

  • Super Contributor
  • ***
  • Posts: 9053
  • Country: us
    • SiliconValleyGarage
Re: Need to generate precise pulses; what device/micro?
« Reply #3 on: February 02, 2026, 07:26:41 pm »
a micro with hardware PWM block. or roll your own in a small CPLD
Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 

Online PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 3373
  • Country: au
Re: Need to generate precise pulses; what device/micro?
« Reply #4 on: February 02, 2026, 07:38:17 pm »
So after that long-winded explanation of what I am trying to acheive, what microcontrollers or processors have the capability to generate precise synchronous signals like this? At first I wanted to use a raspberry pi pico, because it is familiar and cheap, but I am concerned about its ability to do this while also running a bunch of other stuff. Could I run a bunch of timers and interrupts on the second core? I have never really leveraged the second core on a pico.

10us is about 0.2 degrees, so any MCU can manage that timing in HW easily enough.

Since you know the Pico, the PIO's on the Pico2 should manage this? 
Or a MCU with config logic blocks?

Or, you can use multiple PWMs/timers.
You need to capture the sensor for RPM/phase, and then a good MCU allows prescale of the output PWM, so you can set PWM full scale to appx 360 degrees.
Such ranging would allow the timing to work down to cranking speeds.
PWM can position edges, but they are not so good at arbitrary pulse generate, so you may need simple external logic to create a pulse from 2 edges.


How many pulses do you need, and how many sensors?

« Last Edit: February 03, 2026, 12:00:57 am by PCB.Wiz »
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 5811
  • Country: dk
Re: Need to generate precise pulses; what device/micro?
« Reply #5 on: February 02, 2026, 07:54:49 pm »
That is true, I need to look into that more. Actually I think somebody has made an ECM with and arduino, not sure how that works.

https://github.com/speeduino/speeduino
 

Offline PGPG

  • Super Contributor
  • ***
  • Posts: 1343
  • Country: pl
Re: Need to generate precise pulses; what device/micro?
« Reply #6 on: February 02, 2026, 11:36:29 pm »
The max engine speed will be around 3600 rpm, so 60 rotations per second, and 30 cycles per second. That is about 16.6 ms per rotation and 33ms per cycle.

In 1988 we have build EPROM programmer based on 8748 8 bit microcontroller. It had no UART integrated so serial communication had to be done by code. We reached 57600 bps so during 17us several things happened (selecting next bit from data byte, checking if whole byte was already send,...). 16.6ms is 1000 times longer time so each microcontroller should be able to do everything that is needed, I think.
 
The following users thanked this post: pardo-bsso

Online gamalot

  • Super Contributor
  • ***
  • Posts: 1947
  • Country: au
  • Correct my English
    • Youtube
Re: Need to generate precise pulses; what device/micro?
« Reply #7 on: February 02, 2026, 11:44:03 pm »
I'd guess that most MCUs' timers and PWM peripherals should be enough for what you need. If you're looking for higher resolution, you might consider an STM32F334 with HRTIM or a similar type of controller.
I'm a poet, I didn't even know it. |  https://youtube.com/@gamalot | https://github.com/gamalot
 

Offline Haenk

  • Super Contributor
  • ***
  • Posts: 1918
  • Country: de
Re: Need to generate precise pulses; what device/micro?
« Reply #8 on: February 03, 2026, 10:42:19 am »
If an MCU with a processor from the early 80s could do it, a processor from 40 years later certainly will have no problem with the timing.
I think the hard part is not the timing itself, but the non-linear action going on - how fast is the propagation of the flame front after spark, how much fuel has been injected after injection started, how well is it mixed, when is the best time for ignition and so on. There is a reason, why it takes thousands of people to develop an ICE engine, let alone the electronics to drive it.
It certainly can be done, but it will require a lot of expertise to get it "right"; however even a shoddy effort is probably better than a purely mechanical solution.
 

Online SteveThackery

  • Super Contributor
  • ***
  • Posts: 3388
  • Country: gb
  • 50 year novice
Re: Need to generate precise pulses; what device/micro?
« Reply #9 on: February 03, 2026, 11:48:40 am »
I think the hard part is not the timing itself, but the non-linear action going on - how fast is the propagation of the flame front after spark, how much fuel has been injected after injection started, how well is it mixed, when is the best time for ignition and so on.

Engine manufacturers use sophisticated modelling tools to help nail down those parameters you discuss. After that will be extensive dyno testing for fine tuning. Amateurs or model engineers need to use informal judgements on how well the engine is running. It is also fairly easy to couple a generator to the engine with a variable electrical load, in order to adjust the engine parameters over a range of loads.

Unless we are discussing direct injection, the timing of fuel into the inlet tract is rarely critical (unless it is actually during the intake stroke). The old Bosch K-Jetronic, for example, injected fuel continuously. Later FI systems used bank injection, where two or more injectors would actuate simultaneously (therefore at different times with respect to the four-stroke cycle). More modern engines use timed injection for each cylinder, but they have to comply with tight emissions standards, unlike a typical model engine.

We also need to check what fuel is being used. For example, the electronic fuel injection system I'm working on (for a 60cc model engine) uses propane, because it mixes more easily with the air. Gasoline injection at these small volumes is more difficult because it must be atomised for optimum running, and that takes a certain amount of energy.

There is a reason, why it takes thousands of people to develop an ICE engine, let alone the electronics to drive it.

Yeah, true, but if this is a hobby engine with no emissions requirements it can all be done easily enough. My engine runs off an Arduino Nano Every.
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 5811
  • Country: dk
Re: Need to generate precise pulses; what device/micro?
« Reply #10 on: February 03, 2026, 02:17:47 pm »
Unless we are discussing direct injection, the timing of fuel into the inlet tract is rarely critical (unless it is actually during the intake stroke). The old Bosch K-Jetronic, for example, injected fuel continuously. Later FI systems used bank injection, where two or more injectors would actuate simultaneously (therefore at different times with respect to the four-stroke cycle). More modern engines use timed injection for each cylinder, but they have to comply with tight emissions standards, unlike a typical model engine.

even for direct injection timing is not that critical, 10us is less than half degree for for most realistic rpms
banked injetion usually injects once per engine rotation, avoiding the need for a cam shaft sensor to get the phase of the engine, while ensuring that all cylinders get the same two injections per four cycles 
 

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 403
  • Country: us
Re: Need to generate precise pulses; what device/micro?
« Reply #11 on: February 03, 2026, 02:41:43 pm »
Lots of good info and discussion here, thanks!

The engine will be directly coupled to an alternator from a car, so running the engine under load for in-depth testing should be really easy. I can see how much power the engine is producing is real time like a dyno.

I have not really decided how to do the fuel injection timing. I thought for such a small single cylinder engine with a tiny intake path the injection would be timed such that it sprays directly into the intake port during the intake stroke. My worry is that injecting fuel on each rotation would cause problems, but what do I know. There is more research to be done here I think.

Somebody mentioned using propane as the fuel, that would be an interesting thing to test. I could see it working better at this small scale.
 

Online SteveThackery

  • Super Contributor
  • ***
  • Posts: 3388
  • Country: gb
  • 50 year novice
Re: Need to generate precise pulses; what device/micro?
« Reply #12 on: February 03, 2026, 02:47:26 pm »
even for direct injection timing is not that critical, 10us is less than half degree for for most realistic rpms

Indeed - it depends on how you define "critical". Tens-of-microseconds will definitely be sufficient precision for the OP's engine, unless it is very unusual. I bet it isn't direct injection, though: I haven't seen that on any model engine apart from diesels and hot bulb / hot tube engines.
 

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 403
  • Country: us
Re: Need to generate precise pulses; what device/micro?
« Reply #13 on: February 03, 2026, 02:58:58 pm »
You are correct, the engine is not direct injected. I sourced the engine from an older craftsman yard tool like an edger or weed wacker. It is a pretty generic carbureted 4 stroke engine, actually impressive that 4 strokes of this size are produced in decent numbers and are pretty cheap on ebay.
 

Offline coromonadalix

  • Super Contributor
  • ***
  • Posts: 8817
  • Country: ca
Re: Need to generate precise pulses; what device/micro?
« Reply #14 on: February 03, 2026, 03:35:05 pm »
mmm you had / have  open ecu projects    with arduino boards, or more powerful ones

surely some ideas can be taken from theses projects ?


some stm32 devices can pulse very fast, always depend on the code and optimization(s)
 

Offline Picuino

  • Super Contributor
  • ***
  • Posts: 1469
  • Country: es
    • Picuino
Re: Need to generate precise pulses; what device/micro?
« Reply #15 on: February 03, 2026, 03:57:09 pm »
8-bit PIC microcontrollers usually have fairly advanced peripherals for pulse control, but they may be a little small if you want to add large programmes, and you will need a special programmer (Pickit 3).

The Arduino UNO processor (Atmega328, 8 bits) is also fast enough, and you can find a lot of information about it online.

The 32-bit STM32s are more powerful and faster, but more difficult to program, especially if you want to achieve very precise timing.

What experience do you have with microcontrollers? Because that should also be taken into account when making your decision.
 

Offline coromonadalix

  • Super Contributor
  • ***
  • Posts: 8817
  • Country: ca
Re: Need to generate precise pulses; what device/micro?
« Reply #16 on: February 03, 2026, 05:01:18 pm »
some Nucleo  stm32 dev boards do include the stlink 2,  you can snap it off  and keep it as a programmer

we have designed a pulse generator for some projects,  alas closed source, a small nucleo 432kc (usb stlink 2 programmer on it)   ... 

all coded in arduino v2.x  ide ... just add stm32 librairies in it ...  more recent designs changes use the same mcu,  but use an external st-link 3 minie  who don't cost a fortune

but it is not synced with anything, it is a stand alone generator
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 5811
  • Country: dk
Re: Need to generate precise pulses; what device/micro?
« Reply #17 on: February 03, 2026, 05:21:14 pm »
a single cylinder not very high rpm engine is not problem for all most any mcu with a simple timer, it simple doesn't need to be that accurate

but, that said by far the easiest is to take something like speeduino. It takes care all the other stuff you also have to do, like fuel maps, ignition maps, timing triggers, etc.
 

Offline Andreas

  • Super Contributor
  • ***
  • Posts: 3582
  • Country: de
Re: Need to generate precise pulses; what device/micro?
« Reply #18 on: February 03, 2026, 07:25:15 pm »
Maybe there’s an open-source Engine Control Unit (ECU) project? Someone might have already done some setup for you
Hello,

search for the "megasquirt" project. (But I am not shure if it handles more than 1-2 cylinders).

I dont know how long the injector pulse will need to be, the injector is meant for more than 32cc, so the pulse might be pretty short.
This might be a problem (especially with high ohmic injectors i.e. without booster cirquit) since the timing at low quantities is very inaccurate (non linear) and depends on battery voltage. Usually there is a minimum usable opening time.

Usually the timing for combustion engines is done either by a gate array (long time ago)
or by a specialized timer array like "TPU" "PCP" or "GTM"

Example processor: https://www.infineon.com/products/microcontroller/32-bit-tricore/aurix-tc3xx/tc37xtp

I'd guess that most MCUs' timers and PWM peripherals should be enough for what you need. If you're looking for higher resolution, you might consider an STM32F334 with HRTIM or a similar type of controller.

Not shure about that. For static engine speed this might be ok. But Engine speed can vary dramatically during start or even by compression cycle. So in fact you need adjustments during rotation to hit the right "angle" for the ignition.

with best regards

Andreas
« Last Edit: February 03, 2026, 07:43:49 pm by Andreas »
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 17264
  • Country: de
Re: Need to generate precise pulses; what device/micro?
« Reply #19 on: February 03, 2026, 08:24:06 pm »
The pulse genration itself can be from hardware timers. That part is easy with µC that have enough timers (some may need 2 channels for start and stop).

For a variable speed the µC would likely have to run some PLL type code and rescale the timings accordingly. For this it can get a bit tricky with an older 8 bit µC. An ARM class µC should however be plenty.
The interpolation of table values may also want some processing power (e.g. HW multiply).
 

Online PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 3373
  • Country: au
Re: Need to generate precise pulses; what device/micro?
« Reply #20 on: February 03, 2026, 09:44:40 pm »
At first I wanted to use a raspberry pi pico, because it is familiar and cheap, but I am concerned about its ability to do this while also running a bunch of other stuff. Could I run a bunch of timers and interrupts on the second core? I have never really leveraged the second core on a pico.

Google finds this code example for the RP2350, which uses the improved PIO to read two timing-delay parameters and pass flags to another state engine.
https://forums.raspberrypi.com/viewtopic.php?t=375677

The PIO has 32bit counters so has very wide dynamic range, (eg a 24ns loop has a full scale of 103 seconds) so you may want to add a sensor-watchdog type feature that can force exit from a wait loop on a flag. This forces the code to a known wait point and avoids unexpected very long timer waits.

Quote
I need to generate control signals for the ignition and fuel injector at precise points relative to a hall/inductive sensor. The complication is that I need to control the pulse width of the fuel injector signal, and the exact timing of the ignition signal.

This could be 3 PIO state engines :
One that manages hall/inductive sensor to generate fixed delay and alternating ignition and fuel zero/trigger flags and maybe out of range exit flags. Can be pins for easy debug.
plus one state engine for each of ignition and fuel that have your variable delays and widths, with watch-dog delay loop exits.


 

Online SteveThackery

  • Super Contributor
  • ***
  • Posts: 3388
  • Country: gb
  • 50 year novice
Re: Need to generate precise pulses; what device/micro?
« Reply #21 on: February 03, 2026, 09:48:30 pm »
I dont know how long the injector pulse will need to be, the injector is meant for more than 32cc, so the pulse might be pretty short.
This might be a problem (especially with high ohmic injectors i.e. without booster cirquit) since the timing at low quantities is very inaccurate (non linear) and depends on battery voltage. Usually there is a minimum usable opening time.

It goes without saying that the necessary injector pulse duration depends on the pressure from the fuel injection pump. I think a good place to start would be a scrap motorcycle - choose the smallest possible engine size that you can find with fuel injection. Motorcycle FI pumps typically operate around 45psi, and it would be very sensible indeed to use the injector that is fitted to the motorcycle.  Even if you can't find a suitable scrap bike, spares will be available on eBay.

For what it's worth, the pulses I feed the gas valve on my model engine vary from 9ms at 600rpm idle (zero load) to 15ms when the engine is running at zero load at 1500rpm (my chosen maximum speed). When operating with a full load (wide open throttle, 800rpm) the pulse duration goes up to 24ms.

All injectors have an operate lag and a release lag. But you don't need to worry about that, because you will have to develop your own fuel map, and that automatically takes into account the injector lags.  Let me explain....

My software has a "setup" mode where the injector pulse duration is under the control of a potentiometer. The engine has a simple output-only diagnostic port which sends the engine rpm, the throttle opening, and the injector duration as a continuously repeating text string back to the host PC (Serial.print()). I mess with the pot until the engine starts, then operate the engine over a range of speeds and loads (throttle openings). For each speed/load combination I adjust the pot to get the optimum performance, and then make a note of the injector pulse duration. Thus I accumulate the raw data for the fuelling map, which I then include in the Arduino software.

Despite what you might think, the ignition timing has a surprisingly small overall effect unless it is a long way from optimum. Too advanced increases heat loss to the cooling system, too retarded leads to excess heat going into the exhaust valve and exhaust header. As a general rule, weaker mixtures burn more slowly so need more ignition advance.
 
The following users thanked this post: PCB.Wiz

Online SteveThackery

  • Super Contributor
  • ***
  • Posts: 3388
  • Country: gb
  • 50 year novice
Re: Need to generate precise pulses; what device/micro?
« Reply #22 on: February 03, 2026, 09:54:59 pm »
search for the "megasquirt" project. (But I am not shure if it handles more than 1-2 cylinders).


It handles eight, depending on the model. Megasquirt is great, but way over the top for this little project. Speeduino would be a better place to start, but honestly I think the OP would have a lot of fun starting from scratch.
 

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 403
  • Country: us
Re: Need to generate precise pulses; what device/micro?
« Reply #23 on: February 03, 2026, 10:11:59 pm »
It sounds like you may have a lot of knowledge on this sort of topic Steve, that may prove to be useful, thanks!  :-+

It looks like right now I need to do some research and testing, I have some of the parts for the engine setup but it is not assembled yet. I currently live in an apartment with a garage that I am renting, I still need to set up a workshop space.

I found this injector on ebay: https://www.ebay.com/itm/316477819004  it seems to be the smallest I can find, no idea what the quality is like. I also don't know if I need to try to find the smallest (least flow) injector as long as I can pulse a larger injector fast enough. Do you have any recommendations for a fuel pump? I found this: https://www.ebay.com/itm/263768997712 , it is a gear pump, so in theory it should be able to generate pressure, but I think these pumps are only designed for refueling RC vehicles, no pressure required. alternatively there are cheap automotive inline fuel pumps meant for EFI.

For such a simple system with only a fuel injector, throttle blade, and some timing pickups, I would like to build a system from scratch. This engine and alternator is going to be installed in a 4 foot RC boat, which itself is all scratch built. The diy and open source EFI systems are cool though.
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 19227
  • Country: us
  • DavidH
Re: Need to generate precise pulses; what device/micro?
« Reply #24 on: February 03, 2026, 10:13:26 pm »
The max engine speed will be around 3600 rpm, so 60 rotations per second, and 30 cycles per second. That is about 16.6 ms per rotation and 33ms per cycle.

10us is about 0.2 degrees, so any MCU can manage that timing in HW easily enough.

I am going by memory here.

As I recall, the PIC uses a 4-phase clock so a 1 microsecond instruction cycle at 4 MHz, and can operate at say 20 MHz, so could have a 200 nanosecond instruction cycle.  That is way more than fast enough, with plenty of processing time left over.  An AVR should perform similarly.

I would use a separate microcontroller dedicated to the ignition and injector timing, programmed at the hardware level although there might be a suitable real-time OS available.  I have done this in the past with PIC, with the main loop precomputing the next set of operations, which are then interrupt driven through the timer.  The precomputation includes phase locking to the crankshaft and camshaft, so position sensors are required.  Today I would probably use AVR for simplicity over ARM.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->