timer.h seems to have vanished in the new release!!!

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

Hello all,

Felt very happy :D to note the release of newer version of WinAvr. Downloaded and thought I will just check out , loaded an existing project and tried to compile. CBU and SBI have vanished, Thats OK cause we have all been warned about the impending removal, but TIMER.H file also seems to have vanished. Is this intentional? How shoul the timers be used then?

Thanks

Parthasaradhi Nayani

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

See the NEWS file, yes, it had been deprecated a while before (though
not as long as the other macros), and removed upon moving to version
1.2.x, too.

This file wasn't useful for many reasons:

. The prescaler definitions in the file were only valid for some
AVRs, not for all.

. The file only handled timer 0, so for the majority of timers, you
had to do the legwork yourself anyway.

. The inline functions at the bottom of the file were completely bogus
and never worked as advertised. As nobody even bothered to file a
bug report for this, we took this as an indication that noone is
seriously using that file.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

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

Dear Jorg,
Thanks for a very prompt reply. But I have been using the latest WinAvr and in many of my applications I used timers and in all cases included the timer.h and never faced any errors. Only in this new version did the compiler report the error. Perhaps the timer defs have been moved to io.h. One more thing I noticed is the location of io.h file, as feared the CBI and SBI have vanished. Is the alternative to these two macros _BV ?

Regards

Parthasaradhi Nayani

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

Use _BV instead of BV.

Use foo |= _BV(x) instead of sbi(foo, x), and foo &= ~_BV(x) instead
of cbi(foo, x) (standard C). Sure, you can make that macros yourself
if you prefer.

If you've been using timer.h in the past, you've probably been using
the various CK* constants. Just make your own header file with them,
but do make pretty sure they match your controller. Notably on the
ATmega64/128 the old definitions didn't. Also verify them if you're
using anything else but timer 0, see above, the old header file has
never been designed for anything else but timer 0.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

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

cbi()?

just kidding :)

MY MICROCONTROLLER CAN BEAT THE HELL OUT OF YOUR MICROCONTROLLER /ATMEL

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

Sorry for my simple question! What do you mean with _BV? I wrote the definitions (in io.h) like this:

#define cbi(foo,x) { foo &= ~_BV(x) }

is that right?
Then I got the following error, can someone explain?
...\Temp/ccYhaaaa.s: Assembler messages:
...\Temp/ccYhaaaa.s:137: Error: missing ')'
...\Temp/ccYhaaaa.s:137: Error: constant value required
...\Temp/ccYhaaaa.s:137: Error: constant value required
...\Temp/ccYhaaaa.s:137: Error: garbage at end of line
(i´m using WinAVR release 050214)

Thanks!

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

You may try a forum search next time...

You will find something like this thread then:
https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=8764&highlight=programmers+101

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define cbi(foo,x) { foo &= ~_BV(x) } 

You're missing a semicolon, so this should have generated a compile (not
assembly) error. When I fixed this one thing, it compiled fine. Could you
please paste the Actual Code you're using, rather than trying to re-type it?

That said, I don't see any simple permutations of this definition
which would have generated assembly errors. Could you also paste the
line where you're using this macro (or the whole source, if it's practical)?

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

For one thing, those curly braces are unnecessary and could be causing the problem....

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

Wouldn't

#define cbi(foo,x) { foo &= ~_BV(x) }

cbi(PORTA,1); expand to { PORTA &= ~_BV(1) };

In that case i suppose our resident EWW preprocessor is right again :-)

/Bingo

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

True (directed at the last few posts).

And you could get into trouble even with a semicolon inside the curly braces. Concider this:

#define sbi(foo,x) { foo |=  _BV(x); }
#define cbi(foo,x) { foo &= ~_BV(x); }

if(bitval)
  sbi(foo,x);
else               // You'll get an error because this "else" is misplaced.
  cbi(foo,x);

It is a good idea to encapsulate as much as possible if you're writing macros, but do it like this instead:

#define cbi(foo,x)  ((foo) &= ~_BV(x))

Note: no semicolon, and normal parentheses.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define cbi(foo,x) { foo &= ~_BV(x); } 

The form I've been using for years (haven't found any gotcha-s yet) is:

#define cbi(foo,x) do { (foo) &= ~_BV(x); } while(0) 

I didn't dwell on that since it was clear to me that:

1) The OP didn't provide the code that was actually being used, since
what was given wouldn't have made it past the syntax analyzer.
2) Generating assembly errors from the compiler (absent the use of
inline assembly) isn't easy, so there must be something important
being omitted.