Question for Arduino Uno users.

Thread Starter

MaxHeadRoom

Joined Jul 18, 2013
30,589
Transferring a Arduino assy file to picmicro , a time delay has the following.
What will be the delay for this routine. ?

delayMicrosec:
LDI R21, 55
15: DEC R21
BRNE 15
RET
 

be80be

Joined Jul 5, 2008
2,394
This is what they say you have to figure out
Generally you figure out how many clock cycles you need to burn, then write a loop. Consult your datasheet to determine how many cycles your loop takes and calculate how many iterations you need.

ldi r16, x ; 1 cycle
loop: nop ; 1 cycle
dec r16 ; 1 cycle
brne loop1 ; 2 cycles when jumping, 1 otherwise
 

atferrari

Joined Jan 6, 2004
5,005
This is what they say you have to figure out
Generally you figure out how many clock cycles you need to burn, then write a loop. Consult your datasheet to determine how many cycles your loop takes and calculate how many iterations you need.

ldi r16, x ; 1 cycle
loop: nop ; 1 cycle
dec r16 ; 1 cycle
brne loop1 ; 2 cycles when jumping, 1 otherwise
Could you explain in pseudocode?
 

be80be

Joined Jul 5, 2008
2,394
Here maybe a better explanation

Code:
; Delay subroutine for Arduino
; Assumes a 16MHz clock

delay_1ms:
    ldi r18, 250     ; Load 250 into register r18
    ldi r19, 4       ; Load 4 into register r19
outer_loop:
    ldi r20, 4       ; Load 4 into register r20
inner_loop:
    dec r20          ; Decrement r20
    brne inner_loop  ; Branch if not equal (to zero)
    dec r19          ; Decrement r19
    brne outer_loop  ; Branch if not equal (to zero)
    dec r18          ; Decrement r18
    brne outer_loop  ; Branch if not equal (to zero)
    ret              ; Return from subroutine
 

MrChips

Joined Oct 2, 2009
34,689
Arduino nano circuit uses a 16 MHz quartz crystal.
However, you still need to know what frequency the ATmega328 code has selected. To find out, run a GPIO toggle program and measure the frequency with an oscilloscope.

In your case, run the delay function and measure the delay time. Simply create the same delay on your target system.
 
Top