How to change ICR1 from signed to unsigned (using Atmel Studio 7)

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

Hi gentlemen.

 

Mi name is ALfredo, from Argentina.

I am working on a project, where I am using Timer1 (Atmega328p).

 

I have a problem and so far I couldn´t fixed, I hope you can help me.

 

i need to load ICR1 Register with 40000 (ICR1=40000), but I saw, after this code is executed ICR1 has a negative value, it is because the register of 16 bits is defined as SIGNED, but I need to used as UNSIGNED.

 

How can change it?

 

ICR1 is defined in Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include\avr\iom328p.h

 

#define ICR1 _SFR_MEM16(0x86)

 

Resume:

Micro=Atmega328p
Atmel Studio 7

ICR1 register is set as Signed but i need ot used as unsigned (0 to 65535) and I do not know how to do it.

 

 

any comment is welcome.

 

Br

Alfredo

 

This topic has a solution.
Last Edited: Thu. Jan 16, 2020 - 05:46 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Where the value is displayed is the problem, not with icr1 itself.

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


Hi Kartman.

the assignation is done it, but i am using ATmel Studio (Simulation)  i can see the issue...

 

in the picture you see....

 

ICCR1=40000;

but the ICR1 Register has a negative value.........

 

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

To add to Kartman

 

The register, itself, is UNSIGNED. The method you use to show its value changes to signed. If you use IOView, that should show it as unsigned. If you use a Watch Window, you can change how each value is displayed. There, an unsigned value can be displayed as signed, or a signed value can be displayed as unsigned. You can change it to unsigned right in the Watch Window (but, at this instant, I do not remember how).

 

Also, it may not be obvious to you but, for example, the value 0xFFFF is still 0xFFFF whether you show it as signed or unsigned. If signed, 0xFFFF = -1 but if unsigned, 0xFFFF = 65535. Same register value, two ways of looking at it.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Thu. Jan 16, 2020 - 05:31 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi  ka7ehk .

OK, so the Register has the right value, my mistake was how I saw it.

 

Ok, thanks a lot for your help.

 

br

Alfredo

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

on watch windows, clic on var/register , if i select in Hex format i can see 0x9c40(40000).

 

Thanks for your help.

 

Alfredo