if with ORed conditions is different than direct value

Hello,

I'm working on IR decoding with C and I compile and upload the code with Arduino IDE using pro micro board.

So what I noticed is the timing of blinking on board LED is different using two different types of conditions:

  1. When I state if condition with ORed arguments (count < 100)||(count > 80)
  2. When I state if condition with direct equal argument (count = 90)

The first one has faster blinking almost double the speed of the second type of if argument condition.

So, what is the reason?

My code:

void setup() {
  // put your setup code here, to run once:
DDRB = 0x00;
DDRD = 0x20;
PORTB |= (1<<PB5);
}

void loop() {
  uint32_t ir_code;
  uint16_t count=0,i;
  while (!(PINB & (1 << PINB5)))
  {
    count++;
    _delay_us(100);  
    //Serial.println(count); 
    if (count == 90)
    {
    PORTD |= (1<<PD5);
    _delay_ms(50);
    PORTD &= ~(1<<PD5);
    _delay_ms(50);
    }
  }
}

In the case of

(count < 100)||(count > 80)

isn't this ALWAYS going to be true? It seems to me that count is ALWAYS either greater than 80 or less than 100, and sometimes both.

Isn't this different from (count == 90) ?

Of course, if you had provided BOTH version of the ACTUAL code, someone might be able to make an informed suggestion. What we can say absolutely, positively, 100% for certain is that there will be NO discernable difference in ANY aspect of the programs execution using either of the two expressions you describe, if properly coded. There is something ELSE wrong with your code that is causing the visible difference you cite.

Regards,
Ray L.

vaj4088:
In the case of

(count < 100)||(count > 80)

isn't this ALWAYS going to be true? It seems to me that count is ALWAYS either greater than 80 or less than 100, and sometimes both.

Isn't this different from (count == 90) ?

I thought about this, that (count == 90), isn't always true. But, I tested the accuracy of the pro micro board and it's very accurate.

And so (count == 90) should occur every time it matches this condition.

But the other condition is different! It's almost double the speed, so I don't think it's because (count == 90) occurs less frequent than (count < 100)||(count > 80).

RayLivingston:
Of course, if you had provided BOTH version of the ACTUAL code, someone might be able to make an informed suggestion. What we can say absolutely, positively, 100% for certain is that there will be NO discernable difference in ANY aspect of the programs execution using either of the two expressions you describe, if properly coded. There is something ELSE wrong with your code that is causing the visible difference you cite.

Regards,
Ray L.

The code in the original post is the actual code, you just have to change the if argument in the while loop.

I should edit the post and comment where you change the condition.

I don't know what is wrong with my code as it's very simple and there's nothing else to change in the code except the if arguments.