about danni's switches debouncing

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

yes I know the code and used it a couple of years ago, it is dated 2005 but switches debouncing questions occur every week in the forum, it should be a sticky post :)

https://www.avrfreaks.net/index.p...

Recently I went through the excellent walkthrough

https://www.avrfreaks.net/index.p...

In general I use volatile for my variable that I read and write both in the ISR and elsewhere.

Why key_press is not volatile? It's more about optimization than cache access or something like this?

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

Magister wrote:
In general I use volatile for my variable that I read and write both in the ISR and elsewhere.

That's correct.

I started programming in 1995 with Keil C51 on the 8051 and then no volatile was needed.
Also earlier WINAVR versions are not so pedantic.

Thus some of my early AVR code was not fully correct under all circumstances.

Peter

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

I compared assembly file generated with and without volatile. With it, key_press is read a second time in the get_key_press() function, to avoid caching in a register, but as the reads are in a protected atomic block, it's ok to not use volatile here.

But still, people, use Cliff's FAQ#1 in case you are not sure or do not know how to check the generated assembly :)

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

Quote:

Cliff's FAQ#1

Just to note that's just a very short form of this (maybe that's obvious?).