Loop's run time

Hi! I have a project, make an EFI ECU. How can i set the LOOP’s run time to 10 ms? The loop is only calculate the injection time. For avoid the fault it have been restarted every 10 ms. Any idea?

Ricsard:
Hi! I have a project, make an EFI ECU. How can i set the LOOP's run time to 10 ms? The loop is only calculate the injection time. For avoid the fault it have been restarted every 10 ms. Any idea?

You don't make the loop run at that specific time, what you do is, every time through the loop, you check if something is due to happen yet.

something like

unsigned long lastThing=0;
void loop()
{
  unsigned long t=millis();

  if(t-lastThing>9)
  {//Do your thing here

    //and update your reminder for next time
    lastThing += 10;
  }

}

You are looking at this the wrong way. Let the loop() function run as fast as it can but arrange for what you want to happen every 10 ms. Have a look at the BlinkWithouutDelay example in the IDE to see how to do this without blocking execution of other code.

I have to create semaphore, like PIC. While the loop run, the interrupts are worked per about 7-15 ms . I want that, the loop is calculated, and after 10 ms, the loop restart, wherever it takes.

You can lead a horse to water.

KenF:
You can lead a horse to water.

but you can't make it blink without delay()

Ricsard:
I have to create semaphore, like PIC. While the loop run, the interrupts are worked per about 7-15 ms . I want that, the loop is calculated, and after 10 ms, the loop restart, wherever it takes.

Even allowing for "Sorry my English is very bad" this question makes very little sense.

I do not know PIC or what it does with Semaphores (you can program Arduino C to implement any Semaphore you like)
"The interrupts are worked .. 7-15ms". If you mean your interrupts use 7 to 15 ms, then you have a very bad interrupt code. If you mean the interrupt is triggered every 7 to 15 ms then that is fine - and has NOTHING to do with loop() time.

If you wanted something to happen 10 ms after the interrupt is triggered (that is what I GUESS you are trying to say) then you do use the BlinkWithoutDelay as a starting point.

  1. The interrupt code sets a volitile byte variable to 1
  2. The loop checks if the variable is 1, if so
    2a set it back 0 . Note current millis() in the timer
  3. if millis()-timer >10 do the action (possibly with another variable so it only is done once)

But to answer the first question . NO you can NOT reprogram the loop() speed. "Whatever it takes" makes no differnece, it can not be done.