Go Down

Topic: CDI tester project (Read 13533 times) previous topic - next topic

cattledog

I've got a 20x4 on order, and should be able to work in your format when it arrives.

tom_bauer

Hi, on lines 61 to 69 and then 102 to 109 there is lcd info that seems to conflict in a way I don't understand.
Tom

cattledog

Because I was working with a 16x2 display, I didn't have the real estate for your current display parameters, so I tried to use a set up screen and then an operating screen.  I will have a 20x4 in a few days and can go back to your original approach with one screen.

Quote
that seems to conflict in a way I don't understand.
Can you explain more.

These lines are for a setup screen, and the values are filled in with the print statement in the setupSwitchPresets() function

Code: [Select]
//61-69
lcd.begin(16, 2);
lcd.setCursor(0, 0); // lcd display setup of unchanging headings
lcd.print("RPM:"); // print fixed characters
lcd.setCursor(9, 0);
lcd.print("Mode:");
lcd.setCursor(0, 1);
lcd.print("1stPulse:"); //first pulse + or -
lcd.setCursor(11, 1);


These lines are for the operating screen and show the current RPM from the pot setting, and the delay of the return pulse from the module from the point in time when the R or F edge of trigger pulse was sent.

Code: [Select]
/102-109
lcd.setCursor(4, 0);
lcd.print("           "); // print blank spaces to clear old data
lcd.setCursor(5, 0);
lcd.print(RPM);
lcd.setCursor(9, 1);
lcd.print("       ");
lcd.setCursor(10, 1);
lcd.print(delayDegrees, 1);


We should get bact to the 20x4, and display what ever data makes sense to you.

tom_bauer

Hi, OK I think I see. Yes I would like to go to the display I had, it shows everything I want to know. No need for the firstPulse info, I will see if the toggle switch is up for + or down for -. Also I prefer the Degrees Advanced, I had a calculation in the last code that did that quite well.
Tom

tom_bauer

Hi, I have done some testing and here is my revision of the code. Pins 6, 5, 4 do not update, require a reboot, how to have them reset parameters when they are changed?

No charge pulses on pin 7.

LCD would not work until I moved the code from line 248 to 129 and from 259 to 123

Tom



Code: [Select]
//V1.0 set RPM potentiometer/configuration swtiches/hd44780 lcd/revised pin numbers

#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h> // include i/o class header
hd44780_I2Cexp lcd; // declare lcd object: auto locate & config display for hd44780 chip

//utility definitions
#define positive HIGH
#define negative LOW
#define firstPulse 0
#define secondPulse 1

//You can use pots to set RPM, pulseWidthDegrees, and barWidth
//unsigned int RPM = 1200;//adjusted with potementiometer
unsigned int pulseWidthDegrees = 10;
unsigned int barWidthDegrees = 60;
int pickupPositionOffset = 0; //timing offset from TDC

unsigned long pulseWidthTime;//degrees converted to time
unsigned long timerTopValue;//sets 360 degree cycleTime
unsigned int timerTicksPerDegree;

//output pins
const byte chargePin = 7; //charge pulses
const byte pinB = 8;      //to DAC pin 5
const byte pinA = 9;      //to DAC pin 6 - 12, called 6

//configuration switch setup
const byte polaritySwitch = 4;
boolean firstPulsePos = positive; //first pulse polarity
const byte setFallingSwitch = 5;
char risefall = 'R'; //default rising mode start timing from rising edge
const byte setChargePulseSwitch = 6;
boolean chargePulse = false ;  //AC CDI default is DC

int pot1 = A3; //input pin for pot which sets rpm

//return pulse interrupt variables
volatile boolean trigger = false;
volatile boolean interruptFlag;
volatile unsigned long delayPeriod;
unsigned long copy_delayPeriod;
volatile unsigned long delayPeriodStart;
float delayDegrees; // changed from int to float for decimal place display


int RPM;
int pickup;
int barWidth;
int pulseWidth;


