I am trying to create a precise (10% tolerance) delay subrouting using assembler in AvrStudio 7.0.1188.
The purpose for this routine is to learn about the instruction timing and in the end, integrate it into a custom sw-uart library.
Using Attiny85, I have written the code in . For the instruction timings, I have checked the #Clocks column in Paragraph Instruction Set Summary (Attiny85 datasheet Rev. 2586Q–AVR–08/2013, page 202 ) and the AVR Instruction set Reference .
As far as I understand, the repeat loop in my code should take 100 repetitions *3cc (dec (1) + brne(2, condition false)) = 300 cc. Since my tiny85 is running at 1Mhz (internal osc, CKDIV8 not set), I am expecting around 300us delay for a pin toggle. Instead, I am seeing a 144us delay using an oscilloscope.
What could be the root cause here? I assumed a pipeline speedup, but the tiny85 clearly states close to 1MIPS at 1Mhz (about 1 instruction per cc) and not more.
Many thanks in advance.
.include "tn85def.inc" .cseg .org $000 rjmp initAndStart ; Replace with your application code initAndStart: sbi DDRB, 1 // PORTB.1 output start: sbi PORTB, 1 // PORTB.1 high rcall delay cbi PORTB, 1 // PORTB.1 low rcall delay rjmp start delay: ldi r16, 100 repeat: dec r16 brne repeat ret