ussing different registers

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

Hello all,

I made a delay in 2 ways and one is working fine but the other one doesn't work. I use the atmega328.
My delay must be 1.6 sec. but with the non working it is much less than that and from my opinion it must be the same.

The difference between the two is that in the working one I use a register Count in the upper register (r23). The non working has the register Count in the lower register (r13).

I can not find out what I'm doing wrong here.
Can anybody give me a clue or a push in the right direction so I can solve this problem.

I include a piece of code that only shows the counter in the interrupt.

Already thanks for the help,
Patrick

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
LDS R13, 200

has a COMPLETELY different effect to:

LDI R23, 200

Yes, it's true that you can only use LDI on registers R16..R31 which makes loading R13 more complex. Replace your LDS with:

LDI R16, 200
MOV R13, R16

and it should work as before. (but you now face the issue that this has used another register so if this is in a called function you may want to PUSH/POP the "temp" register such as R16 you use for LDIs.

You probably want to read the opcode manual about LDS to realise what it was actually doing (hint: how the code behaves would be dependent on what's in location 200).

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

Thanks Clawson,

Now everything makes sense. :D

If I look at the location 200, and do the calculation with the number on this location it is the same as with the measured time.

So thank you very much for your help,
Patrick

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

Patrick, perhaps print a version of this and keep it at hand:

http://www.atmel.com/images/doc0856.pdf