There comes a time... (DIY Electronic Ignition)

Sonreir said:
Yeah, that's what I figured. At 15,000 RPM each rotation is taking 4000 microseconds, so that allows me (potentially) around 1000 instructions between rotations. Double it if I run from the cam instead of the crank.

A thousand lines in assembly is easily enough headroom. Still, I would start using a basic compiler and write it in C. Don't worry too much about instruction time and such. Use a scope and you'll know if you are within your calculated time. Setup a basic interrupt routine and ping an output periodically. Add a bunch of NO-OP lines until it is at the max of the clock. I think you're already prototyping it with the LED blinker. But try it in C.
 
you run an isr off the crank sensor, that solves any timing issues, and without an o-scope, it's going to be a nightmare to eliminate back emf off the coils to get a reliable ignition... if you've got both those issues addressed, my apologies, I didn't read through the whole thread. but as far as ignitions, been there, done that, full electronic advance, etc etc, realized it's simpler and more reliable to just buy one that's already been debugged and proven in the field
 
I'm still deciding on the crank sensor. I'm concerned about running it on the stator side due to the EMF and so I'm looking at maybe using a gear tooth counter instead? Dunno yet... Flyback is currently handled by a purpose-made automotive transistor that was designed to trigger coils (both ignition and injectors) and so I'm hoping that will fit the bill. I may run some extra resistance from the emitter to the base just in case, though.

Anyway... I'm making some good progress on the code, but I've had to switch microcontrollers. The 16F84A only provides 68 bytes of data memory and 1K of program memory. The 16F88 brings the program memory up to 368 bytes and the data memory to 4096 byes. A HUGE help considering I've taken eyhonda's advice and switched over to embedded C. So far in my simulations, TMR0 with a prescaler of 8 has been sufficient resolution to calculate out the timing. I may have room to switch the prescaler to 4, but I'm trying to be careful as I'm running interrupts from the hall sensor and from the internal timer and because timing is so important here, I really want to avoid interrupting an interrupt.
 
What tools are you using for writing, compiling and programming? Basically, how are you debugging now at this stage? Are you using an ICE or just edit/compile/flash for every iteration of code? It's usually easier to just do the edit/compile/flash/check routine. ICE (in-circuit emulator) is good for learning quickly how the micro works and where it goes (memory stacks, interrupts, etc). With an emulator, you just edit/save/run/check. It's faster but (I think) more expensive. A lot of the companies I worked for (Tier 1 suppliers) had a lot of tools at our disposal. So, I got to play with emulators. If you edit and flash, you have to have a programming port on your board and the programmer hooked up. Anyway, just wondering how your doing it with a PIC. You should have the PIC installed on a socket. So, an ICE would be easy to use in it's place.
 
I'm currently using an ICE, yeah. I'm using MPLAB which provides a free version of the Hi-Tech C Compiler that works with PIC 10/12/16 MCUs. MUCH better than having to burn and test for sure; especially because I don't have an oscilloscope and so I'm relying heavily on the ICE to get me in the ball park before my real world testing.
 
Nice! So, depending on what it can display, you should be able to see everything going on in the micro. Does it run real-time? Can it measure pulsewidth output (in place of a scope)? Maybe you can write a small routine to output time stamp data serially or save time data in the eeprom at specific intervals. As long as that routine doesn't add too much time, it should be reasonably accurate.

Wow, no scope? I would have a really hard time without one. A scope is about as essential (to me) as a multimeter and soldering station. I would be shopping for one on CL. I think you can even get your PC to run as a scope with some hardware.
 
It actually runs faster than real time but provides a StopWatch utility that gives me an output of the Program Counter, elapsed time in µs, and elapsed cycles. I can "zero" it and reset it at anytime. Also, I can display the contents of any memory cell in hex, binary, and decimal so it's a nice tool considering the price (free). Finally, the provision for breakpoints has been a real bonus and I'm not sure how I used to program without them. Being able to step through the code line by line and watch it execute has been pretty essential for me.

On the down side, it doesn't handle any of the 18 series chips unless you fork over some cash though, so maybe it's more of a hobbyist tool....
 
So, Sonrier.. How's the code coming along? I actually have my code 90% working! It's working on the bench. I have yet to test it on a working motor. I'll post more details. For now, just checking on your progress.
 
I have all the code written and it "mostly" works in the IDE, but working out these timing issues is killing me. Initially, I was trying to do too much in the way of calculations and anything past 8,000 RPM wasn't working because the real-world events were taking place faster than the chip could keep up.

