cancel
Showing results for 
Search instead for 
Did you mean: 

How long does a nop instruction take at max. HSI (16MHz) ?

jeffrey23
Associate II
Posted on April 29, 2010 at 01:51

How long does a nop instruction take at max. HSI (16MHz) ?

6 REPLIES 6
fggnrc2
Associate II
Posted on May 17, 2011 at 15:08

Boltnut,

an empty ISR doesn't takes as much clock cycles as a nop.

The STM8 CPU Programming Manual shows what happens when an ISR is serviced:

the STM8 core pushes PCL, PCH, PCE, Y, X, A and CC registers onto the stack before fetching the ISR interrupt vector. This takes 9 clock cycles.

If your ISR is empty, i.e. it consists only in an IRET, another 9 clock cycles are needed to restore those registers.

EtaPhi

jeffrey23
Associate II
Posted on May 17, 2011 at 15:08

EtaPhi,

Do you mean that a NOP instruction takes 1/16MHz = 62.5 ns

if fMASTER = 16MHz ?

fggnrc2
Associate II
Posted on May 17, 2011 at 15:08

Boltnut,

the STM8 core has got a three stage pipeline.

If an instruction stream contains no jump instructions, each NOP instruction takes one clock cycle, i.e. 1/16MHz = 62.5 ns.

Your conclusion is true, but only if the instruction pipeline is full.

Regards

jeffrey23
Associate II
Posted on May 17, 2011 at 15:08

Hi EtaPhi,

I need a shorter delay time for I2C timing and

implement the following function:

void I2C_Delay (UB8 bTime)

{

    bTime /= 3;             // 3.5 cycles each loop !

//69               ; 97     while (bTime--)

//71  0005 7b01             ld  a,(OFST+1,sp)       ; 1.0 cycle

//72  0007 0a01             dec (OFST+1,sp)         ; 1.0 cycle

//73  0009 4d               tnz a                   ; 1.0 cycle

//74  000a 26f9             jrne    L13             ; 0.5 cycle

    while (bTime--)

        ;

} /* I2C_Delay */

Is it correct ?

How to estimate the delay time correctly ?

Regards,

Boltnut
fggnrc2
Associate II
Posted on May 17, 2011 at 15:08

Hello Boltnut.

If you mean ''smaller delay granularity'' in your request, you can use:

while ( --bTime )

   ;

which your compiler should translate in:

      ld  a,(OFST+1,sp)

L13:

      dec a

      jrne L13

This code should take 3 x bTime + 1 clock cycles to execute (if interrupts aren't allowed)

There is a simple way to measure how long a delay routine takes: add an instruction which toggles an output pin before and after the delay routine.

Then use an oscilloscope to see and measure the waveform.

Regards

EtaPhi

jeffrey23
Associate II
Posted on May 17, 2011 at 15:08

Hi EtaPhi,

Thanks for your advice.

I tried to revise it as below:

void I2C_Delay (UB8 bTime)

{

//  59  0000 88             push a

//  75            ; 106     while (--bTime)

//  77  000d 0a01           dec (OFST+1,sp)         ; 1.0 cycle

//  78  000f 26fc           jrne    L13                      ; 0.5 cycle

    while (--bTime)

        ;

//  71  0005 84             pop a

//  72  0006 81             ret

} /* I2C_Delay */

It is good enogh to my application.