CDI tester project

cattledog: I think I understand.

You want a new ignition pulse, on two pins to replace the current single output on pin 4.

Yes

It looks like we now get an output pulse on pin 4 of some length and some repeating frequency determined by the RPM setting. It sound like you want to change this to an output on two pins.

The length of the existing pulse is determined by barWidth I think. So the 2 new pulse array must replace >that in such a way that it tells the DAC to output a pos pulse and then after a time determined by barWidth >output a neg pulse, then no pulse until it repeats. i have to determine what the pulse width should be.

What I'm unclear of is how the two outputs to the DAC are timed. Is a +/- varying signal sent from the DAC to the module each cycle. Can you draw a timing diagram of how the 11 00 10 output states are sent to the DAC? Are they all sent in sequence during one output timing cycle?

In this simplest control of the DAC it has 3 states of output, 0 volt, pos volt, neg volt.

It would help me if you could draw a timing diagram of the desired output pulses.

attached is something that may help. MSB is DAC pin 5 and all others are 6 thru 12 tied together.

Can you explain about "barWidth". This variable does not appear in the previous code we worked on. What is it, and how does it relate to the timing of the 2 pulses.

It is the width of the bar that passes past the pickup coil. Some engines it is just a short bar and only >serves to make a short pulse where they are only interested in the positive component of the signal. These >generally have two pickup coils and two short bars. In this case I am only interested in one of the positive >pulses so I set the barWidth to small value. Other times the bar can be 60° long and the negative pulse is >at the beginning and then the positive is at the end of bar which has just one pickup coil. For this I set the >barWidth to a higher value, usually the bar length in degrees plus the base timing so 74 is a normal setting.

In this new mode of output to the DAC, will the the return pulse from the module and the reading on the pin 2 interrupt be unchanged?

I think the answer is yes.

Will the charge pulse code be unchanged?

Yes

It's been awhile :confused:

Yes for me also, I tend to forget a lot of what I have learned doing this!!

here is a representation of the DAC control.

Maybe this also helps, I ask a friend with a similar interest and he said.

How wide should the on time of each pulse I send to the DAC be?

The answer is: "it depend !"

For having Zero volt , DAC need 10 (MSB pin at 1 , others at 0) Leave MSB pin at 1 , others at 0 as long as you want a 0volt, about 350degres (so most of the time)

The time MSB is 1 and other are 1 too to produce a +12v is up to you. If you want a 1ms pickup, then those 2 pins must not move during 1ms

Personally , I decided that ONE pulse last 10degree so the code is : - send 10 to produce 0volt - for positive pickup: send 11 to produce +12v - wait (PERIOD/360) * 10 (PERIOD is in ms)

  • send 10 to produce 0volt -wait 'barWidth' millisecond you want

-send 00 to produce -12v -wait (PERIOD/360) * 10 (PERIOD is in ms) - send 10 to produce 0volt

That's it , then wait for the next rotation

Do I use 'barWidth' for beginning of pulse to end of the other, or between the 2 pulses.

between the 2 pulses

OK, I think I have it. I'll express things in degrees, and the event timing will be changed by RPM.

First, you will need a switch to set the AC trigger mode. This will be similar to the RISE/FALL switch and the CHARGEPULSE mode switch. Do you have this switch installed already?

Personally , I decided that ONE pulse last 10degree

In the AC Trigger mode you want the + and - pulses each to be 10 degrees long, separated by 60 degrees. We can make those values adjustable by a pot, but these sound like default starting values. I think you already have a pot 3 for bar width.

Other times the bar can be 60° long and the negative pulse is >at the beginning and then the positive is at the end of bar

You have also described and drawn the pulse train as starting with a positive 12 volts. i.e. +12v for 10 degrees, 0v for bar width(60) degrees, -12v for 10 degrees, 0v for remainder of the timing cycle.

What pulse do you want to lead with?

