hey, i'm looking for support to figure out in what case the 'false' result can break the while loop, or any other mistake i made;
in the code, the 'x' was a const int e.g. 2000; in principle, the serial print result to be exactly '2000';
but in my practice, if run this code in a loop, i'll get something like 2000,1890,2000,2000,1890,2000,1890..... and this sequence it was not repeatable, the'1890' seems to be randomly appreared, but each time the 'tolerence' was the same(always 1890);
i can hardly understand why 'step_count=1890' can break the while loop, and below is part of my code:
while(step_count<x)
{
if (loaded==0)
{if(digitalRead(outer)==0)
{digitalWrite(motora1, HIGH); //loaded and stop rolling
loaded=1;shooted=0;
//timerecord();//loaded time
}
else{}}
}
Serial.println(step_count);
step_count=0;
//and 'step_count' was designed in below ISR to record the stepper
ISR(TIMER1_COMPA_vect)
{
//accel mode, index_acc = x; twice_coe=1; index_acc +1 and steps + 1 every two PB0 inverse
if (ticks) //
{
PORTB^=(1<<0);
twice_coe=!twice_coe;
if (twice_coe)
{
step_count++;
switch(flag)
{
case SLIP:
break;
case ACCEL:
if (index_acc==accel_step){flag=SLIP;} //set the accel_step as the limitation of max speed
else{
index_acc++;
OCR1A = pgm_read_word_near(speed_table+index_acc);
}
break;
case DECEL:
if (index_acc==0){flag=STOP;}
else{
index_acc--;
OCR1A = pgm_read_word_near(speed_table+index_acc);
}
break;
case STOP:
TIMSK1 &=(~(1 << OCIE1A));
digitalWrite(steperEN,1);
step_count=0;
break;
}
}
ticks=!ticks;
}
else {
ticks=!ticks;
}
}
```````````````