void setup()
{
  Serial.begin(115200);
  //set outputs for 0v
  pinMode(13, OUTPUT); //telltale led
  digitalWrite(13, LOW);
  pinMode(pinA, OUTPUT);
  digitalWrite(pinA, LOW);  //DAC 6 LOW
  pinMode(pinB, OUTPUT);
  digitalWrite(pinB, HIGH); //DAC 5 HIGH
  pinMode(3, INPUT_PULLUP); //interrupt pin, return pulse drives low
  pinMode(chargePin, OUTPUT); // declare the chargePin as an OUTPUT

  // initialize LCD with number of columns and rows:
  lcd.begin(20, 4); // initialize the lcd for 20 chars 4 lines, turn on backlight
  lcd.setCursor(0, 0); // lcd display setup of unchanging headings
  lcd.print("RPM:"); // print fixed characters
  lcd.setCursor(9, 0);
  lcd.print("Mode:"); //to display code choice R or F
  lcd.setCursor(1, 1);
  lcd.print("Pos:");
  lcd.setCursor(9, 1);
  lcd.print("Width:");
  lcd.setCursor(1, 2);
  lcd.print("Us Delay:");
  lcd.setCursor(1, 3);
  lcd.print("Deg Advance:");

  setupTimer1();
  setupSwitchPresets();

  //15000000 timerTicksperMinute at 4 us per tick with prescaler 64
  //timerTopValue = 12500 at 1200 RPM 50ms per revolution
  timerTopValue = 15000000UL / RPM;
  timerTicksPerDegree = timerTopValue / 360;
  pulseWidthTime = pulseWidthDegrees * timerTicksPerDegree;
  TCNT1 = 0;
  OCR1B = pulseWidthTime;//timer ticks
  attachInterrupt(digitalPinToInterrupt(3), delayPeriodTiming, FALLING);
  delay(5000);//display setup parameters
  //lcd.setCursor(0, 1);
 //lcd.print("DelayDeg:");
}

void loop()
{
  const unsigned long analogReadInterval = 250;//250; //read pots and map
  static unsigned long lastAnalogRead = 0;
  if (millis() - lastAnalogRead >= analogReadInterval)
  {
    //add other potentiometer adjustments here
    lastAnalogRead += analogReadInterval;
    RPM = map(analogRead(pot1), 0, 1023, 500, 4000);
    //adjust timer values for RPM
    timerTopValue = 15000000UL / RPM;
    timerTicksPerDegree = timerTopValue / 360;
    pulseWidthTime = pulseWidthDegrees * timerTicksPerDegree;
    OCR1B = pulseWidthTime;

    lcd.setCursor(4, 0);
    lcd.print("     "); // print blank spaces to clear old data
    lcd.setCursor(4, 0);
    lcd.print(RPM);

    lcd.setCursor(14, 0);
    lcd.print("  ");
    lcd.setCursor(14, 0);
    lcd.print(risefall); //print R or F at upper right side

    lcd.setCursor(16, 0);
  if (firstPulsePos)
    lcd.print("+");
  else
    lcd.print("-");

    lcd.setCursor(18, 0);   
  if (chargePulse)
    lcd.print("AC");
  else
    lcd.print("DC");

    lcd.setCursor(6, 1);
    lcd.print("   ");
    lcd.setCursor(6, 1);
    lcd.print(pickup);

    lcd.setCursor(16, 1);
    lcd.print("   ");
    lcd.setCursor(16, 1);
    lcd.print(pulseWidth);

    lcd.setCursor(11, 2);
    lcd.print("       ");
    lcd.setCursor(11, 2);
    lcd.print(copy_delayPeriod);
   
    lcd.setCursor(14, 3);
    lcd.print("      ");
    lcd.setCursor(14, 3);
    lcd.print(delayDegrees, 1);   //delayDegrees, 1);
  }

  if (trigger == true && interruptFlag == true )
  {
    trigger = false;
    interruptFlag = false;
    noInterrupts();
    copy_delayPeriod = delayPeriod;//microseconds
    interrupts();
    //Serial.print(copy_delayPeriod);
    //Serial.print('\t');
    //divide by 4 to convert microseconds to timer ticks
    delayDegrees = (copy_delayPeriod / 4) / timerTicksPerDegree;
    //Serial.println(delayDegrees);
    //delayDegrees = pickup - (360.0 * (copy_delayPeriod) / (timerTopValue * 4.0)); //for decimal place in deg display.
  }
}