You will need to determine where you want the return pulse delay measurement to start. At present the RISE/FALL switch controls whether delay timing starts with the rise of the trigger or the fall of the trigger. With the AC trigger and the bar width, you will need to establish the the start of timing for the return.

I'm pretty sure you have a scope to measure output pulses. I think I will try to write a simple piece of test code at 1200 rpm (50 ms cycle timing). 50/360 = .139 milliseconds/degree or 140 microseconds/degree to use a nice round number. Let me know if you want to lead with 00 (-12v) or 11(+12v) and I will try to write some code which outputs the pulse train.

Do you have arduino pin numbers you want me to use for D1 and D2?

Hi, I can easily install a switch for AC trigger but I am not clear on it's purpose.

The pulse length can be hard coded as long as I can change it in the code easily, I assume I would be able to. Once set it would likely never be changed. The pot to change barWidth is all that is needed here and I have that along with the readout on display.

It would be nice to have the polarity of the output switchable and I think I can do that by swapping pins 2 & 4 on the DAC. So just + first should be OK.

To answer the last question I need to understand what you refer to as AC trigger. Thanks, Tom

Hi, I can easily install a switch for AC trigger but I am not clear on it's purpose.

How will the program know to run the dual trigger pulse instead of the standard single pulse trigger for the cdi module?

To answer the last question I need to understand what you refer to as AC trigger.

I am referring to the two +/- voltage pulses as an AC trigger for the cdi module. If you have other terminology like "bipolar trigger" or anything else you like, let me know. I focus on the word trigger, because the pulses are used to trigger the delayed response from the module and we have used the word trigger in the existing code to refer to the outgoing pulse from the arduino.

Oh OK, I see what you think. No this as you say AC trigger, completely replaces the old single trigger.

Before I had the single trigger go to a very small transformer so as the trigger turns on it energizes the transformer and makes a output pulse, then it stays on for period of time and when it turns off the collapse of field in transformer also makes a opposite pulse. Crude but it works, now I just wanted to improve the system. Also I can code the Arduino to drive more bits of the DAC to make a better sine wave.

By the way I have a Hantek DSO5072P. I love it. Before I had a Tektronic 585A, 50 years old now and still works. Tom

The output pins can be 4 and 5. I see that it may be necessary to have a switch to tell Arduino to do - or + first, no electronic way to easily swap them. Tom

Here’s some code to test to see if we have the output pulses correct. Please check that I have the correct output to the DAC pins for the +/- 12 and 0 voltage. I have tried to keep nomenclature similar to the original code. To get the two pulses, I have changed the timer mode from what we had, and broke the 360 degree cycle into two unequal pieces, each containing one pulse. Output compare interrupt B always turns off the pulses. I tested with an led indicator and a slower rpm and timer prescaler, but have left these adaptations commented in the code. Throw a scope on this and tell me what you get. Ask any questions for clarification.

//You can use pots to set RPM, pulseWidthDegrees, and barWidth
unsigned int RPM = 1200;
//unsigned int RPM = 400;
unsigned int pulseWidthDegrees = 10;
unsigned int barWidthDegrees = 60;
unsigned long pulseWidthTime;
unsigned long timerTopValue;//sets 360 degree cycleTime
unsigned int timerTicksPerDegree;
const byte pinA = 4; //to DAC pins tied together
const byte pinB = 5; //to pin5 DAC

void setup() {
  pinMode(13, OUTPUT); //telltale led
  pinMode(pinA, OUTPUT);
  pinMode(pinB, OUTPUT);
  //initialize timer
  TCCR1A = 0;
  TCCR1B = 0;
  //set Timer1 mode Fast PWM to ICR1 
  TCCR1B |= (1 << WGM13) | (1 << WGM12);
  TCCR1A |= (1 << WGM11);
  
  timerTopValue = 15000000UL / RPM; 
  //15000000 timerTicksperMinute at 4 us per tick with prescaler 64
  //timerTopValue = 12500 at 1200 RPM 50ms per revolution
  timerTicksPerDegree = timerTopValue/360;
  ICR1 = timerTopValue;//initial placeholder
  pulseWidthTime = pulseWidthDegrees*timerTicksPerDegree;
  OCR1B = pulseWidthTime;

  //start Timer apply prescaler
  //TCCR1B |= (1 << CS12) | (1 << CS10); //1024 for led test
  TCCR1B |= (1<<CS11) | (1<<CS10);//64 for .5 us tick

  //enable B OutputCompare and Overflow interrupts
  TIMSK1 |= (1 << OCIE1B) | (1 << TOIE1);
}

