Need clear examples AVR manuals are confusing

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

Hi,

I think AVR manuals are confusing.
I speak english as my first and only language and have been an embedded engineer for 20 years.

Does anyone actually understand this ? (from the AT90USB manual) :

The TOP value, or maximum Timer/Counter value, can in some modes of operation be defined by either the OCRnA Register, the ICRn Register, or by a set of fixed values. When using OCRnA as TOP value in a PWM mode, the OCRnA Register can not be used for generating a PWM output. However, the TOP value will in this case be double buffered allowing the TOP value to be changed in run time. If a fixed TOP value is required, the ICRn Register can be used as an alternative, freeing the OCRvA to be used as a PWM output.

(end)

Now what the hell does all that mean ?

* (Note Added, lots of replies thanks. I have found some good tutorials with example code, and achieved what I needed.

Good basics to PWM but does not show how to change the frequency:

http://maxembedded.com/2012/01/0...

The following has code at the end that worked.

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

Conclusions:
on my AT90

I can achieve two 8 bit PWMs and one 16 bit PWM.

Only the 16bit timer can be used to create a pwm with fully adjustable frequency (and duty cycle)
The 16 bit timer is timer1.

The 8 bit timers are timer0 and timer 2
The frequency of these can be adjusted using divider settings only eg divide by 64, divide by 128

Last Edited: Thu. Feb 28, 2013 - 02:33 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there not a table of modes that clearly explains this?

http://www.atmel.com/Images/doc7...
Table 15.4

Exactly what do you want the timer to do?

Note: We are not Atmel - just average Joes like yourself. Complain to Atmel - not to us.

BTW The AVR docs are pretty good - have a go at the TI doc for their Cortex M4 parts or ST for their STM32F4 parts. I think your brain might explode!

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

I sympathize with you but, the Timers/PWM peripherals are probably the most complex of all the peripherals. I don't believe a data sheet is the best place, to give all the examples of every feature of every peripheral. The size of the data sheets would treble in size.
That is where the Application sheets, AVRfreaks & the AVR Tutorials come in too!

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

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

And they probably evolved. I betcha the very first avr timer functions were a lot like the hc11. Generate an interrupt on overflow or on compare. You can do pwm with that if you want to write the interrupt handlers. Then came the pwm modes... 8,9,10 bit. Then someone asked for the top value to be specified in the ocr reg. But that meant you couldnt use the ocr mode dammit. So they invented the mode where the top value can be in the icr reg and you can still use the ocr for compare. At least the darn timer is in the chip and you dont need ttl chips to generate a chip select and hook up 8 data bits to talk to an external timer chip on the bus. Ah. The Good Old Days.

Imagecraft compiler user

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

Yea. I agree, that paragraph Is confusing. I go down to the "registers" section. Pick out which mode I want, then just follow down through the list of registers. A sheet of paper helps. I write a line for each bit in the register giving its name, then, following through the charts, decide which bits I want 1 and which 0. The most confusing are the "wgm" as they are split between 2 registers.

They explain it all a couple different ways, with paragraphs and charts, 'cause some of us understand one form better than the others.

There's a pretty good explanation in the tutorial section.

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

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

The best strategy is pick ONE mode and study/use it, hopefully w/ an o.scope until it sinks in ( As Lee wrote, the 'sheet would be huge if they expanded the details of such a system ). Include an open datasheet and a 'freaky Timer/PWM tutorial and you're set. Like w/all things complex, you have to break it up into manageable bites.

The sentence from the 'sheet you posted isn't so bad ,and clear enough ( took a couple of re-reads, my 1st time through ). It takes TWO values to do PWM ( a value for PERIOD(freq.) and another for D.C. ),TOP => PERIOD and so sets frequency. If you use a OCRxx register for TOP, THAT register can't be used for anything else ( you'd wipe out the PERIOD value ). Another OCRxx reg. sets D.C. Free up the TOP reg. by using a fixed value OR ICR, and then you'd have 2 OCxx pins for PWM ( if uC has the 2 OCxx pins ).

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

Quote:
Yea. I agree, that paragraph Is confusing.
Let's be realistic here. The paragraph quoted is from the Overview section. You can hardly expect it to have everything that is necessary to explain all 15 mode the timer has. That is why there is another 20 or so pages (and that does not include the register descriptions).

Regards,
Steve A.

The Board helps those that help themselves.

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

Quote:

Does anyone actually understand this ? (from the AT90USB manual) :

The TOP value, or maximum Timer/Counter value, can in some modes [...]


Yes. I am sure many people understand this. The first time I tackled the chapter for a Timer/Counter I of-course hasd to read it several times.

The reason such texts are hard to read are
- They need to be formal, there should be as little room for assumptions etc as possible.
- The Timers/Counters of AVRs are complex, so the text will be complex.

Having said that I do agree that good examples helps to make initial studies of e.g. AVR Timers/Counters easier.

Having said that, I am sure there will always be a demand for the missing example that does exactly what some AVR user needs. I.e. to demonstrate everything, the collecrion of examples will become ridiculously large.

I am also sure that people having dealt with e.g. Timers/Counters from other microcontroller families have an easier time understanding the AVR documentations than people who are entirely new to microcontrollers.

Overall, the AVR data sheets are very clear and to the point as compared with many other microcontroller data sheets. (This is in part due to the relatively "clean" design of AVRs as such.)

Yes, you ned to browse the entier chapter on the specific timer once or twice, to roughly understand the over-all worings of it. Then you go into the details of one of the modes and get that to work.

Quote:
We need clear examples and explanations of a single mode of operation.

Do you mean of every mode? That would render a chapter perhaps 50 pages long..

Or is it one specific mode you want details on? Which one, then? Why exactly that one?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Tue. Feb 26, 2013 - 09:25 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Part 2, the breakdown (and my interpretations/rewrites assumes Timer/Counter1, to instantiate all those n's in the generic text):

Quote:
The TOP value, or maximum Timer/Counter value, can in some modes of operation be defined by either the OCRnA Register, the ICRn Register, or by a set of fixed values.

In some modes the counter counts to a fixed value. In some modes the timer counts to the value set in the ICR1 register. In some modes the counter counts to the value set in OCR1A. Regardless of the mode, we generically use the word "TOP" to refer to this maximum value the counter counts to.
Quote:
When using OCRnA as TOP value in a PWM mode, the OCRnA Register can not be used for generating a PWM output.

For the modes where OCR1A is used for the TOP value, the OCR1A register can (of-course) not also be used to specify a duty cycle for PWM. Thus, for those modes only one PWM channel (with duty cycle in OCR1B) is available. This is a draw-back, but ...
Quote:
However, the TOP value will in this case be double buffered allowing the TOP value to be changed in run time.

...there is also the advantage that in this mode you can modify the TOP value without glitches while the timer is running.(The double-buffering mechanism is described in detail elsewhere.)
Quote:
If a fixed TOP value is required, the ICRn Register can be used as an alternative, freeing the OCRvA to be used as a PWM output.

If you do not need to modify the TOP value while the timer is running you can select a mode that uses OCR1 for holding the top value. If you do not need to alter the TOP value at all at run-time there are modes with a fixed TOP value (i.e. "hard-wired"). For both these cases you have both PWM channels available (with duty cycles in OCR1A and OCR1B).

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

I don't see why they couldn't do a better job of explaining how the timer works in the datasheet.

On an Atmega328P there are 16 different timer modes. You would think that it would be possible to describe the general stuff in a few pages, and what remains should be possible to explain in one page per mode.

That would be 16 pages, and in a datasheet that is already 555 pages you would think that 16 pages does not matter all that much when we're talking about an important feature such as the 16-bit timer.

There is more than one timer and they do have different features, but it still seems reasonable to expect an explanation of how the heck they work.

Sid

Life... is a state of mind

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

Quote:

to be changed in run time

Am I the only one who thinks the quoted paragraph makes complete sense then? The one part I would question is this "changed in run time" phrase which just seem like an odd English construct and doesn't really convey the point the author was trying to make anyway (ie that you can change the match value at any time in the cycle as it only comes into affect the next time the counter rolls over TOP).

Once you've read the entire timer chapter and understand all parts of it then, otherwise, that paragraph seems to summarise a lot of the operation pretty well.

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

Quote:

Am I the only one who thinks the quoted paragraph makes complete sense then?

No. I'm in. I'd rather have an undersytanding of how the T/C works as a whole, and then apply that to the specific modes, than have a cook-book for each mode. The latter would definitively lead to redundancy, and for those of you who know me you know that I am a swordn enemy of that.

Quote:
The one part I would question is this "changed in run time" phrase

Yes. "Run time" can be interpreted in several ways. In my interpretation above I reworded this to "while the timer is running" which is much more specific (even totally un-ambigious, I hope).

Re the discussion as a whole, for me the bottom line is: If something is inherently complex, the explanation of it also will have complexity.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

When I have uncertainty, I grab the bull by the horns. And test with scope or Logic A, code, and often another avr to generate timings. I learn by getting my hands involved. The manuals give a good start.

It all starts with a mental vision.

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

Tecpenguin,

Let's see, the three SuperFreaks, (Johan, Cliff, and Steve), that posted can all read and understand that paragraph, and Kartman, who is almost a SuperFreak.

I'm on your side of this discussion, however. Although I can dissect the paragraph and sort it out, it isn't easy to do so. And in spite of the SF's comments, I agree it could be more clearly written.

I also think the excuses for not providing clearly written, concise examples of the different modes is crazy. As noted, the manual is 100's of pages long, and with an indexed PDF or an on-line hyperlinked version the length doesn't matter. Clarity for the end user is what matters.

Additionally, I don't think one should have to track down a bunch of different App Notes just to set up a timer, that's what the manual is for.

Don't get me started on the Xmegas having two manuals for everything...

JC

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

Quote:

Additionally, I don't think one should have to track down a bunch of different App Notes just to set up a timer, that's what the manual is for.

Please no! I want the bare, concise details in the datasheet. If I want example code I will look at libraries (such as ASF) and app notes separately. The datasheet is a professional tool and not a beginners guide. I for one don't want it loaded up with a load of pointless noise just to help "beginners". There's plenty of other info resources for them. Experience shows that when Atmel do include example code in datasheets they invariably screw it up or suffer horrendous copy/paste errors when that same code from a 10 year old model just gets pasted into a new device datasheet where the mechanism/names are quite different.

Until ASF came along I thought what they did in the AVR13NN numbered app notes for Xmega was a particularly good approach with an introduction to each peripheral in each one. What they screwed up on badly (though admittedly it was to reduce the copy/paste errors) was not doing a single datasheet per device for the Xmega but each devices has "local" details then there's a generic "family" one covering a number of models. 99 times out of 100 the detail you are looking for is in the "other one".

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

And don't worry. Once you begin to understand them, the timers become very handy and can do amazing things for you. But, yes, there is a lot to learn there.

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

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

Quote:
Am I the only one who thinks the quoted paragraph makes complete sense then?
I believe that it is perfectly clear, but that is with the benefit of knowing how the timer works to begin with. But at the point in the document where this paragraph is, I think it is perfectly acceptable, even for first time readers. This is the overview. If you need more explanation, read the detail sections that follow. Still need more, look outside of the document for examples.

Regards,
Steve A.

The Board helps those that help themselves.

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

Quote:

Don't get me started on the Xmegas having two manuals for everything...

I'm not an XMega man, but I have delved into several ARM Cortex-Mx's. For those, several different data sheets seems to be the norm. Stuff shared by e.g. a whole family in one document, specifics for a certain model in another. Makes sense to me..

I can fully understand that reading a Timer/Counter chapter in an AVR data hseet can be a daunting experience the first time through. But when you've "cracked" it you'd probably not want say 50 pages for each T/C. I'm sure I don't.

Now, let's say you have a T/C with 6 PWM modes. Would you need 6 examples, or should each mode have an example for inverted PWM also? No? Should only one example have the info on inverted PWM? Which one, and what critique would come out of that? Oh, you mean that inverted PWM could be broken out in a separate section that holds for all PWM modes? OK, but then why not break out everything that is shared? If that is OK you're pretty close to what we have now..

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

I am somewhere in the middle on this.

I do find the mode descriptions (that is, how the timer is expected to behave in different modes) a bit muddy. On the other hand, there is worse out there, way worse.

For example, I happened to look at a Mega8515 spec sheet recently. Timer0 (8-bit) has 4 modes. Mega8's Timer0 has one mode ("normal" with no compare). So, things have changed pretty dramatically.

And, for someone encountering this for the first time, it can be daunting. Sleep modes have a similar problem.

The challenge is that it takes EFFORT to understand. Many of us don't like to make that effort. I happen to enjoy it, but many do not. Particularly among the latter are the folks in the camp that says "I don't want to understand it, I just want to use it." In part, that is why Arduino is so attractive.

Rather than throw up ones hands in a gesture "of I don't get it", just ask for an explanation some place like this forum. You will get lots of (competing) help!

Jim

 

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

 

 

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

Datasheets are written by engineers for engineers. They were never intended for any other audience.

When I started EE they called all the new guys into a a room and said, 'look at the guys to your left and right. They won't be here when you graduate.' And 2/3 did bail out before it was over. This stuff, like math, is hard and there is no royal road to competency.

The vast majority of these ICs are used by folks who can, in fact, read datasheets. It isn't easy, but either the information is there or you call a rep and get help. It makes no sense for a company like Atmel to invest in providing documentation for folks who don't have the background to be their major customers.

That said, there is a wealth of excellent documentation available for novices and intermediate folks. The Arduino provides just about everything any novice would want to do in an easily digestible form. AVRFreaks and similar fora have folks who are eager to help others learn to use AVRs. People just need to relax and start where they are and enjoy all the help and tools available that are aimed at their level of expertise.

Smiley

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

Obviously I'm fighting a loosing battle here...

What with the concept that if I want to hook up an SD card to a micro, I'll look for an Application Note describing the process, highlighting best practices, and pointing out common pitfalls and traps.

And if I want to connect an IA amp to a single ended, ground referenced uC's ADC I'll pull out an App Note...

And if I want to hook up a string of one-wire devices to a micro I'll pull an App Note...

But if I want to know how one of the module's inside a specific chip works, I'll pull out the manual, and read the relevant section. And, if I'm lucky, there will be a couple of working examples, either embedded in the section, or hyper-linked to the section. (Does anyone actually print out an entire manual these days? Perhaps sections, or tables, but the entire manual?)

Hyper-links don't work on paper print outs...

Once its a digital manual, instead of a bound paper pages book, I want it all in front of me. I don't want to go searching for the relavent explaination of how it is "really suppose to work".

Oh well, its been a while on the Forum since there was a religious war. Sometimes it is hard to guess which topics will strike a nerve!

JC

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

DocJC wrote:
Oh well, its been a while on the Forum since there was a religious war. Sometimes it is hard to guess which topics will strike a nerve!
I'm not seeing a religious war. You of all folks should understand this. What do you say when somebody says, 'But Doc, I looked this up on the Internet and ...'? Surely you don't think the obtuse documentation for drugs should be written for the general public? I'd say this holds for any profession with a steep learning curve. There is documentation for the folks trained to understand it and then there is a separate set of materials for the rest of us. Do you hand folks medical journal articles on a given condition or summary pamphlets written especially for them? I think that is all we are saying and I don't see how that is religious.

Smiley

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

Hi Smiley,

My calling it a religious war was in reference to the general concept of minimalistic data sheets and lots of accessory documents, or the stuff it all in one big binder approach.

As you pointed out, there is a different set of material needed for different indications, be it the Arduino manual vs the advanced micro's module's minutia; or the medical analogy you mentioned above.

I'm still laughing to myself, however, as yesterday, studying an Atmel Xmega manual, I had half a dozen files open to track down the info I needed, which was missing from the manual. A couple of hours invested instead of a quick skim of the Table of Contents, the Index, or the SEARCH option. And I still haven't had a chance to go search on what the 'enable circular buffer' flag was all about, noticed in passing while researching something else. A classic case of "you don't know what you don't know". In this case if I don't know about the "enable circular buffer" flag, and the ramifications of setting the bit, then I don't know if it plays a factor in the dead chip sitting in front of me, not doing what I would like it to do, or if it plays a role in the many other modes of operation, but not the mode I'm currently interested in. Which actually brings me full circle, back to the OP's original concern and the response of the expert SuperFreaks. Once you are an expert it all makes sense, but you have to know it all and be an expert to make sense out of it. Catch 22.

Oh well, enough rambling.

JC

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

All this discussion and no response from the OP!

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

Kartman wrote:
All this discussion and no response from the OP!

Probably dumped Atmel and went to the "dark side".

I was able to get the the timer/counters to do what I wanted. The documentation is reasonably accurate, but it's not at all user friendly.

There really aren't that many fundamentally different things you can do with the timer/counters, so surely it would not be too difficult to set down a few examples with varying levels of complexity? A single table showing all the relevant registers with which bits do what would a great help too.

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

Quote:
Probably dumped Atmel and went to the "dark side".

Are their data sheets better?

Quote:
The documentation is reasonably accurate, but it's not at all user friendly.

I find it engineer friendly.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

JohanEkdahl wrote:

I find it engineer friendly.

This engineer has been looking at stuff like this for forty years, and he did not find it at all friendly. It may be obvious to you, but that's probably because you've been using it for quite a while.

It really doesn't bother me much either way, but if Atmel wants to sell more silicon, they probably want to take the reactions of potential new customers very seriously.

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

Hey !

Great posts.
I didn't dump Atmel and go to the 'dark side'

I am liking Atmel but have no allegiance.
I enjoy the post on the 'EEV blog' regarding pic vs atmel.

What I like about atmel so far is the EEPROM functionality and the nice IDE ATstudio6.

I find there is lots of support and examples which has helped alot.

Could use with a library for PWM though something like:

PWM1_enable()
PWM1_setup(period,duty)
PWM1_start()
PWM1_stop()

I can dive into the details of registers etc only if necessary.

And I have updated my original post with a bit more positive information with some links.