void setupTimer1()
{
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;
  //set Timer1 mode Fast PWM to ICR1
  TCCR1B |= (1 << WGM13) | (1 << WGM12);
  TCCR1A |= (1 << WGM11);
  //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);
}

ISR(TIMER1_OVF_vect)
{
  //alternate ICR1 values to generate two outputs over 360 degrees
  //360 degree cycle time broken into two pieces
  //timerTopValue adjusted with RPM pot
  //timerTicksPerDegree = timerTopValue / 360; //gets new value to update ICR1
  static byte pulse = firstPulse;
  if (pulse == firstPulse)
  {
    ICR1 = timerTicksPerDegree * (pulseWidthDegrees + barWidthDegrees); //first pulse and bar width
    digitalWrite(13, HIGH);
    if (firstPulsePos == true)
      setPulse(positive);
    else
      setPulse(negative);
    //set timing start at lead edge of first pulse
    if (risefall == 'R')
    {
      delayPeriodStart = micros();                                          //start looking for response as pulse rises
      trigger = true;
    }
    else //risefall == 'F' set timing at trailing edge of first pulse
    {
      //convert pulseWidthTime in timer ticks to microseconds
      //prescaler 8 = 4us/timer tick
      delayPeriodStart = micros() + pulseWidthTime * 4;                    //start looking for response as pulse rises
      trigger = true;
    }
    pulse = secondPulse; //next pulse
  }
  else //second pulse
  {
    ICR1 = timerTicksPerDegree * (360 - (pulseWidthDegrees + barWidthDegrees)); //second pulse and dead band
    digitalWrite(13, HIGH);
    if (firstPulsePos)
      setPulse(negative);
    else
      setPulse(positive);
    pulse = firstPulse; //next pulse
  }
}

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
}

void setPulse(byte state)    //state negative = LOW state positive = HIGH
{
  digitalWrite(pinA, state );  //DAC 6 state
  digitalWrite(pinB, state);  //DAC 5 state
}

void setupSwitchPresets()
{
  pinMode(setChargePulseSwitch, INPUT_PULLUP);
  if (digitalRead(setChargePulseSwitch) == LOW)
    chargePulse = true; //AC CDI
  else
    chargePulse = false;
  //lcd.setCursor(19, 0);   //moved to line 129
  //if (chargePulse)
    //lcd.print("Y");
  //else
    //lcd.print("N");

  pinMode(polaritySwitch, INPUT_PULLUP);
  if (digitalRead(polaritySwitch) == HIGH)
    firstPulsePos = true; //first pulse positive
  else
    firstPulsePos = false; //first pulse negative
  //lcd.setCursor(17, 0);   // moved to line 123
  //if (firstPulsePos)
    //lcd.print("+");
  //else
    //lcd.print("-");

  pinMode (setFallingSwitch, INPUT_PULLUP); //check for a LOW input to indicate switch is closed to ground
  if (digitalRead(setFallingSwitch) == LOW) //set Falling
  {
    risefall = 'F';
  }
  else
  {
    risefall = 'R';
  }
  //lcd.setCursor(14, 0);
  //lcd.print(risefall);
}

void delayPeriodTiming()
{
  delayPeriod = micros() - delayPeriodStart;
  interruptFlag = true;
}


cattledog

#200
Feb 02, 2019, 12:30 am Last Edit: Feb 02, 2019, 12:57 am by cattledog
Nice progress getting the code back to the 20x4 display.

