2010-04-28 04:51 PM
How long does a nop instruction take at max. HSI (16MHz) ?
2011-05-17 06:08 AM
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. EtaPhi2011-05-17 06:08 AM
EtaPhi,
Do you mean that a NOP instruction takes 1/16MHz = 62.5 ns if fMASTER = 16MHz ?2011-05-17 06:08 AM
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. Regards2011-05-17 06:08 AM
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 cyclewhile (bTime--)
; } /* I2C_Delay */ Is it correct ? How to estimate the delay time correctly ?Regards,
Boltnut2011-05-17 06:08 AM
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 EtaPhi2011-05-17 06:08 AM
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 cyclewhile (--bTime)
; // 71 0005 84 pop a // 72 0006 81 ret } /* I2C_Delay */ It is good enogh to my application.