why is delay without millis not being executed?

I want a loop to be executed "x" times.

const byte x = 8;

After this execution I want to suspend execution during time "interval1" and after that resume, etc..

int long interval1 = 5000; // 5 seconds

However the code below is being executed without any suspended period.

What is wrong here?

// https://forum.arduino.cc/index.php?topic=410853.15
// http://forum.arduino.cc/index.php?topic=507719.0
// Test PWM period and width measurement (connect pin 3 to pin 8)
// Measurement timing diagram: http://i.imgur.com/NqV4nXe.png
// code without the PWM generating part

volatile word timerValue[4];
volatile byte testState = 0;

boolean newValuesAvailable = false;
float pwmPeriod, pwmWidth, pwmDuty, pwmFrequency;

const byte x = 8; // loop value: loop amount = x+2 because min and max values are removed
unsigned long previousMillis1 = 0; // timer 1
const long interval1 = 5000; // interval between readings
int long interval; // intermediate storage for interval
unsigned int dutyCycleFinal; // final result for duty cycle



void setup()
{
  // TIMSK0 = 0;   // for testing with timer0 disable
  Serial.begin(115200);
}

void loop()
{
int repeat1 = 0;  
unsigned int signalMax1 = 0; // max value for duty cycle
unsigned long int signalMin1 = 100; // min value for duty cycle
unsigned long currentMillis = millis();

  if ((currentMillis - previousMillis1) >= interval)
  {
  previousMillis1 = currentMillis;  
  getPwmValues();
  if (newValuesAvailable)
  {
    
    while (repeat1 < x)
    {
    repeat1++;
      
    newValuesAvailable = false;
    Serial.print("pwmPeriod     ");
    Serial.print(pwmPeriod, 3);
    Serial.println(" us");

    Serial.print("pwmWidth      ");
    Serial.print(pwmWidth, 3);
    Serial.println(" us");

    Serial.print("pwmDuty       ");
    Serial.print(pwmDuty, 3);
    Serial.println(" %");

    Serial.print("pwmFrequency  ");
    Serial.print(pwmFrequency, 3);
    Serial.println(" kHz");
    Serial.println();
    }
  }
  // delay(500000);
  }
}

void pwmMeasureBegin()
{
  TCCR1A = 0;       // normal operation mode
  TCCR1B = 0;       // stop timer clock (no clock source)
  TCNT1  = 0;      // clear counter
  TIFR1 = bit (ICF1) | bit (TOV1); // clear flags
  testState = 0;   // clear testState
  TIMSK1 = bit (ICIE1); // interrupt on input capture
  TCCR1B =  bit (CS10) | bit (ICES1);// start clock with no prescaler, rising edge on pin D8
}

ISR (TIMER1_CAPT_vect)
{
  switch (testState) {
    case 0: // first rising edge
      timerValue[0] = ICR1;
      testState = 1;
      break;
    case 1: // second rising edge
      timerValue[1] = ICR1;
      TCCR1B &=  ~bit (ICES1); // capture on falling edge (pin D8)
      testState = 2;
      break;
    case 2:  // first falling edge
      testState = 3;
      break;
    case 3: // second falling edge
      timerValue[2] = ICR1;
      testState = 4;
      break;
    case 4: // third falling edge
      timerValue[3] = ICR1;
      testState = 5;  // all tests done
      TCCR1B = 0; //stop timer
      break;
  }
}

void getPwmValues()
{
  static boolean measurementInProcess = false;
  if (!measurementInProcess)
  {
    pwmMeasureBegin();
    measurementInProcess = true;
  }
  else if (testState == 5)//measurement complete
  {
    calculatePwmValues();
    measurementInProcess = false; //reset
  }
}

void calculatePwmValues()
{
  word periodValue = timerValue[3] - timerValue[2];
  word widthValue = timerValue[2] - timerValue[1];
  word diffValue = widthValue - periodValue;

  pwmPeriod = (periodValue * 0.0625);
  pwmWidth = diffValue * .0625;
  pwmDuty = (pwmWidth / pwmPeriod) * 100;
  pwmFrequency = 1000 / pwmPeriod;

  newValuesAvailable = true;
}

Sorry, solved: syntax error on line 34.

if ((currentMillis - previousMillis1) >= interval)

should be

if ((currentMillis - previousMillis1) >= interval1)

BTW
You can remove the ()
if (currentMillis - previousMillis1 >= interval1)

That is a user error but it is not a syntax error !

larryd:
BTW
You can remove the ()
if (currentMillis - previousMillis1 >= interval1)

Great! I am still in doubt when to and when not to "()"; especially with combined "or" and "and" statements.

UKHeliBob:
That is a user error but it is not a syntax error !

heuu... please enlighten me? Thanks

The point was the ( ) are extraneous.

.

larryd:
The point was the ( ) are extraneous.

.

OP is referring to the difference between using interval and interval1. A syntax error results from a deviation from the grammar of the language. A programmer error might not do that.

As most of us have experienced, it is quite possible to have a program that compiles perfectly and has errors. Those errors are a result of the difference between the structure of the program, and the programmer's intent.

larryd:
The point was the ( ) are extraneous.

.

Yes, that part I understood. But I had coded in the past where "or" and "and" was needed in "if" statements and I found that my assumptions of logic precedence did either not work, or I had made the wrong assumptions about precedence. Issues were solved by adding "()".
But I realise there must be a very logical explanantion; I just have not made it yet to studying them.

aarg:
OP is referring to the difference between using interval and interval1. A syntax error results from a deviation from the grammar of the language. A programmer error might not do that.

ah ok!

brice3010:
heuu... please enlighten me? Thanks

A syntax error involves getting the structure of a command wrong as in

pinMode(aPin);

Note the missing second parameter
or

Serial.print("Hello World);

Note the missing closing quotes

Your error did not cause a compiler error because what you wrote was syntactically correct code. The compiler had no way of knowing that you had used the wrong variable in the comparison.

aarg:
OP is referring to the difference between using interval and interval1. A syntax error results from a deviation from the grammar of the language. A programmer error might not do that.
. . .

That’s why the reference was BTW, no implication was made that ( ) would not work.
"can remove" this was not written as 'must remove'

Way too much time spent on this.

I think, if you had a compiler that could always know that you inadvertently used the wrong variable, you would be well on the way to having a compiler that could write code, i.e. be a programmer.

UKHeliBob:
A syntax error involves getting the structure of a command wrong as in

pinMode(aPin);

Note the missing second parameter
or

Serial.print("Hello World);

Note the missing closing quotes

Your error did not cause a compiler error because what you wrote was syntactically correct code. The compiler had no way of knowing that you had used the wrong variable in the comparison.

Thanks!