-1

I want to use Arduino Uno (Rev. 3) resp. Arduino Nano for time critical ignition control of a combustion engine. Software is developed under arduino rev. 1.6.2.

The only Arduino system functions i use are micros() and delayMicroseconds(). I suppose they are implemented by a timer interrupt, which may fire within time critical port polling regions of the program.

What's the maximum runtime for the ISR i have to expect? As long it stays within the range of a few microseconds, say 10 or like, it would be tolerable.

Are there other time ressources used in the background by the arduino system i have to cope with?

1

Here is the The ISR code.

Here is the obj-dump:

000008f6 <__vector_16>:
#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ISR(TIM0_OVF_vect)
#else
ISR(TIMER0_OVF_vect)
#endif
{
 8f6:   1f 92           push    r1
 8f8:   0f 92           push    r0
 8fa:   0f b6           in  r0, 0x3f    ; 63
 8fc:   0f 92           push    r0
 8fe:   11 24           eor r1, r1
 900:   2f 93           push    r18
 902:   3f 93           push    r19
 904:   8f 93           push    r24
 906:   9f 93           push    r25
 908:   af 93           push    r26
 90a:   bf 93           push    r27
    // copy these to local variables so they can be stored in registers
    // (volatile variables must be read from memory on every access)
    unsigned long m = timer0_millis;
 90c:   80 91 a0 01     lds r24, 0x01A0
 910:   90 91 a1 01     lds r25, 0x01A1
 914:   a0 91 a2 01     lds r26, 0x01A2
 918:   b0 91 a3 01     lds r27, 0x01A3
    unsigned char f = timer0_fract;
 91c:   30 91 9f 01     lds r19, 0x019F

    m += MILLIS_INC;
    f += FRACT_INC;
 920:   20 e3           ldi r18, 0x30   ; 48
 922:   23 0f           add r18, r19
    if (f >= FRACT_MAX) {
 924:   2d 37           cpi r18, 0x7D   ; 125
 926:   20 f4           brcc    .+8         ; 0x930 <__stack+0x31>
    // copy these to local variables so they can be stored in registers
    // (volatile variables must be read from memory on every access)
    unsigned long m = timer0_millis;
    unsigned char f = timer0_fract;

    m += MILLIS_INC;
 928:   40 96           adiw    r24, 0x10   ; 16
 92a:   a1 1d           adc r26, r1
 92c:   b1 1d           adc r27, r1
 92e:   05 c0           rjmp    .+10        ; 0x93a <__stack+0x3b>
    f += FRACT_INC;
    if (f >= FRACT_MAX) {
        f -= FRACT_MAX;
 930:   23 eb           ldi r18, 0xB3   ; 179
 932:   23 0f           add r18, r19
        m += 1;
 934:   41 96           adiw    r24, 0x11   ; 17
 936:   a1 1d           adc r26, r1
 938:   b1 1d           adc r27, r1
    }

    timer0_fract = f;
 93a:   20 93 9f 01     sts 0x019F, r18
    timer0_millis = m;
 93e:   80 93 a0 01     sts 0x01A0, r24
 942:   90 93 a1 01     sts 0x01A1, r25
 946:   a0 93 a2 01     sts 0x01A2, r26
 94a:   b0 93 a3 01     sts 0x01A3, r27
    timer0_overflow_count++;
 94e:   80 91 a4 01     lds r24, 0x01A4
 952:   90 91 a5 01     lds r25, 0x01A5
 956:   a0 91 a6 01     lds r26, 0x01A6
 95a:   b0 91 a7 01     lds r27, 0x01A7
 95e:   01 96           adiw    r24, 0x01   ; 1
 960:   a1 1d           adc r26, r1
 962:   b1 1d           adc r27, r1
 964:   80 93 a4 01     sts 0x01A4, r24
 968:   90 93 a5 01     sts 0x01A5, r25
 96c:   a0 93 a6 01     sts 0x01A6, r26
 970:   b0 93 a7 01     sts 0x01A7, r27
}
 974:   bf 91           pop r27
 976:   af 91           pop r26
 978:   9f 91           pop r25
 97a:   8f 91           pop r24
 97c:   3f 91           pop r19
 97e:   2f 91           pop r18
 980:   0f 90           pop r0
 982:   0f be           out 0x3f, r0    ; 63
 984:   0f 90           pop r0
 986:   1f 90           pop r1
 988:   18 95           reti

I'll let you calculate how many clock cycles that is. My guess is that it's less that 160 clock cycles (i.e. 10S).

But I'm unsure if the accuracy of micros is good enough in your application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.