OK to have crystal oscillator on OSC pins when configured for internal osc?

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

I have a ATmega328p design that has a 32.768 Khz oscillator on the XTAl1 and XTAL2 pins.  This was for an internal RTC implementation.

 

I have compile flags that conditionally configure the oscillator for 32.768.  When I want maximum battery life, functionality that needs the RTC is disabled.

 

I saw some quirky behavior after reprogramming a part.   I was getting a mis-compare on the same addresses as a part on a completely different board.

 

When I when ahead without verifying, the code didn't run properly.    It's like the the program would get to a certain spot, then restart.  Like maybe a WDT reset.

 

I went in debug mode an saw that was what was happening.  The program would step along and then, back to the beginning.

 

But, after I closed debug mode, and cycled power, everything seems to be working ok.  I did a flash verify. 

 

No mis-compares.  Maybe programming via debugWire worked when ISP didn't?

 

Do I need to remove the oscillator from the OSC pins if I want to run with an internal oscillator?  Could this explain the spurious execution and flash mis-compare?

 

Two boards had the same address mis-compare, but only one had the spurious execution issue.  But, now I can't reproduce the execution issue--it's running ok now.

 

Both the "quirky" boards are about 10 years old.  But, probably less than 500 hours total power on time.

 

 

Last Edited: Sun. Oct 3, 2021 - 11:59 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Life is much simpler when you quote your actual fuse values e.g. HEX values.   Then we don't have to guess.

 

You can run the mega328P on the 8MHz RC

You can put a watch crystal on the TOSC pins.   Run a TOSC oscillator e.g. for a RTC.

Or set the TOSC pins as GPIO when you don't need the TOSC oscillator.

 

On a mega328P the TOSC pins are on PB6, PB7

 

David.

 

 

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

Yes,  as I posted there is an oscillator on the PB6,PB7 pins.  Also known as PB6(XTAL1/TOSC1) and PB7(XTAL2/TOSC2).  

 

Fuses are set for internal oscillator, when I don't need the RTC, eg:

 

Extended:    0xFD

High:           0xD9

 

 

(Internal RC oscillator)

 

The question--

 

Is it Ok to have an external oscillator on the XTAL1/XTAL2 pins when using the internal oscillator?

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

david.prentice wrote:

Or set the TOSC pins as GPIO when you don't need the TOSC oscillator.

 

 

Isn't that their default state?

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

davethomaspilot wrote:

Do I need to remove the oscillator from the OSC pins if I want to run with an internal oscillator? 

I could not find any corresponding warning in the entire datasheet, only this:
"In this mode, a crystal Oscillator is connected to this pin, and the pin cannot be used as an I/O pin."
 

The truth is more important than the facts.

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

Thanks for checking.

 

It was just a WAG.  Maybe it has something to do with it previously being in external oscillator when first programming to then use internal.

 

Anyway, both units seem to be working without issue now.  Now that I have some parts (Thanks Jim!), I'm building new boards without the oscillator on them.  

 

 

Last Edited: Sun. Oct 3, 2021 - 04:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

davethomaspilot wrote:

Fuses are set for internal oscillator, when I don't need the RTC, eg:

 

Extended:    0xFD

High:           0xD9

It is LFUSE that determines clock type, SUT, etc

Is it too difficult to just quote your LFUSE, HFUSE, EFUSE values ?

 

Yes,  GPIO is the default state.   But if you have configured for TOSC you need to re-configure for GPIO when you are attempting to reduce current by stopping the TOSC.

 

Life is much easier if you quote Fuse value.

Copy-paste your TOSC configuration statements.

 

Then you will get accurate replies.

 

David.

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

But if you have configured for TOSC you need to re-configure for GPIO when you are attempting to reduce current by stopping the TOSC

 

But, I'm not doing that!  There are NO TOSC configuration statements--they are conditionally compiled--#ifdef HAVE_RTC .. #endif RTC.  

 

 

It is LFUSE that determines clock type, SUT, etc

Is it too difficult to just quote your LFUSE, HFUSE, EFUSE values ?

 

Well, I guess so.  I thought I explained why it's not relevant, 

 

If you STILL think that's relevant,  please tell me how to get what you requested.  Attached is a screen shot of what I see when I read the fuses.

 

Everything is default except CKDIV.

 

 

 

 

 

Attachment(s): 

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

EXTENDED = 0xFD

HIGH     = 0xD9

LOW      = 0xE2

 

seems pretty straightforward to type the HEX values from the JPG.

Yes,  your fuses seem fine.   As I said earlier typing LFUSE=0xE2 removes all guesswork.

 

Conditional RTC compilation is fine.   You will only get accurate advice if you paste your code.

I assumed that you wanted to disable RTC at runtime.

 

David.

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

Is it Ok to have an external oscillator on the XTAL1/XTAL2 pins when using the internal oscillator?

 

I assume you mean that you have an external crystal on the Xtal pins, not that they are connected to an external oscillator, (which itself generates a signal and injects it into the uC's pin).

 

Then, Yes, you can have an Xtal on the Xtal pins and use an internal clock source.

That is not a problem, and in and of itself it should not generate any of the problems you mentioned.

 

JC 

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

Even an external oscillator SHOULD not be a problem if XTAL1 is turned back into a normal GPIO. As far as I can tell, that is what actually happens with an M328P.

 

Jim

 

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

 

 

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

... IF the XTAL1 is setup as INPUT... otherwise the XTAL1 port pin will be suffering from the external current sucking vampire bug at the clock frequency.

You don't want to short circuit to ground a port pin set as output and high level, the clock oscillator will be doing exactly that half the time.  

Wagner Lipnharski
Orlando Florida USA

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

davethomaspilot wrote:

I have a ATmega328p design that has a 32.768 Khz oscillator on the XTAl1 and XTAL2 pins.  

You need to give exact part numbers.

Most common is to use an external 32.768kHz crystal, which connects to two pins, and that is not an external oscillator.

Powered 32.768kHz external oscillators are less common, and those connect to one pin only, and generate a CMOS or reduced amplitude output. (depends on model) 

 

 

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

Who-me wrote:

You need to give exact part numbers.

Most common is to use an external 32.768kHz crystal, which connects to two pins, and that is not an external oscillator.

 

You are quite correct.

32768 Hz is very difficult to find in metal case 4 pins powered oscillator.

The super comom is the cylindric small very low power crystal.

We don't know how the OP program the fuses when he needs to use that 32768 crystal.

The correct setup is "EXTERNAL CRYSTAL / OSCILLATOR", not "EXTERNAL CLOCK".

His expression of "External Oscillator" is not very correct, since the crystal is not an oscillator, but he may be have good intentions to select "External Crystal" on the fuses.

We simply don't know.

Even so, the super fragil 32768 cylindric crystal can be damaged by applying 5V directly to it, when the AVR powers up with Xtal1/2 as GPIO, but chances are both port pins lift to 5V at the same time.

Some AtMegas has selection for external crystal of low power, instead of full swing, since full swing can damage fragile crystals.

 

Here at the company we are forbidden to use Huntron Tracker around such small crystals on motherboards, it fries them, with its 10V 80Hz AC 54Ω waveform.

 

Wagner Lipnharski
Orlando Florida USA