Quote
Pins 6, 5, 4 do not update, require a reboot, how to have them reset parameters when they are changed?
Add the function setupSwitchPresets() into this section of loop(). The pinMode() calls in the function should  be moved into setup().

Code: [Select]
if (millis() - lastAnalogRead >= analogReadInterval)
  {
      //all the pot/switch reading to change settings and display them code
   }


Quote
No charge pulses on pin 7.
Correct. I am working on the timer2 and charge pulse code now. With the dual pulses I think there may be some changes about how the charge pulses are coordinated and synced to the trigger pulse.

Quote
LCD would not work until I moved the code from line 248 to 129 and from 259 to 123
This does not make sense to me, but when I get the 20x4 on line I can revisit this. It does not make any difference it you are going to change the toggle switch settings while the code is running.

Quote
Also I prefer the Degrees Advanced, I had a calculation in the last code that did that quite well.
First, declare a new global variable called degreesAdvance and call it when/where you want to display it on the lcd.

Then add a new line to the code after the line of code which calculates the delayDegrees from the interrupt timing of the delayPeriod.

Code: [Select]
delayDegrees = (copy_delayPeriod / 4) / timerTicksPerDegree;
degreesAdvance = pickup - delayDegrees;


This will be the degrees before TDC of  the return pulse.

When do you think you will have the hardware set up to test the dual pulses? Can you do that without the charge pulses?





tom_bauer

'Add the function setupSwitchPresets() into this section of loop(). The pinMode() calls in the function should  be moved into setup().

Code: [Select]
if (millis() - lastAnalogRead >= analogReadInterval)
  {
      //all the pot/switch reading to change settings and display them code
   }
'
This I do not really understand..??

OK re the charge pulses, actually now it may be good to have twice as many pulses for the charge output to drive the transformer that makes the AC.

'This does not make sense to me, but when I get the 20x4 on line I can revisit this. It does not make any difference it you are going to change the toggle switch settings while the code is running.'
The way it was the Arduino would not even start until I commented out those lines.

'First, declare a new global variable called degreesAdvance and call it when/where you want to display it on the lcd.
Then add a new line to the code
Code: [Select]
delayDegrees = (copy_delayPeriod / 4) / timerTicksPerDegree;
degreesAdvance = pickup - delayDegrees;

This will be the degrees before TDC of  the return pulse.'

OK I will work on this after I get the hardware set up.

'When do you think you will have the hardware set up to test the dual pulses? Can you do that without the charge pulses?'

Yes I can, but the pulses look correct on the scope so I have little doubt it will work correctly when wired up. Bread board should be here tomorrow.
Tom





[/quote]

cattledog

Quote
'Add the function setupSwitchPresets() into this section of loop(). The pinMode() calls in the function should  be moved into setup().
Quote
This I do not really understand..??
Code: [Select]
//V1.0 set RPM potentiometer/configuration swtiches/hd44780 lcd/revised pin numbers

#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h> // include i/o class header
hd44780_I2Cexp lcd; // declare lcd object: auto locate & config display for hd44780 chip

//utility definitions
#define positive HIGH
#define negative LOW
#define firstPulse 0
#define secondPulse 1

//You can use pots to set RPM, pulseWidthDegrees, and barWidth
//unsigned int RPM = 1200;//adjusted with potementiometer
unsigned int pulseWidthDegrees = 10;
unsigned int barWidthDegrees = 60;
int pickupPositionOffset = 0; //timing offset from TDC

unsigned long pulseWidthTime;//degrees converted to time
unsigned long timerTopValue;//sets 360 degree cycleTime
unsigned int timerTicksPerDegree;

//output pins
const byte chargePin = 7; //charge pulses
const byte pinB = 8;      //to DAC pin 5
const byte pinA = 9;      //to DAC pin 6 - 12, called 6

