whenever call delay function its not working properly

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

 

In the simulation everything goes perfect, but in the real test, when it enters the label label it does not leave that loop, it does not leave the call subroutine

 

<label: call delay_1s

          in r10,pind
         cp r10,r18
         breq yes1
         jmp return_1
         yes1:ldi r26,2
         jmp done        

....

....

 

delay_1s:    
            LDI     r23,   8       ; One clock cycle;
        Delay11:
            LDI     r24,   125     ; One clock cycle
        Delay12:
            LDI     r25,   250     ; One clock cycle
        Delay13:
            DEC     r25            ; One clock cycle
            NOP                     ; One clock cycle
            BRNE    Delay13          ; Two clock cycles when jumping to Delay3, 1 clock when continuing to DEC

            DEC     r24            ; One clock cycle
            BRNE    Delay12          ; Two clock cycles when jumping to Delay2, 1 clock when continuing to DEC

            DEC     r23            ; One clock Cycle
            BRNE    Delay11          ; Two clock cycles when jumping to Delay1, 1 clock when continuing to RET            

RET

>

 

now,If I do this now, everything is perfect in the simulation and in the real test.

 

<label:    

 

            LDI     r23,   8       ; One clock cycle;
        Delay11:
            LDI     r24,   125     ; One clock cycle
        Delay12:
            LDI     r25,   250     ; One clock cycle
        Delay13:
            DEC     r25            ; One clock cycle
            NOP                     ; One clock cycle
            BRNE    Delay13          ; Two clock cycles when jumping to Delay3, 1 clock when continuing to DEC

            DEC     r24            ; One clock cycle
            BRNE    Delay12          ; Two clock cycles when jumping to Delay2, 1 clock when continuing to DEC

            DEC     r23            ; One clock Cycle
            BRNE    Delay11          ; Two clock cycles when jumping to Delay1, 1 clock when continuing to RET            

 

         in r10,pind
         cp r10,r18
         breq yes1
         jmp return_1
         yes1:ldi r26,2
         jmp done      

>

 

when instead of performing the call subroutine, and I make the delay avoiding subroutine everything goes well in the simulation and in the real test ...

What could be happening ?, I tried with call and rcall the result is the same.

 

This topic has a solution.
Last Edited: Thu. Sep 5, 2019 - 06:34 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

beginner error, every time you are going to perform subroutine you should always save the last address of sram memory in spl and sph records

 

ldi r16,high(ramend)
out sph,r16
ldi r16,low(ramend)
out spl,r16

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

That kind of depends on which AVR it is. All the later ones auto-load RAMEND into SP at power on anyway.

 

By implication you must be using a very old AVR.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am using an atmega32