I ended up simplifying a lot of it. Rather than calculating out each of the "break points" where the RPMs have changed enough to require a change in timing, I've entered them as constants so all I need to do is check the current RPM against the RPM I've entered as a variable instead of as a calculated value. Basically, it's a static timing map in memory rather than a calculated one.

This has worked out quite well, but anything above 11,000 RPM is still getting me because I'm still having to do calculations to decide how many µs after the left cylinder to fire the right. My next step is to split this project across three chips. One chip will be input from the Hall sensor and act as master to the other two (one for each cylinder). This isn't saving me a great deal of cycles, but it might be enough to get me to 14,000 RPM (just a guess).

I suppose the other option is to give up on 4Mhz and go for higher clock cycles. ;D
 
Pretty sure top end won't survive at 14K.
You'll probably need Carrillo rods over 12.5K unless pistons are a lot lighter than stock
 
I'm not using an ICE, debugger or simulator. I just edit, compile & flash. Then, I check the I/O with a scope. I have a function generator as the trigger and some LED's on the outputs. My motor is simpler; being a single and having one pulse every cam rotation (every other crank rotation). I'm running at 8mhz clock and a pre scaler of 8. Then, I use both an external and a timer interrupt. The trigger is on the ext int. The timer sets the base time loop of 255 us (8mhz/8 = 1uS * 255 timer0 loops). The ext trigger measures the rpm based on the period. For my app, 130 ms is 900 rpm and 13 ms is 9000 rpm. There are two loop timers; one for rpm and one for delay (advance). Basically, if the period is 130ms and the advance is 1ms, I fire the output after 129ms. The fire pulse is fixed (5ms for now). The advance is based on 720 due the half speed cam. So at 40 degrees advance, I only need 20. At about 6000 rpm, the period is about 20ms. 40 deg advance is about 5% of the period. I wait 95% of the period (19ms) before firing the ignition. The idea is that I can't fire an output in advance but I can after a delay. So the first two pulses calculate the period (rpm) and the advance fire is ahead of the third pulse. The timers are reset every ext interrupt. So far it's working. It's not very accurate since the smallest/shortest delay is only 255us. I tried a prescaler of 1 that makes a timer loop of 32us but it was intermittent pulsing. I'm thinking some math error or overflow is occurring. I think a 255us resolution is ok for now. Next I will try to make a pulse doubler to trigger the tach I have. It is a 2 stroke twin looking for a pulse every rev. My motor is 1 every 2 so I need a double freq to trigger the tach. Also, I'm using the adc to determine voltage levels with 3 LEDS (low/middle/full).
 
Just another couple notes for you. You can power the output transistor directly to the coil. The 12v side of coil will only be on the collector when off and won't affect the 5v levels of the micro. You still need the diode. Don't use a relay to fire the coil. At high rpm, it won't keep up. Remember, it's still a mechanical switch and will have a speed limit.

Good ideas for the shift and redline. I will implement those features too. It will be easy now since I have a continuous rpm calculation. For know, I'll just hard code the numbers in. It's easy to flash new software with ICP. Just a 6 pin connection. Also, the advance is also hard coded in (19 steps). I have two other tables to program (a sport and base table of curves). I have the race curves programmed now.
 
crazypj said:
Pretty sure top end won't survive at 14K.
You'll probably need Carrillo rods over 12.5K unless pistons are a lot lighter than stock

Yeah... I have no plans of going past 11,000 or so and even then, only sparingly. The goal of chasing higher RPMs in code is to help increase the accuracy of the ignition at lower RPMs. The faster I can get the code to execute, the less real-world time will take place between sensor readings and calculations.

[quote author=eyhonda]I'm not using an ICE, debugger or simulator. I just edit, compile & flash. Then, I check the I/O with a scope. I have a function generator as the trigger and some LED's on the outputs. My motor is simpler; being a single and having one pulse every cam rotation (every other crank rotation). I'm running at 8mhz clock and a pre scaler of 8. Then, I use both an external and a timer interrupt. The trigger is on the ext int. The timer sets the base time loop of 255 us (8mhz/8 = 1uS * 255 timer0 loops). The ext trigger measures the rpm based on the period. For my app, 130 ms is 900 rpm and 13 ms is 9000 rpm. There are two loop timers; one for rpm and one for delay (advance). Basically, if the period is 130ms and the advance is 1ms, I fire the output after 129ms. The fire pulse is fixed (5ms for now). The advance is based on 720 due the half speed cam. So at 40 degrees advance, I only need 20. At about 6000 rpm, the period is about 20ms. 40 deg advance is about 5% of the period. I wait 95% of the period (19ms) before firing the ignition. The idea is that I can't fire an output in advance but I can after a delay. So the first two pulses calculate the period (rpm) and the advance fire is ahead of the third pulse. The timers are reset every ext interrupt. So far it's working. It's not very accurate since the smallest/shortest delay is only 255us. I tried a prescaler of 1 that makes a timer loop of 32us but it was intermittent pulsing. I'm thinking some math error or overflow is occurring. I think a 255us resolution is ok for now. Next I will try to make a pulse doubler to trigger the tach I have. It is a 2 stroke twin looking for a pulse every rev. My motor is 1 every 2 so I need a double freq to trigger the tach. Also, I'm using the adc to determine voltage levels with 3 LEDS (low/middle/full).