//configuration switch setup
const byte polaritySwitch = 4;
boolean firstPulsePos = positive; //first pulse polarity
const byte setFallingSwitch = 5;
char risefall = 'R'; //default rising mode start timing from rising edge
const byte setChargePulseSwitch = 6;
boolean chargePulse = false ;  //AC CDI default is DC

int pot1 = A3; //input pin for pot which sets rpm

//return pulse interrupt variables
volatile boolean trigger = false;
volatile boolean interruptFlag;
volatile unsigned long delayPeriod;
unsigned long copy_delayPeriod;
volatile unsigned long delayPeriodStart;
float delayDegrees; // changed from int to float for decimal place display


int RPM;
int pickup;
int barWidth;
int pulseWidth;


void setup()
{
  Serial.begin(115200);
  //set outputs for 0v
  pinMode(13, OUTPUT); //telltale led
  digitalWrite(13, LOW);
  pinMode(pinA, OUTPUT);
  digitalWrite(pinA, LOW);  //DAC 6 LOW
  pinMode(pinB, OUTPUT);
  digitalWrite(pinB, HIGH); //DAC 5 HIGH
  pinMode(3, INPUT_PULLUP); //interrupt pin, return pulse drives low
  pinMode(chargePin, OUTPUT); // declare the chargePin as an OUTPUT
  //add toggle switch pinMode
  pinMode(setFallingSwitch, INPUT_PULLUP);
  pinMode(polaritySwitch, INPUT_PULLUP);
  pinMode(setChargePulseSwitch, INPUT_PULLUP);

  // initialize LCD with number of columns and rows:
  lcd.begin(20, 4); // initialize the lcd for 20 chars 4 lines, turn on backlight
  lcd.setCursor(0, 0); // lcd display setup of unchanging headings
  lcd.print("RPM:"); // print fixed characters
  lcd.setCursor(9, 0);
  lcd.print("Mode:"); //to display code choice R or F
  lcd.setCursor(1, 1);
  lcd.print("Pos:");
  lcd.setCursor(9, 1);
  lcd.print("Width:");
  lcd.setCursor(1, 2);
  lcd.print("Us Delay:");
  lcd.setCursor(1, 3);
  lcd.print("Deg Advance:");

  setupTimer1();
  setupSwitchPresets();

  //15000000 timerTicksperMinute at 4 us per tick with prescaler 64
  //timerTopValue = 12500 at 1200 RPM 50ms per revolution
  timerTopValue = 15000000UL / RPM;
  timerTicksPerDegree = timerTopValue / 360;
  pulseWidthTime = pulseWidthDegrees * timerTicksPerDegree;
  TCNT1 = 0;
  OCR1B = pulseWidthTime;//timer ticks
  attachInterrupt(digitalPinToInterrupt(3), delayPeriodTiming, FALLING);
  delay(5000);//display setup parameters
  //lcd.setCursor(0, 1);
  //lcd.print("DelayDeg:");
}

