Interesting tip for variables storage

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

I saw this "tip" in Atmel's C programming app note (from a long time ago)...is this still viable, widely used or never used???...never heard or thought of  using "spare" control registers until now.   Seems a bit dangerous & sneaky (and a potential for mysterious brain busting bugs).

 

Unused locations in the I/O Memory can be utilized for storing global variables when certain peripherals are not used. As example, If the UART is not used the UART Baud Rate Register (UBRR) is available, and if the EEPROM is not used both the EEPROM Data Register (EEDR) and the EEPROM Address Register (EEAR) will be available to store global variables.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

Sounds very much like "fiddling while Rome burns".

 

Or, perhaps, "rearranging the deckchairs on the Titanic".

 

I'd have thought that if you need to scratch about for the odd byte here & there like that, then it's really time to be moving up to a bigger-RAM part - or having a major review of your RAM usage.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

An alternative view is job security supporting the product - most normal people trying to introduce a new feature to the product would get pummeled by mysterious problems.  Sneaky indeed!

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

Why would you use that at all?

 

If you are in a range where 1 ticks of IN / OUT vs. LDS / STS alrfeady matters, then you want to use (inline) assembler for that part or for the whole application.

 

Moreover, such variables don't comply to the C standard because they are in static storage but not initialized by startup-code (except you are using own akward startup-code).

avrfreaks does not support Opera. Profile inactive.

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

avrcandies wrote:

...from a long time ago...

 

Perhaps it dates from the time when assembler was the only language to write AVR code in and RAM was in short supply?

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

From about 2005 onwards AVRs have GPIOR0 in the SBI/CBI range so you can arrange to put your 8 most used binary flags into it. On "old iron" like mega16/mega32 there was no such luxury so I have habitually used TWAR for this purpose. It's an 8 bit read/write register, in range of SBI/CBI and, unless you use I2C, untouched.

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

I will say it's from the time where some AVR didn't have any RAM! 

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

With the "new and improved" I/O memory-maps [roughly, those models having 256 bytes of I/O memory space] the valuable low memory space is so sparse that the technique isn't too attractive anymore.  GPIOR0 is the exception.  If you have to use the SRAM-mapped address to use a "spare" I/O register, only the most pathological apps needing "one more byte" might be candidates.

 

It has been discussed at some length over the years.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

The tip come from page 14 of this Atmel document (AVR035):

 

 

http://ww1.microchip.com/downloads/en/AppNotes/doc1497.pdf

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

avrcandies wrote:
The tip come from page 14 of this Atmel document (AVR035):
theusch wrote:
With the "new and improved" I/O memory-maps [roughly, those models having 256 bytes of I/O memory space] the valuable low memory space is so sparse that the technique isn't too attractive anymore. GPIOR0 is the exception. If you have to use the SRAM-mapped address to use a "spare" I/O register, only the most pathological apps needing "one more byte" might be candidates.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

avrcandies wrote:

The tip come from page 14 of this Atmel document (AVR035):

 

So from January 2004.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

remember it's from 2004, there the chips had a lot of IO's in the lower end.

 

And I see that on page 15 there is an error ! in the table it say it take 4 bytes to set/clear a bit in a register! (for the top 16 it's only 2).

So like any Atmel documents there is a lot of errors!

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

So from January 2004

 

I wonder what is the time constant, (or even half-life) of an Atmel tip ?surprise

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!