void loop() {
}

ISR(TIMER1_COMPB_vect) {
  digitalWrite(13, LOW); //turn off pulse
  digitalWrite(pinA, LOW); //tied pins LOW
  digitalWrite(pinB, HIGH); //DAC5 HIGH
}

ISR(TIMER1_OVF_vect) { 
  //alternate ICR1 values to generate two outputs
  //360 degree cycle time broken into two pieces
  static byte count = 0;
  if (count == 0)
  {
    ICR1 = timerTicksPerDegree*(pulseWidthDegrees+barWidthDegrees); //first pulse and bar width
    digitalWrite(13, HIGH);
    //positive pulse
    digitalWrite(pinA, HIGH);
    digitalWrite(pinB, HIGH);
  }
  if (count == 1)
  {
   ICR1 = timerTicksPerDegree*(360-(pulseWidthDegrees+barWidthDegrees));//second pulse and dead band
    digitalWrite(13, HIGH);
    //negative pulse
    digitalWrite(pinA, LOW);
    digitalWrite(pinB, LOW);
  }
  count++;
  if (count == 2)
    count = 0;
}

OK, I have some parts on order and need to wire it up so it may be a few days. Thanks, I will keep in touch. Tom

Can you scope the output from the Arduino and confirm that it is what you want before connecting to all the other hardware down stream? I'd like to try and separate any software issues from subsequent hardware issues.

OK I will look at it soon but I am tied up with other work til mid week Tom

OK pin 4 = yellow, 5 = blue

I think that’s what we wanted.
dce2ff8adfabcae920714d0e887178ea314ece15.jpg

Before I had the single trigger go to a very small transformer so as the trigger turns on it energizes the transformer and makes a output pulse, then it stays on for period of time and when it turns off the collapse of field in transformer also makes a opposite pulse.

Where to want to start timing the return pulse. How have you been using the R and F settings?

I think there are 4 places we can time from Start and Finish of the tied pins(yellow trace/PinA) going High and back to Low, or the Start and Finish of the single pin to DAC5(blue trace/PinB) going Low and then back to High.

I hope I have the pin and color designations correct. I think we should change the nomenclature from pinA and pinB to something else. dacTiedPins and dacPin5 works to clarify things for me. Do you ahve something else to call then which makes better sense to you?

const byte dacTiedPins = 4; //to DAC pins tied together
const byte dacPin5 = 5; //to pin5 DAC

Hi, OK maybe this helps? I have to think about the R and F, to see if I only really use one.

acf57ca81a8191bab910b0b376a061b833e2e329.jpg

Some comments on your understanding of what line in the code does what.

I recommend that you consider the cycle to start with the +12v pulse and that it is done with the code at lines 54-61. This + pulse (and the - pulse as well) are taken back to 0v with the code at line 44. The code triggering the -12v is at lines 62-69.

There are two interrupts which turn the pulses on and off.

Turn Off code, is in the Compare B interrupt which always occurs after 10 degrees of pulse length.

Turn On code, with either +12 or -12, is in the Overflow interrupt, and the time to overflow, or overall cycle length, is set by the rpm.

You could consider the alternating pulses as a switch case, or state machine, situation where the two alternating cases are 1)give a positive pulse and wait at 0v for the bar length time and 2)give a negative pulse and wait at 0v for the remainder of the cycle time.