void loop()
{
  const unsigned long analogReadInterval = 250;//250; //read pots and map
  static unsigned long lastAnalogRead = 0;
  if (millis() - lastAnalogRead >= analogReadInterval)
  {
    //add other potentiometer adjustments here
    lastAnalogRead += analogReadInterval;
    RPM = map(analogRead(pot1), 0, 1023, 500, 4000);
    //adjust timer values for RPM
    timerTopValue = 15000000UL / RPM;
    timerTicksPerDegree = timerTopValue / 360;
    pulseWidthTime = pulseWidthDegrees * timerTicksPerDegree;
    OCR1B = pulseWidthTime;

    setupSwitchPresets();

    lcd.setCursor(4, 0);
    lcd.print("     "); // print blank spaces to clear old data
    lcd.setCursor(4, 0);
    lcd.print(RPM);

    lcd.setCursor(14, 0);
    lcd.print("  ");
    lcd.setCursor(14, 0);
    lcd.print(risefall); //print R or F at upper right side

    lcd.setCursor(16, 0);
    if (firstPulsePos)
      lcd.print("+");
    else
      lcd.print("-");

    lcd.setCursor(18, 0);
    if (chargePulse)
      lcd.print("AC");
    else
      lcd.print("DC");

    lcd.setCursor(6, 1);
    lcd.print("   ");
    lcd.setCursor(6, 1);
    lcd.print(pickup);

    lcd.setCursor(16, 1);
    lcd.print("   ");
    lcd.setCursor(16, 1);
    lcd.print(pulseWidth);

    lcd.setCursor(11, 2);
    lcd.print("       ");
    lcd.setCursor(11, 2);
    lcd.print(copy_delayPeriod);

    lcd.setCursor(14, 3);
    lcd.print("      ");
    lcd.setCursor(14, 3);
    lcd.print(delayDegrees, 1);   //delayDegrees, 1);
  }

  if (trigger == true && interruptFlag == true )
  {
    trigger = false;
    interruptFlag = false;
    noInterrupts();
    copy_delayPeriod = delayPeriod;//microseconds
    interrupts();
    //Serial.print(copy_delayPeriod);
    //Serial.print('\t');
    //divide by 4 to convert microseconds to timer ticks
    delayDegrees = (copy_delayPeriod / 4) / timerTicksPerDegree;
    //Serial.println(delayDegrees);
    //delayDegrees = pickup - (360.0 * (copy_delayPeriod) / (timerTopValue * 4.0)); //for decimal place in deg display.
  }
}

void setupTimer1()
{
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;
  //set Timer1 mode Fast PWM to ICR1
  TCCR1B |= (1 << WGM13) | (1 << WGM12);
  TCCR1A |= (1 << WGM11);
  //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);
}

ISR(TIMER1_OVF_vect)
{
  //alternate ICR1 values to generate two outputs over 360 degrees
  //360 degree cycle time broken into two pieces
  //timerTopValue adjusted with RPM pot
  //timerTicksPerDegree = timerTopValue / 360; //gets new value to update ICR1
  static byte pulse = firstPulse;
  if (pulse == firstPulse)
  {
    ICR1 = timerTicksPerDegree * (pulseWidthDegrees + barWidthDegrees); //first pulse and bar width
    digitalWrite(13, HIGH);
    if (firstPulsePos == true)
      setPulse(positive);
    else
      setPulse(negative);
    //set timing start at lead edge of first pulse
    if (risefall == 'R')
    {
      delayPeriodStart = micros();                                          //start looking for response as pulse rises
      trigger = true;
    }
    else //risefall == 'F' set timing at trailing edge of first pulse
    {
      //convert pulseWidthTime in timer ticks to microseconds
      //prescaler 8 = 4us/timer tick
      delayPeriodStart = micros() + pulseWidthTime * 4;                    //start looking for response as pulse rises
      trigger = true;
    }
    pulse = secondPulse; //next pulse
  }
  else //second pulse
  {
    ICR1 = timerTicksPerDegree * (360 - (pulseWidthDegrees + barWidthDegrees)); //second pulse and dead band
    digitalWrite(13, HIGH);
    if (firstPulsePos)
      setPulse(negative);
    else
      setPulse(positive);
    pulse = firstPulse; //next pulse
  }
}

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
}

void setPulse(byte state)    //state negative = LOW state positive = HIGH
{
  digitalWrite(pinA, state );  //DAC 6 state
  digitalWrite(pinB, state);  //DAC 5 state
}