Just another couple notes for you. You can power the output transistor directly to the coil. The 12v side of coil will only be on the collector when off and won't affect the 5v levels of the micro. You still need the diode. Don't use a relay to fire the coil. At high rpm, it won't keep up. Remember, it's still a mechanical switch and will have a speed limit.

Good ideas for the shift and redline. I will implement those features too. It will be easy now since I have a continuous rpm calculation. For know, I'll just hard code the numbers in. It's easy to flash new software with ICP. Just a 6 pin connection. Also, the advance is also hard coded in (19 steps). I have two other tables to program (a sport and base table of curves). I have the race curves programmed now.[/quote]

I've just upped mine to 20Mhz with a prescaler of 0. We'll see how that works out. I'm running with interrupts on the external (Hall) and on the timer as well. It seems to make the most sense to do it that way.

I've done a few things differently though... I'm running everything in µs rather than ms and calculating out the µs per degree which, of course, changes as a function of RPM. What's really killing me is the programmable dwell, though. I'm having to ground the coil in advance of the advance, if that makes sense.

It just occurred to me, in the typing of this, that I should probably do it a bit differently. I'm hardcoding all the "advance steps" in µs breakpoints with a large conditional statement to jump between them. I suppose I should just be hard coding the µs of advance rather than the degrees of advance. That will save more calculations...

As for the relay, I cut that from the plan a while ago. I ran across the same problem you mention. It's just not fast enough to keep up. Instead, I'm going solid state and I found a transistor I quite like for the task: IRGB14C40L

I don't think switching the coil from most standard transistors will be a good idea. There's A LOT of flyback coming from the coil when you unground it. Several hundred volts, usually.

Anyway... if you wanna look at what I have for code so far, lemme know. I'll email it over. I don't making this a joint project. :)
 
Ok, yeah, email me. My email is eyhonda "at" yahoo. I think it might be simpler than you are thinking. I have a spreadsheet that helps with the some of the constants needed. I did some quick calculations for my application and for one TMR0 overflow, you have a 12.75us resolution. Basically, you only need 10 loops to get to 120.75us and so forth. I'm assuming you mean prescaler of 1 not 0. Being an EE, yes I know about the flyback spikes. Just take care of it with a flyback diode across the coil. It's a similar topology for relays. I can translate your code to PIC so we are on the same micro. I also have MPLAB to work with and a couple handfuls of micros (PIC17F7X) and a few BU941ZT transistors (coil driver, darlington). These transistors are used in high voltage golf carts (36-42v) with a Vce breakdown of 350v. So, these are plenty beefy. I can give you a few to play with in exchange for the LEDs you already gave me. Just heatsink it accordingly and calculate your heat dissipation with a good safety margin. I'm assuming the last comment you made was "I don't MIND making this a joint project". Just remember, we'll have to adjust some constants back and forth since I'm using a single with only 1 pulse per 2 revs. I'm using a CDI pulser for the trigger. So, it is a positive pulse on the interrupt. You just need to configure for falling edge, not rising edge.

So, anyway. let's post here when we make a good milestone so as to not muddy the waters with minute details that doesn't immediately make sense.

BTW, I also have the redline limit working too!
 
I found site with a bunch of neat electronics.
http://motogadget.com/?___store=en

I've heard they have what you may need to do the conversion...
 
I've measured 318V with peak volt adapter on the '12' volt side of coil at around 6,000rpm. (on TPI system)
HD were using peak primary volts to monitor fuel injection system, lean mixture needs higher voltage, rich mixture lower volts (within whatever parameters they were using?)
 
popssss said:
I found site with a bunch of neat electronics.
http://motogadget.com/?___store=en

I've heard they have what you may need to do the conversion...

Cool site! A little pricey, but nice ideas.

PJ - thanks for that data point. Now, I know we are in the ballpark for targeting the drive transistor.
 
I was shocked, in more ways than one ;)
Like, 'that didn't feel like 12v' so measured it ;D
 
Back
Top Bottom