here is a little easier to see pattern, but yes it looks to do what is needed.
pin 4 = yellow
pin 5 = blue

OK I have changed the comments a little to help me, so I hope you also think it is good description.
Also to consider, I leave the Rise / Fall switch at Rise all the time so it could be done just in code, no need for a switch anymore.
The other thing is that there should be a switch to choose Pos first or Neg first for this trigger pulse.

//You can use pots to set RPM, pulseWidthDegrees, and barWidth
unsigned int RPM = 1200;
//unsigned int RPM = 400;
unsigned int pulseWidthDegrees = 10;
unsigned int barWidthDegrees = 60;
unsigned long pulseWidthTime;
unsigned long timerTopValue;//sets 360 degree cycleTime
unsigned int timerTicksPerDegree;
const byte pinA = 4; //to DAC pin 6 - 12, called 6
const byte pinB = 5; //to DAC pin 5 

void setup() {
  pinMode(13, OUTPUT); //telltale led
  pinMode(pinA, OUTPUT);
  pinMode(pinB, OUTPUT);
  //initialize timer
  TCCR1A = 0;
  TCCR1B = 0;
  //set Timer1 mode Fast PWM to ICR1
  TCCR1B |= (1 << WGM13) | (1 << WGM12);
  TCCR1A |= (1 << WGM11);
 
  timerTopValue = 15000000UL / RPM;
  //15000000 timerTicksperMinute at 4 us per tick with prescaler 64
  //timerTopValue = 12500 at 1200 RPM 50ms per revolution
  timerTicksPerDegree = timerTopValue/360;
  ICR1 = timerTopValue;//initial placeholder
  pulseWidthTime = pulseWidthDegrees*timerTicksPerDegree;
  OCR1B = pulseWidthTime;

  //start Timer apply prescaler
  //TCCR1B |= (1 << CS12) | (1 << CS10); //1024 for led test
  TCCR1B |= (1<<CS11) | (1<<CS10);//64 for .5 us tick

  //enable B OutputCompare and Overflow interrupts
  TIMSK1 |= (1 << OCIE1B) | (1 << TOIE1);
}

void loop() {
}

ISR(TIMER1_COMPB_vect) {
  digitalWrite(13, LOW);    //turn off pulse for 0 volt
  digitalWrite(pinA, LOW);  //DAC 6 LOW
  digitalWrite(pinB, HIGH); //DAC 5 HIGH
}

ISR(TIMER1_OVF_vect) {
  //alternate ICR1 values to generate two outputs
  //360 degree cycle time broken into two pieces
  static byte count = 0;
  if (count == 0)
  {
    ICR1 = timerTicksPerDegree*(pulseWidthDegrees+barWidthDegrees); //first pulse and bar width
    digitalWrite(13, HIGH);    //turn on pulse for +12v
    digitalWrite(pinA, HIGH);  //DAC 6 HIGH
    digitalWrite(pinB, HIGH);  //DAC 5 HIGH
  }
  if (count == 1)
  {
   ICR1 = timerTicksPerDegree*(360-(pulseWidthDegrees+barWidthDegrees));//second pulse and dead band
    digitalWrite(13, HIGH);   //turn on pulse for -12v
    digitalWrite(pinA, LOW);  //DAC 6 LOW
    digitalWrite(pinB, LOW);  //DAC 5 LOW
  }
  count++;
  if (count == 2)
    count = 0;
}

OK I have changed the comments a little to help me, so I hope you also think it is good description.

Looks good to me.

The other thing is that there should be a switch to choose Pos first or Neg first for this trigger pulse.

I patched in the code for the first pulse polarity. You’ll need to set up a toggle switch for this. I think you can use the R/F switch but in the current code it is on pin5 which is becoming an output.

