CLK_PSADIVn_bm wrong?

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

HI.

Forgive my inexperience, but trying to use:

CLK_PSADIV2_bm. Ddn't work.

After reading the datasheet, I noticed that all the division _bm's are ODD numbers so I used CLK_PSCTRL = 0b00001100 and it worked.

 

Looking at the header file iox64a4u.h I see:

#define CLK_PSADIV2_bm  (1<<4)  /* Prescaler A Division Factor bit 2 mask. */

 

Surely it should be: #define CLK_PSADIV2_bm  (3<<2)

 

Tore my hair out for a few hours...

 

Toolchain is Atmel studio 6.2, chip is XMEGA64A4U.

Doing a 'grep' I see ALL headers are 'wrong' - if I'm right...

 

Am I right?

 

-Andy

 

 

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

I use _bp to make it easy for myself but they both are single bits anyway no group of bits.

.equ CLK_PSADIV2_bm = (1<<4) ; Prescaler A Division Factor bit 2 mask
.equ CLK_PSADIV2_bp = 4 ; Prescaler A Division Factor bit 2 position = (1<<4)

So you need to or more than 1 bit in your expression 

CLK_PSCTRL = (CLK_PSADIV3_bm | CLK_PSADIV2_bm);

OR

 

CLK_PSCTRL = ((1<<CLK_PSADIV3_bp) | (1<<CLK_PSADIV2_bp));

edit I think I have the wrong bits looking at your code above but you get the point.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Sun. Mar 15, 2015 - 06:47 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For 0b00001100 you need to use CLK_PSADIV0 and CLK_PSADIV1 unless you REALLY want a single bit CLK_PSADIV2 which doesn't seem to be a valid choice on it's own.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Yeps!
Sorry, folks - I meant

#define CLK_PSADIV4_bm  (1<<6) 

 

Surely it should be: #define CLK_PSADIV4_bm  (3<<2) (or is it (5<<2)) ? Don't have my manual with me.

 

Realised my error when I was on my Sunday morning walk...I'd pasted my old (wrong) code onto the forum...got two replies before I could get back home to correct my mistake!

 

Anyway, my original premise holds...According to the manual all Prescaler A settings are odd numbers...sems setting bit 0 of the _gc is a 'shortcut' to turning off the prescaler.

I downloaded the latest AVR Toolchain (my home copy was out-of-date, although my dev. env. copy at work is auto-loaded by Atmel Studio. No difference)

 

Header files are definitely wrong. Surprised I can't find a reference to someone reporting this as a bug...

-Andy

 

Last Edited: Sun. Mar 15, 2015 - 08:35 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But what's wrong? Didn't you understand John's posts?

 

#define CLK_PSADIV4_bm  (1<<6)  /* Prescaler A Division Factor bit 4 mask. */
#define CLK_PSADIV4_bp  6  /* Prescaler A Division Factor bit 4 position. */

These are for bit number 4 in the PSADIV configuration, nobody said it was for the A prescaler to divide by 4. You have to combine the bits that corresponds to divide by four. Or directly use

    CLK_PSADIV_4_gc = (0x03<<2),  /* Divide by 4 */

 

Last Edited: Sun. Mar 15, 2015 - 10:06 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

(Puts thumb in mouth, tugs ear...Plays banjo on bridge...)

Sorry to have the temerity to post amongst the Gods as a complete imbecile, but I thought I did undestand John's post.
Except I'm having difficulty relating to: http://www.atmel.com/Images/Atme... section 7.9.2. Page 92.

" CLK_PSADIV_4_gc = (0x03<<2), /* Divide by 4 */"
If I had that, it'd be: MY CODE!!!!  YOWSER! (Toss banjo in river...)

-Andy

 

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

DON'T JUMP OFF THE BRIDGE........ wink

 

I have hardly used the Xmegas and I didn't quite understand the "new way" of naming the bits, isn't it maddening when people make things easier for you? I was just getting used to 1<<bitname when now they give me at least 3 ways of doing things.  _gc (group of bits, like you wanted) , _bp (bit position), _bm (bit mask) WHO'S RESPONSIBLE.  laugh

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

OK, now I've got it. Don't use -bm for this (why it's there will always be a mystery to me...) but use _gc.
(Can't even blame a hangover for my stupidity...)

From the header file,

CLK_PSADIV_4_gc = (0x03<<2),  /* Divide by 4 */

And it works. Of course, I didn't find it in Studio's helpful prompt, because - unlike _bm and _bp it has an extra underscore!

Now, the header file iox64a4u.h has a copy on my desktop, linked to notepad++ so I can search for these 'oddities' easily. I won't print it, 'cos it's 170 pages...

Ta for your patience.

-Andy

 

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

Hi all,

 

I suggest to read this app note from Atmel : http://www.atmel.com/Images/doc8075.pdf

 

Have a nice day,
Kraal