free electronic ignition code!

xjwmx

XS650 Guru
Top Contributor
Messages
8,055
Reaction score
4,888
Points
313
Location
U.S.A.
I've been meaning to write this for awhile, and finally finished it up. It is C code for an XS650 Special-like ignition. It is for the TM4C123G evaluation board, which is a tiny little controller board you can get for around $15 these days. Add a coil firing transistor circuit, and buffering for the pickup mounted on the stator and you're ready to run...

...almost. Many easy changes needed to be made to the values for the variables. For example for ease of conceiving it, I assumed TDC is 180 degrees CCW from the second pickup pole. I assumed the two pickup poles are 10 degrees apart. I assumed advance kicks in at 1000 RPM and is finished at 5000 RPM. I assumed the maximum advance is 20 degrees - all incorrect for the XS650 excepting for coincidence, but if you understand the code, changing these and a few other things to the right values is nothing. Now go make an ignition!
https://github.com/hwm1/electronic-ignition
 
Have not made any hardware, so no testing at all. But the flow is right, at least. A lot will need to be changed, as I was saying, but they are fairly easy changes. There's a post here somewhere that gets into details of the TCI advance, which could be plugged right in. Mouser is a good place to get the board, if you want to try soldering up an ignition. I can give you an informal hand with the code, if you're interested. There will be some electronics involved; this is basically just the brains of it.
 
Are there values to control/adjust dwell in your code?
 
No, the coil turns on as soon as you have a commitment to fire. Rough on the coil, but makes for easier to follow code. To add dwell, I would probably break the time to fire calculation into two parts, making the first part the time to turn on the coil in addition to part of the time to fire. Or turning the coil on could come from a timer interrupt handler. I made a couple of changes to it this morning after it dawned on me a millisecond timer isn't enough resolution, so I changed it to 1/100 ms. If anyone wants to make one, it will be a bit of an ordeal involving oscilloscopes and some circuit design, not as easy as just finding another TCI to buy.... :)
 
I don't really understand the code... can you clarify this?
-------------------------------------------------------
current_counter_value = look_for_pulse();



//have valid first and second pulse here



//we are going to fire coil so begin charging it

//turn on ignition coil here to charge it
GPIO_PORTF_DATA_R = 0x02;
// poll for pulses from sensor

---------------------------------------------------------
From my almost nonexistent understanding of the code, it looks like the coil starts to charge as soon as it see's the triggers?
Upwards of 100-150 deg. of dwell?
 
As I said, there's no accounting for dwell, to make the code easier to understand at this point, but it's also because I don't know what the dwell should be. The best way to find out what it should be is find out what it is with the stock TCI, which requires hooking up an oscilloscope, something I have no desire to do! If someone someday starts putting one together then we will dig into it further.

The first line of code you pasted looks for two tightly enough spaced pulses which it takes to be from the magnet passing both poles in one cycle. The function there returns the time in 1/100 ms that it took to pass both poles. Then the other line of code there immediately turns on the coil, no concept of dwell. Probably not very good in practice. Note also the polarity of the pulses is assumed. The actual polarity will depend on the external circuit to buffer them and square them up. A lot of bench work needed to turn it into a reality
 
Where's Bueller, I mean too many??

Ruh-roh.

I like the idea of an inexpensive doit-yerself kit, suitable for amateur building, simply download the code and flash the microprocessor.

But, this TM4C123G is a monster.
Tm4c123gxl_launchpad01.jpg

Tm4c123gxl_launchpad02.jpg


The chip is a 64-pin surface mount.
TM4C123GH6PM.jpg


I understand xjwmx's code skeleton, but my coding style for real-time applications was different. Instead of polling the inputs, I normally used a block code base for calculations/management/output, with independent/asynchronous processes (daemons) that are interrupt triggered (input state and/or timer) to process the data and deliver it to a section of shared memory, with a return vector into the base code. My coding for these were mostly in assembly.

A quickie look shows the evaluation board at $250, books/docs over $100, then there's the ancillary equipment and aspirins.

Looking at the stock TCI triggering, rotor magnet passing under 2 sense coils, the signals need a bit of looky-see. As the magnet passes under a sensor coil, the signal will be sinusoidal, and the magnet's polarity defines whether the leading lobe is negative or positive, signal voltage crossing zero as the magnet is directly under the sensor coil. The magnitude of this signal will vary with rpm. Modern crank-triggered ignitions don't use this signal as a one-shot trigger, but analyze the waveshape to determine where it is. In the stock xs650 TCI ignition box, the input waveform hits 2 series-connected diodes, which gives only the positive part of the pulse, clipping it down by at least 1.2v, and sending it on to an R/C timer/conditioner, which drives an input transistor, like an old-school analog computer.