//You can use pots to set RPM, pulseWidthDegrees, and barWidth
unsigned int RPM = 1200;
//unsigned int RPM = 400;
unsigned int pulseWidthDegrees = 10;
unsigned int barWidthDegrees = 60;
unsigned long pulseWidthTime;
unsigned long timerTopValue;//sets 360 degree cycleTime
unsigned int timerTicksPerDegree;
const byte pinA = 4; //to DAC pin 6 - 12, called 6
const byte pinB = 5; //to DAC pin 5
//set first pulse state with toggle switch like R/F or charging switch
//const byte setfirstPulseSwitch = ??;
//boolean firstPulsePos = true;
boolean firstPulsePos = false;

void setup() {
  pinMode(13, OUTPUT); //telltale led
  pinMode(pinA, OUTPUT);
  pinMode(pinB, OUTPUT);
  /*
    pinMode(setFirstPulseSwitch, INPUT_PULLUP);
    if (digitalRead(setFirstPulseSwitch) == HIGH)
     firstPulsePos = true;
    else
     firstPulsePos = false; //first pulse negative
  */

  //initialize timer
  TCCR1A = 0;
  TCCR1B = 0;
  //set Timer1 mode Fast PWM to ICR1
  TCCR1B |= (1 << WGM13) | (1 << WGM12);
  TCCR1A |= (1 << WGM11);

  timerTopValue = 15000000UL / RPM;
  //15000000 timerTicksperMinute at 4 us per tick with prescaler 64
  //timerTopValue = 12500 at 1200 RPM 50ms per revolution
  timerTicksPerDegree = timerTopValue / 360;
  ICR1 = timerTopValue;//initial placeholder
  pulseWidthTime = pulseWidthDegrees * timerTicksPerDegree;
  OCR1B = pulseWidthTime;

  //start Timer apply prescaler
  //TCCR1B |= (1 << CS12) | (1 << CS10); //1024 for led test 8us tick
  TCCR1B |= (1<<CS11) | (1<<CS10);//64 for .5 us tick

  //enable B OutputCompare and Overflow interrupts
  TIMSK1 |= (1 << OCIE1B) | (1 << TOIE1);
}

void loop() {
}

ISR(TIMER1_COMPB_vect) {
  digitalWrite(13, LOW);    //turn off pulse for 0 volt
  digitalWrite(pinA, LOW);  //DAC 6 LOW
  digitalWrite(pinB, HIGH); //DAC 5 HIGH
}

ISR(TIMER1_OVF_vect) {
  //alternate ICR1 values to generate two outputs
  //360 degree cycle time broken into two pieces
  static byte count = 0;
  if (count == 0) //first pulse
  {
    ICR1 = timerTicksPerDegree * (pulseWidthDegrees + barWidthDegrees); //first pulse and bar width
    digitalWrite(13, HIGH);
    if (firstPulsePos == true)
      setPulsePos();
    else
      setPulseNeg();//first pulse neg if firstPulsePos == false
  }
  
  if (count == 1)//second pulse
  {
    ICR1 = timerTicksPerDegree * (360 - (pulseWidthDegrees + barWidthDegrees)); //second pulse and dead band
    digitalWrite(13, HIGH);
    if (firstPulsePos)
      setPulseNeg();
    else
      setPulsePos();//first pulse was negative
  }
  count++;
  if (count == 2)
    count = 0;
}

void setPulsePos()
{
  digitalWrite(pinA, HIGH);  //DAC 6 HIGH
  digitalWrite(pinB, HIGH);  //DAC 5 HIGH
}

void setPulseNeg()
{
  digitalWrite(pinA, LOW );  //DAC 6 LOW
  digitalWrite(pinB, LOW);  //DAC 5 LOW
}

Hi, OK it works changing the polarity. I have assigned different pins, here is my choice,
D3 - timing signal from clamp on probe.
D4 - polarity switch
D5 - rise / fall
D6 - controls AC - DC output
D7 - output for charge pulses
D8 - to DAC 5
D9 - to DAC 6 - 12

This is the schematic of the whole tester.
Thanks, Tom

CDI_tester.pdf (32.6 KB)