ATmega 4809 timming question and other

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

Hello everyone. i often program the classic family of AVR's  ATmega328p, 2560, etc etc. 
So i decided to buy some ATmega4809s and i am really confuse. Im trying to make a blinking led to study the new MCU.

 

my questions are:

 

1. there is not "XTALn" pins, instead there is a pin called "EXTCLOCK". i guess that i have to send a pulse to this pin with a resonator circuit like this one  https://abracon.com/datasheets/AWSCR-CPLA.pdf  (page2/6) and connect it 

am i right?

 

2. To configure the external clock i guess that i have to configurate the fuses as all MCU, but to define it in a program i can use the macro "F_CPU" like all the "classic" AVR's?

example:
 


#include <avr/io.h>

#define  F_CPU 4000000

#include "util/delay.h"

int main(void){

    while (1) {

          //CODE

    }

   return 0;
}



>

 

3. And my final question i often program the ports and registers of this form: 

DDRB |= (1<<DDB5);
PORTB |= (1<<PORTB5);

 

but in ATMEL Studio when i try to put:

PINCTRL |= (1<<PULLUPEN);

     as example

     its mark with the red line that shows that there is an error;

     in which part of the data sheet says how to configure this?

 

Thanks and saluts

 

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

 

ATmega4809 has no oscillation circuit. Therefore, use such an oscillator.

https://support.epson.biz/td/api/doc_check.php?dl=brief_SG7050CAN&lang=en

 

"F_CPU" only tells the compiler the frequency and does not affect the hardware settings.

 

The fuse setting can be described in the program.

However, this chip always starts with 1/6 clock of the internal oscillator regardless of the fuse setting.

You have to switch with your own program.

 

/* for ATmega4809 */
#include <avr/io.h>

// FUSE settings
FUSES = {
    .WDTCFG     = FUSE_WDTCFG_DEFAULT,
    .BODCFG     = FUSE_BODCFG_DEFAULT,
    .OSCCFG     = FUSE_OSCCFG_DEFAULT,
    .SYSCFG0    = FUSE_SYSCFG0_DEFAULT,
    .SYSCFG1    = FUSE_SYSCFG1_DEFAULT,
    .APPEND     = FUSE_APPEND_DEFAULT,
    .BOOTEND    = FUSE_BOOTEND_DEFAULT,
};

int main(void)
{
    // clock settings
    // disable prescaler & select extclk
    _PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, !CLKCTRL_PEN_bm);
    _PROTECTED_WRITE(CLKCTRL.MCLKCTRLA, !CLKCTRL_CLKOUT_bm | CLKCTRL_CLKSEL_EXTCLK_gc);

    while (1)
    {
    }
}

 

Postscript
ATmega4809 is a variety starting from the xmega series, and is different from the conventional mega chip.

It is recommended that you read this document.

 

http://ww1.microchip.com/downloads/en/AppNotes/doc8075.pdf

Last Edited: Wed. Sep 25, 2019 - 07:19 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use the factory internal clock for now...fool around with the clock after you have something working...blinking an led can use almost any clock speed.

 

Use DDRB= value  not DDRV |=value  , be explicit on what you want all 8 bits of the entire register set to....guessing not allowed.

 

but in ATMEL Studio when i try to put:

PINCTRL |= (1<<PULLUPEN);

Have you selected the proper chip number (device) in your studio 7 project config setup? 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

Simple blink for 4809-

 

#include <avr/io.h>
//only to inform delay.h what the actual cpu speed is
//but does not set the speed
//if fuse set to OSC20M, then default speed is-
#define F_CPU 3333333ul
#include <util/delay.h>

int main(){
    PORTF.DIR |= 1<<5;//led=PF5=output
    for( ; ; PORTF.OUT ^= 1<<5, _delay_ms(500) );
}

//there is also VPORT, .OUTSET/.OUTCLR/.OUTTGL
//and many others, need to read the datasheet
//and the iom4809.h header file

 

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

The internal clock(s) in the new series 0/1 chips is much better then the ones in mega/tiny, you may not need an external clock for most projects!

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

Charpie wrote:
1. there is not "XTALn" pins, instead there is a pin called "EXTCLOCK".
TOSC1 and TOSC2 pins for a 32KHz crystal; Microchip mega4809 boards have this crystal.

Arduino Nano Every has no crystals.

The AVR 32KHz app note has been updated for megaAVR 0-series though without recommended crystals.

 

ATmega4809_Curiosity_Nano (page 2, D4) via ATmega4809 Curiosity Nano

NANOEveryV3.0.sch (PDF) via Arduino Nano Every (Documentation tab)

AN2648 Selecting and Testing 32 KHz Crystal Oscillators for AVR Microcontrollers

AN_8002 AVR055: Using a 32kHz XTAL for run-time calibration of the internal RC via ATmega324PB - 8-bit PIC Microcontrollers

 

"Dare to be naïve." - Buckminster Fuller