Just some numbers to gyrate and chew on.
At 9,000rpm, the crank is rotating at 150rps, making a 1 degree rotation in about 18 microseconds. The magnet travels about 0.8mm (1/32") in that 1 degree. Chopping up the trigger signal waveform into 18 pieces would be at 1 microsecond, a 1 Mhz sampling rate.

A bit much for my handheld scope. Would need to buy something in the 20mhz class.

Sounds like a fun project.
Myself, I'd be looking into less voluminous microprocessors, amateur solderable dip package...
 
Last edited:
Here is what I was basing the price I gave on. It looks like it's come down to $13 now.
https://www.mouser.com/ProductDetail/Texas-Instruments/EK-TM4C123GXL?qs=sGAEpiMZZMtw0nEwywcFgM/kur0vyjLa3GaHm/BlYTM=

I think it comes with a USB cable and some PC software. I took a class on it about four years ago, but used a software simulator of the board from a co. named Keil. The class was taught by prof. Valvano, from U.T. Austin. The board was $50 at the time with a discount.

The board looks like overkill, but the way development boards work is you wire up what you need from it to simulate the product you have in mind, write some code, and then eventually design your own much more specific board using the same processor. On this development board, probably every line is brought out, there are buttons and leds on it, and lots of bells and whistles, USB interface, to make it as suitable as possible a starter for any product from toaster guts to ...you name it. I wrote lots of interrupt-driven code too, mostly because it was micro power products and it spent 99.9+% of its time powered down. That was assembly as well. But for quickies, it's much easier to poll than to unearth how the interrupts work! No less efficient. One programming truth is that all programmers hate all other programmers' code :) To judge size, those two large ICs are about 1/2" square.
 
way over my head to but very intersing, My dad works for a company I cant mention, working on fling objects I cant mention and he has allways said that electronic ignitions are pretty simple stuff, when I was a kid he took me to radio shack (remember that place) and we bought a kit you could build a bunch of stuff out of, I made the fm radio transmitter,(legal if it onbly has so much power) but he pointed at the part that needed to be Biger and soon I was transiting in the nabor hood (pirate radio at 8 year old) lol, but I would be interested to follow along and try and see if I can keep up with this.

Would this work with a triger set up like a pamco, boyer or even this one Ive seen for a long time on ebay,
https://www.ebay.com/itm/Tytronic-E...all-68-83-XS-1-XS-2-points-plate/112408793785

or does it only work on a factory style trigger???
 
That is a weird link. The whole description is like wtf. But no, it seems to be complete in itself and doesn't need me
 
xjwmx… it may not need you but WE DO :wink2:

and GGG gary ...did you really order one of those?? I sometime am oblivious to sarcasm.
 
is that the same as the dwell I used to set in my old ford? I think I answeereddeed my own question, I didn't used to set the gap I would set the Dwell on me points
Yes. Dwell is the amount of time a coil is saturated. Dwell time needs to be just long enough to saturate the coil at max rpm. Any longer shortens the life of the coil. I suspect this code, as it written, will be a coil eater.
 
As I said, there's no accounting for dwell, to make the code easier to understand at this point, but it's also because I don't know what the dwell should be. The best way to find out what it should be is find out what it is with the stock TCI, which requires hooking up an oscilloscope, something I have no desire to do! If someone someday starts putting one together then we will dig into it further.

The first line of code you pasted looks for two tightly enough spaced pulses which it takes to be from the magnet passing both poles in one cycle. The function there returns the time in 1/100 ms that it took to pass both poles. Then the other line of code there immediately turns on the coil, no concept of dwell. Probably not very good in practice. Note also the polarity of the pulses is assumed. The actual polarity will depend on the external circuit to buffer them and square them up. A lot of bench work needed to turn it into a reality

Dwell should be about 22.5 degrees on a point system.
Thu
 
The dwell angle on the XS650 points is roughly 90°.
Which is about 180° at the crank.

The dwell time for our coils needs to be at least 3ms.
Less than that gets a weak spark.
More than that is wasteful, and heats up the coil.

On the points bikes,
At an idle speed of 1,200 rpm, the 90° dwell gets you 25ms of dwell time. Too long.
At a high 9,000 rpm, the 90° dwell gets you about 3.3ms of dwell time. Just right.

On the TCI bikes.
When I scoped DogBunny's TCI ignition, at idle, the trace showed a dwell time of 3-4ms. Just right. And, it appears that the TCI ignition has adaptive dwell...
 
xjwmx… it may not need you but WE DO :wink2:

and GGG gary ...did you really order one of those?? I sometime am oblivious to sarcasm.
I know. I am the thin line that keeps it from turning into a nursing home.
He did. Looking forward to hearing about it and what it is.
Yes. Dwell is the amount of time a coil is saturated. Dwell time needs to be just long enough to saturate the coil at max rpm. Any longer shortens the life of the coil. I suspect this code, as it written, will be a coil eater.
No, because as written it won't run at all :)
 
Back
Top