void setupSwitchPresets()
{
  //pinMode(setChargePulseSwitch, INPUT_PULLUP);
  if (digitalRead(setChargePulseSwitch) == LOW)
    chargePulse = true; //AC CDI
  else
    chargePulse = false;
  //lcd.setCursor(19, 0);   //moved to line 129
  //if (chargePulse)
  //lcd.print("Y");
  //else
  //lcd.print("N");

  //pinMode(polaritySwitch, INPUT_PULLUP);
  if (digitalRead(polaritySwitch) == HIGH)
    firstPulsePos = true; //first pulse positive
  else
    firstPulsePos = false; //first pulse negative
  //lcd.setCursor(17, 0);   // moved to line 123
  //if (firstPulsePos)
  //lcd.print("+");
  //else
  //lcd.print("-");

  //pinMode (setFallingSwitch, INPUT_PULLUP); //check for a LOW input to indicate switch is closed to ground
  if (digitalRead(setFallingSwitch) == LOW) //set Falling
  {
    risefall = 'F';
  }
  else
  {
    risefall = 'R';
  }
  //lcd.setCursor(14, 0);
  //lcd.print(risefall);
}

void delayPeriodTiming()
{
  delayPeriod = micros() - delayPeriodStart;
  interruptFlag = true;
}

cattledog

Quote
OK re the charge pulses, actually now it may be good to have twice as many pulses for the charge output to drive the transformer that makes the AC.
In the existing program, there are 5 pulses of 30 degrees starting at 60 degrees
ON at 60,120,180,240,300 = 2,4,6,8,10
OFF at 90,150,210,270,330 = 3,5,7,9,11[/quote]

Do you want say 10 pulses of 15 degrees over the same 240 degrees? Do you want something different than equal duty cycle on/off to cover more of the 360 with pulses. Can we be closer to TDC with the pulses. Now, there is 120 degrees around 0 with no pulses?

tom_bauer

Hi, No, never mind me, I was thinking wrong. Pulses are fine as is.
Tom

tom_bauer

Hi, OK, all tested, all working. Later today I may get to do final test of pulses for DAC just to confirm that they match rpm but I assume they do/will.
Tom

cattledog

Here is the code attached with the charge pulses back in. I have cleaned up some variables and nomenclature. The current code only displays one "width" and I wasn't sure if it was barWidthDegrees or pulseWidthDegrees. You may want to change the display to show both.





tom_bauer

Hi, I was adding the pots and changed a couple variable names and now it won't compile!! I must have done something dumb!
Tom

cattledog

Ok, Here's your version which now compiles. Tere was a misplaced bracket and an undefined variable.
I now have my 20x4 online so I can follow your work more closely,

I see a couple of problems with the code as provided.

You are mapping two values from the same pot. Is that correct?
Code: [Select]
pickupValue = map(analogRead(pot2), 0, 1023, 10, 90);
    barWidth = map(analogRead(pot2), 0, 1023, 20, 80);


I think this should be pickupValue if you want the pot controlled variable and not the fixed one I had.
Code: [Select]
lcd.print(pickup);

I leave you to make these changes to the code if I'm correct.

Have you had the charge pulses on the scope? If so, do they look correct in relationship to the trigger pulse?




cattledog

#209
Feb 08, 2019, 07:45 pm Last Edit: Feb 08, 2019, 08:50 pm by cattledog
I just noted another error in the analogRead() pot mapping section. The placement of the new readings had broken the if/else construction of the rpm mapping with and without the charge pulses. That section should look like this.

Code: [Select]
if (millis() - lastAnalogRead >= analogReadInterval)
  {
    //add other potentiometer adjustments here
    lastAnalogRead += analogReadInterval;
    if (chargePulse)//lowest rpm with charge pulse is 615
      RPM = map(analogRead(pot1), 0, 1023, 615, 4000);
    else
      RPM = map(analogRead(pot1), 0, 1023, 500, 4000);
    pickupValue = map(analogRead(pot2), 0, 1023, 10, 90);//two variables on same pot
    barWidth = map(analogRead(pot2), 0, 1023, 20, 80);//two variables on same pot

  }


EDIT:

With the new adjustable variable pickupValue the code for degreesAdvance should change.

Code: [Select]
//degreesAdvance = pickup - delayDegrees;
    degreesAdvance = pickupValue - delayDegrees;

Go Up