Arduino Based CDI

I began working on this idea a while back but lost attention over the riding season. Cold weather is coming, so it's time to pick it back up. I mentioned this in another thread and several people seemed interested in learning some Arduino usage as well as using the final product. So, I thought I would start a new thread for this specific topic. Once things are sorted out this will all be wiki'd, but for now we can use this as a place to exchange ideas for the thing.

So far, I have been using an Arduino Uno. It's simple and cheap; ~$25 at the time of writing this. You can even buy them at local places like Radio Shack.

When I initially began development of this, I built a simple CDI circuit which was basically a copy of one that Ryan had posted some time before. Essentially it rectified (converted AC to DC) the current coming off the ignition coil and dumped it in to a capacitor, and when the signal coil 'fired', an SCR (Silicon Controlled Rectifier) acted as a switch which would ground the capacitor, thereby dumping its charge to the high tension coil. Here is the circuit to the best of my recollection (as the image from the original thread has 404'd):

Here is a video of the circuit in use:

Now that I had a simple working circuit, I wanted to basically circumvent the trigger signal going in to that SCR and send it to the Arduino, such that I could programmatically delay the response based on various conditions such as current RPM, temperature, etc.

The problem I ran in to was treating the signal coming from the trigger coil so as to prepare it for input to the Arduino. At about 1000 RPM, the trigger coil on my MVT Millennium was putting out about 4 volts, meaning at 15 thousand RPM (no I don't plan on going to that RPM, but if I'm going to design a system, I want it to be able to handle extremes) it would be putting out a whopping 60 volts. I'm still learning all this stuff as I go along, and despite consulting some EE students here at MIT, I could not come up with a good way of essentially converting that to a binary signal. If I were to resist down the signal such that it's low enough to pipe in to an analog input on the Arduino at 15k RPM, the signal at 1k RPM would be so low that it would no different than the ambient noise.

That catches us up to the present date. A few days ago I was kicking an empty can down a dirt road and realized that all I had to do was just epoxy a Hall Effect sensor on to my stator and I could then simply ignore the stock trigger coil all together. Hall Effect sensors's are magic little switches that turn 'on' when a magnet passes over them, and then turn 'off' when the opposite pole of a magnet passes over again. Because most of our flywheels have four magnets in them, all I had to do was listen to this sensor for on-off-on-off and then I know that a full revolution has occurred.

To test my device I have taken a small centrifuge and turned a custom rotor for it on the lathe in to which I have embedded two small neodymium magnets and screwed a shitty piece of wood in there on which to mound my sensor. Yesterday I finished writing some basic code for this project and tested it out. It simply prints to the serial monitor the current RPM. This centrifuge spins up to 14k RPM, and I'm happy to say that my device was reading it as ~14998 RPM!

(old picture.. that is the pickup coil for a 'Treats CDI' from my initial tests. The Hall Effect sensor is not pictured)

So, the next step is to build another CDI circuit to trigger with a digital output pin on the Arduino. I am currently researching a new circuit so I may run it off of a 12v battery. I don't plan on running a total-loss ignition, but it would be nice to have it as an option and would make testing easier. The problem with the earlier circuit is that when the SCR triggers to ground the capacitor, it will also ground the + lead on the battery for a moment and that is going to eventually break things. (edited)

Arduino_Uno.png
CDI_Schematic.png
IMAG0284.jpg

Re: Arduino Based CDI

Nice work boss!

Re: Arduino Based CDI

Ultimately, the device I hope to create will offer dynamic control of timing based on various things. I would like the user to be able to define various timing curves and switch between them on the fly even when riding, as well as offer automatic emergency timing changes when temps rise too high.

I have not yet ordered one, but I plan on using the 16x2 adafruit LCD panel which features integrated control buttons. Fun fact: Lady Ada (The awesome gal who runs adafruit) was a member of MITERS where I make all my stuff.

I'm thinking it would be great to have a thumb button which connects to the control unit which would allow you to switch between pre-defined timing profiles on the fly, so if you want to be a cool guy and take off from a stop like a madman, you can switch to an aggressive curve, but once up to speed you can switch to a milder profile so as not to kill your bike, or have one for racing and one for commuting.

I'm also thinking about connecting a temp sensor so as to allow for automatic emergency retardation of timing if you temps rise too high, and possibly even kill the engine if they get way too high.

Throttle position sensing would also be interesting. What if it were to monitor your throttle behavior, and if you were to suddenly whip back the throttle, it would automatically switch to a more aggressive timing curve, but if your throttle position is calm and relatively static, it would retard a bit as this likely means you are on a long steady ride. (edited)

772_MED.jpg

Re: Arduino Based CDI

Oh, and here's some code to confuse the heck out of ya:

#define OUTPUT_PIN 7

#define HALL_PIN 12

#define MAGNET_COUNT 4

#define UI_UPDATE_FREQUENCY 1000 // in milliseconds

#define INITIAL_ADVANCE 1.5

unsigned int g_hall_state = 0;

unsigned long g_last_ui_update = 0;

float g_last_ui_pulse_count = 0;

unsigned long g_last_pulse = 0;

void setup() {

   Serial.begin(9600); Serial.println("Serial started");

   

   // initialize the LED pin as an output:

   pinMode(LED_PIN, OUTPUT);

   

   // initialize the hall effect sensor pin as an input:

   pinMode(HALL_PIN, INPUT);

   

   g_hall_state = digitalRead(HALL_PIN);

   attachInterrupt(0, pulse, CHANGE);

}

void loop() {

   unsigned long ui_update_duration;

   unsigned long now_time;

   float RPM;

   now_time = millis();

   

   ui_update_duration = now_time - g_last_ui_update;

   if (ui_update_duration > UI_UPDATE_FREQUENCY) {

      RPM = (((float)g_last_ui_pulse_count / MAGNET_COUNT) / ((float)ui_update_duration / 1000)) * 60;

      Serial.print(RPM, DEC);

      Serial.print(" RPM");

      Serial.print("\n");

      g_last_ui_update = now_time;

      g_last_ui_pulse_count = 0;

   }

}

void pulse() {

   static int pulses = 0;

   

   pulses++;

   g_last_ui_pulse_count++;

   if (pulses == MAGNET_COUNT & g_last_pulse != 0) {

      revolution();

      

      pulses = 0;

   }

   g_last_pulse = micros();

}

void revolution() {

   long quarter_rotation_time;

   long one_degree_time;

   quarter_rotation_time = micros() - g_last_pulse;

   one_degree_time = quarter_rotation_time / 90;

   delayMicroseconds(INITIAL_ADVANCE * one_degree_time);

   digitalWrite(OUTPUT_PIN, HIGH); // Send a signal to the SCR

   

   delayMicroseconds(INITIAL_ADVANCE * one_degree_time); // Wait for a moment.

   

   digitalWrite(OUTPUT_PIN, LOW); // Turn off the SCR

} (edited)

Re: Arduino Based CDI

Love it, keep up the good work! I want to run this! have you looked at megasquirt and rest of its products?

Re: Arduino Based CDI

Nope, better than arduino?

Re: Arduino Based CDI

oh jeez, it's a whole thing. I haven't looked in to it at all, but I think Graham Motzing mentioned that he was looking in to using it at one point. My initial thought is that it appears to be way more complicated than we need. Designing a controller of our own from the ground-up is good because we can design it to do exactly just what we need and want. (edited)

Re: Arduino Based CDI

!! This is awesome

Re: Arduino Based CDI

I approve. Godspeed.

Re: Arduino Based CDI

Make a kickstarter and I will donate.

Re: Arduino Based CDI

http://www.microsquirt.info/v2index.htm

This is what i was talking about

Re: Arduino Based CDI

But aren't those fuel injection controllers... Is is that your point?

Re: Arduino Based CDI

Jason Collier /

please finish this. so rad.

Re: Arduino Based CDI

Dominic Valentino /

I've been working on this too, so far I've been successful with implementing simple ignition curves (3 segment interpolation), but even with the most creative use of interrupt/counters the arduino begins to choke at above 200hz trigger frequency. Pushing up against the limits of processor speed vs interpolation calculation and required dwell time.

I moved away from the arduino and onto a different, more powerful/forgiving uC, to deal with this. Also my design uses an igbt/battery to charge the coil and optocouplers to protect the uC

I would like to offer these as kit/built if there's any interest

Re: Arduino Based CDI

Lol. Are you planning on running a vespa over 12000 rpm Dominic? That's ridiculously awesome!

Re: Arduino Based CDI

. (edited)

Re: Arduino Based CDI

That's interesting, Dominic. I'm still building this rig, so it will be interesting to see if, once my curve-handling code is in place if the arduino can keep up. So far, the code I posted above is accurately keeping up with the centrifuge spinning at 14k rpm.

While I am not necessarily planning on hitting 12 or 14 thousand rpm, I like the idea of designing the system to be able to handle extremes.

Re: Arduino Based CDI

NB0tt aholetechbro /

Mars, people have been doing some really neat things with Arduinos for a number of years but what you are doing has got to be the coolest so far!

Good on ya!!!

Re: Arduino Based CDI

orly?

Re: Arduino Based CDI

Dominic Valentino /

Haha, not with the unbalanced Mazzi crank I have

Mars,

Try making up a simple hashtable lookup to change the advance based on rpm then scope your trigger and charge to see if/when/where the advance bombs

Re: Arduino Based CDI

Hmmmm... I might buy an arduino... I had a blast on my matlab final project. Programming is secretly fun to me.

Re: Arduino Based CDI

I thought about this a few years ago, the programing on these is easy for simple things. This probably not being one of them once you get it all worked out.

Re: Arduino Based CDI

Mars, I'm into this, a lot. If you want help with anything I'd be down. i've wanted to do some small part plastic molding for a while, maybe we/I can work on a nice enclosure or something.

Re: Arduino Based CDI

How are you going to provide the input curve? just a lookup table with interpolation between points? Actually you probably don't even need the interpolation. I'm not sure how sophisticated of an input the hardware/software can handle, because I don't know shit about this shit. (edited)

Re: Arduino Based CDI

DERP

Re: Arduino Based CDI

Wow, there's something about seeing the sensor move back and forth like that that I find amazing. Probably because of countless times with the stop-piston-remove-flywheel-clock-stator-replace-flywheel-replace-spark-plug-check-timing routine.

Re: Arduino Based CDI

Oh Adam, yes! Definitely up for some collaboration with the case.

So, I'm working on some code right now to take a series of points and draw a bezier curve between them. I'm going to use that to build a lookup table, so the transition between points will be natural and curved.... I guess. Regarding how to actually program your desired curve, I'm not sure yet. It would be easiest to do a linear (non-bezier) input having the user hit right-right-right to get to the desired RPM, then up-up-up (or down) to get to the desired timing setting, then have a 'set point' button, then go on to the next point.

Re: Arduino Based CDI

Ϫ‡☄ಬ∞ ƀƖḬƝƊ ƤǂƿƎ ∞ಬ☄‡Ϫ - Hoke from Black Pipes Moped Gang /

Dominic Valentino Wrote:

-------------------------------------------------------

> I've been working on this too, so far I've been

> successful with implementing simple ignition

> curves (3 segment interpolation), but even with

> the most creative use of interrupt/counters the

> arduino begins to choke at above 200hz trigger

> frequency. Pushing up against the limits of

> processor speed vs interpolation calculation and

> required dwell time.

>

> I moved away from the arduino and onto a

> different, more powerful/forgiving uC, to deal

> with this. Also my design uses an igbt/battery to

> charge the coil and optocouplers to protect the uC

>

>

> I would like to offer these as kit/built if

> there's any interest

mmmmmmhmmmm?

Re: Arduino Based CDI

This is cool shit. I use Arduino's in my multicopters.

Mars, why not use a smaller Arduino, such as the Nano? It's cheap.

Re: Arduino Based CDI

Because this is what I had kicking around :)

Want to post in this forum? We'd love to have you join the discussion, but first:

Login or Create Account