mega4808 clock source

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

 

I see the mega4808 does not allow connection of a main xtal (other than a 32KHz low freq xtal osc).  so if i want an oddball freq (it is going to be 10.55 MHz) , I need to pump in an external clock source.  Ok, fine.  

 

However, I can't presently use the EXTCLK pin, can I use the TOSC1...described as: Instead of a crystal oscillator, TOSC1 can be configured to accept an external clock source.  AND  Alternatively, an external digital clock can be connected to the TOSC1 pin.

   Great!! However, later,  where it talks more about it, it says:

     Either a crystal is connected to the pins TOSC1 and TOSC2, or an external  clock running at 32 KHz is connected to TOSC1.  WELL, I don't want 32KHZ, I want 10.55 MHz , Does this pin have a 32 KHz freq limit?

 

Note that I have no interest in using the RTC, I just need straightforward clocking of the AVR.

 

    So is the proposed hookup viable?  This diagram seems to indicate so:

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

Last Edited: Mon. Jul 20, 2020 - 03:56 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:
Does this pin have a low freq limit?

 

I would say the pin is only for 32kHz

Last Edited: Mon. Jul 20, 2020 - 02:41 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe it is the function of the PA0 pin.

 

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

Maybe it is the function of the PA0 pin.

Take a look at the post, it states I cannot not use PA0 (However, I can't presently use the EXTCLK pin), it is not accessible now, I need to inject at TOSC1, is that possible? 

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

Last Edited: Mon. Jul 20, 2020 - 03:57 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sorry. I have never done it.

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

I have never done it, but the way I read the datasheet, you should be able to use 10.6MHz on TOSC1 as long as you are operating at 5V ±10%.

(I am referring to Fig 32-4 and Table 32-16 as well as those sections you referenced.)

 

Just be mindful of all the configuration registers... and the notice from 10.3.4.2.1 "When XOSC32K is configured to use an external clock on TOSC1, the start-up time is fixed to two cycles."

 

P.S.

If it releases the magic smoke, I was wrong! devil

David

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

frog_jr wrote:
I have never done it, but the way I read the datasheet, you should be able to use

 

It should be easy to try it out.

And next time it should be easy to plan properly from the beginning and use the designated pin.

If the accuracy requirements allow it, it should also be possible to adjust the internal clock to the required clock approximately.

 

I believe XOSC32K is not called XOSC32K for nothing.

And they don't emphasize in the data sheet for nothing:

"Either a crystal is connected to the pins TOSC1 and TOSC2, or
an external clock running at 32 KHz is connected to TOSC1"

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

is not called XOSC32K for nothing.

Agreed, since if you want to drive an Xtal, oscillator circuitry is tuned to that range of xtals.

 

However for ext input on TOSC1, why don't they include an actual spec?

 

notice they also say:

Instead of a crystal oscillator, TOSC1 can be configured to accept an external clock source

What if you connected a clock at 40 KHz--would the processor no longer run?  

This appears to be a small hole in the spec.  Of course if you want to use the RTC, it expects 32.768 KHz...but  we don't need to use RTC.

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

avrcandies wrote:

This appears to be a small hole in the spec

32.768 kHz are specified, so xxx MHz are outside the spec and missing information about this are no small hole.
Of course you can now test the limits but this is no longer a safe operation. By the way, have you already tried?

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

32.768 kHz are specified

The commentary shows it both ways, so perhaps one is simply more restrictive than the other (and is the more typical usage).  However, the actual spec tables don't give anything about it at all, hence a question on TOSC1's allowable range. It may well be that it performs similar to the EXTLK input, with the exception being it doesn't route to TCD clk select. 

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

avrcandies wrote:
This appears to be a small hole in the spec

It does.

 

Time to raise a ticket with Microchip - and get them to clarify ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

I tried.
I generated 16MHz by tiny1616 and supplied it to TOSC1 of mega809.

 

 

With the code below the LED flashed at the correct 1Hz.

#define F_CPU   16000000L

#include <avr/io.h>
#include <util/delay.h>

FUSES = {
    .WDTCFG     = FUSE_WDTCFG_DEFAULT,
    .BODCFG     = FUSE_BODCFG_DEFAULT,
    .OSCCFG     = FUSE_OSCCFG_DEFAULT,
    .SYSCFG0    = FUSE_SYSCFG0_DEFAULT,
    .SYSCFG1    = FUSE_SYSCFG1_DEFAULT,
};

int main(void){
    PORTA.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTA.PIN1CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTA.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTA.PIN3CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTA.PIN4CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTA.PIN5CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTA.PIN6CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTA.PIN7CTRL = PORT_ISC_INPUT_DISABLE_gc;

    PORTB.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTB.PIN1CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTB.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTB.PIN3CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTB.PIN4CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTB.PIN5CTRL = PORT_ISC_INPUT_DISABLE_gc;

    PORTC.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTC.PIN1CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTC.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTC.PIN3CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTC.PIN4CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTC.PIN5CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTC.PIN6CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTC.PIN7CTRL = PORT_ISC_INPUT_DISABLE_gc;

    PORTD.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTD.PIN1CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTD.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTD.PIN3CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTD.PIN4CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTD.PIN5CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTD.PIN6CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTD.PIN7CTRL = PORT_ISC_INPUT_DISABLE_gc;

    PORTE.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTE.PIN1CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTE.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTE.PIN3CTRL = PORT_ISC_INPUT_DISABLE_gc;

    PORTF.PIN0CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTF.PIN1CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTF.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTF.PIN3CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTF.PIN4CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTF.PIN5CTRL = PORT_ISC_INPUT_DISABLE_gc;
    PORTF.PIN6CTRL = PORT_ISC_INPUT_DISABLE_gc;

    PORTD.DIRSET = PIN5_bm; // LED

    // EXTCLK
    _PROTECTED_WRITE((CLKCTRL.XOSC32KCTRLA), CLKCTRL_SEL_bm | CLKCTRL_ENABLE_bm);
    _PROTECTED_WRITE((CLKCTRL.MCLKCTRLB), !CLKCTRL_PEN_bm);
    _PROTECTED_WRITE((CLKCTRL.MCLKCTRLA), CLKCTRL_CLKOUT_bm | CLKCTRL_CLKSEL_XOSC32K_gc);

    while (1){
        _delay_ms(500);
        PORTD.OUTTGL = PIN5_bm; // LED
    }
}

Is this the correct usage?

I do not know.

 

 

Edit:
The mega stops when I remove the tiny1616.
Evidence of working with an external clock.

Last Edited: Tue. Jul 21, 2020 - 05:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

>Is this the correct usage?

Yes.

 

I did the same thing with a tiny817 and tiny3217. Seems to work, and would make sense according to the diagram (tosc1 bypasses osc circuit, goes to a mux, assume its just digital at that point and is no different that ext clock). I'm not sure I would bet the farm, but would wager a few ears of corn it probably is fine. 

 

Whether you want to wait for an official approval (or non-approval) is up to the user, but in any case I would just test it out for some length of time before 'real' use.

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

Nice to know.  I wonder if this works with the AVRxxxDAxx series?

 

I have another question about clock source.  These chips seem to have a PLL, but it can only be used for some of the timers, and NOT the processor.  I think the PLL can use the 32khz crystal as a reference clock.  Why can't the PLL generate the system clock?  The SAM series chips have this clock option.

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

kabasan wrote:
I tried.

 

Thanks Kabasan.

There is nothing like the practical test of things.

 

curtvm wrote:
Seems to work

 

Sometimes it seems better to leave out information in the data sheet:

 

"... or an external clock running at 32 KHz is connected to TOSC1"

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

kabasan wrote:
I tried.

Maybe I could send a couple bucks to avrcandies and then all would be determined>

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

With the code below the LED flashed at the correct 1Hz.

Thank you very much for the test, it is a relief to know!  I don't have the chip yet, so can't test anything, but with your wonderful test, appears there will be no trouble.   

 

When I first read  Instead of a crystal oscillator, TOSC1 can be configured to accept an external clock source, we went with that, and PA0 was used for other things.

.....later on it was seen:  Either a crystal is connected to the pins TOSC1 and TOSC2, or an external clock running at 32 KHz is connected to TOSC1, so that extra phrase caused a lot of concern!

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