[Ignore post, I'm wrong] #define Bugs in header files

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

These are ALL wrong ( latest Winavr ), for the '128A1 and '16A4 parts at least and I'm CONFIDENT it's in ALL the *.h files !! :? :x

/* System Clock Selection */
typedef enum CLK_SCLKSEL_enum
{
    CLK_SCLKSEL_RC2M_gc = (0x00<<0),  /* Internal 2MHz RC Oscillator */
    CLK_SCLKSEL_RC32M_gc = (0x01<<0),  /* Internal 32MHz RC Oscillator */
    CLK_SCLKSEL_RC32K_gc = (0x02<<0),  /* Internal 32kHz RC Oscillator */
    CLK_SCLKSEL_XOSC_gc = (0x03<<0),  /* External Crystal Oscillator or Clock */
    CLK_SCLKSEL_PLL_gc = (0x04<<0),  /* Phase Locked Loop */
} CLK_SCLKSEL_t;

Correct values are, using pg 87 of manual A :

/* System Clock Selection */
typedef enum CLK_SCLKSEL_enum
{
    CLK_SCLKSEL_RC2M_gc = (0x01<<0),  /* Internal 2MHz RC Oscillator */
    CLK_SCLKSEL_RC32M_gc = (0x02<<0),  /* Internal 32MHz RC Oscillator */
    CLK_SCLKSEL_RC32K_gc = (0x04<<0),  /* Internal 32kHz RC Oscillator */
    CLK_SCLKSEL_XOSC_gc = (0x08<<0),  /* External Crystal Oscillator or Clock */
    CLK_SCLKSEL_PLL_gc = (0x10<<0),  /* Phase Locked Loop */
} CLK_SCLKSEL_t;

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

Last Edited: Fri. Jan 6, 2012 - 05:43 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you sure about that? I disagree.

The table on page 87 allows you to individually turn on and off each of the various oscillator sources, and it does indeed have an individual bit field for each oscillator source. But that has to do with the OSC.CTRL register. The WinAVR defines for these bitfields are named OSC_PLLEN_bm, OSC_XOSCEN_bm, OSC_RC32KEN_bm, and OSC_32MEN_bm, and have the correct values according to my copy of WinAVR 20100110.

On the other hand, the CLK.CTRL register, which is used to select which of the enabled clocks should be routed to the system clock, is defined by a table on page 84, and it appears to correspond perfectly with WinAVR's CLK_SCLKSEL_*_gc definitions.

Hint: The WinAVR defines all name the subsystem for which they apply in the first word of the define. So, the CLK_* defines have to do with the registers in the CLK data structure (documented on pages 84 to 86), whereas the OSC_* defines relate to the registers in the OSC data structure (documented on pages 87 to 91).

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

You're right, thanks for the assist ! I was confusing the clk_ctrl register with the osc_ctrl bit settings... Sorry for the noise ! :roll:

I confused myself in this thread :

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

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