Clock question

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

I have a rather esoteric question about using an external xtal and I believe I already know the answer but will throw it out to the experts.

 

I have an evil mad scientist ATMega328P bare development board that I have installed a 16mHz xtal but I want to run the board at 3.3V.

What I have done is set the fuse to use the internal 8mHz xtal but still have the external xtal in place and am having timing issues.

 

So my question is even though I have the external xtal installed and have programmed the chip to use the internal xtal, is the external xtal interfering in some way with the operation of the chip?

 

Thanks

Last Edited: Wed. Nov 11, 2015 - 04:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is the CKDIV8 fuse enabled? If so, the internal clock will operate at 1MHz.

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

There is no "internal 8mHz xtal". This statement is incorrect in at least two ways:

 

1. mHz is milliHertz (1E-3Hz = .001 Hz). You surely mean MHz (megaHertz, or 1E6Hz = 1000000 Hz)

 

2. The internal oscillator is NOT a crystal oscillator. It is an RC oscillator. Big difference is accuracy and stability.

 

I've never had any issues with a connected external crystal while using the internal oscillator. Please specify "timing issue"! Is it off a little? Or, is it 1MHz instead of the expected 8MHz as james_y suggests?

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

ka7ehk wrote:

There is no "internal 8mHz xtal". This statement is incorrect in at least two ways:

 

1. mHz is milliHertz (1E-3Hz = .001 Hz). You surely mean MHz (megaHertz, or 1E6Hz = 1000000 Hz)

 

2. The internal oscillator is NOT a crystal oscillator. It is an RC oscillator. Big difference is accuracy and stability.

 

I've never had any issues with a connected external crystal while using the internal oscillator. Please specify "timing issue"! Is it off a little? Or, is it 1MHz instead of the expected 8MHz as james_y suggests?

 

Jim

 

Sorry I'll be more careful in my phrasing in the future, not good at asking questions as can be seen by past inquiries.

 

The problem is I'm bit banging a display (SPI), I think the display might be bad but that's another issue.  I hooked up my Saleae logic analyzer and when I run it at 3.3V I get junk and when I bump it up to 5V the output is as expected.  I get same results with or without display being attached.

 

It's a 3.3V display so I would have to use level shifters and am trying to keep the  chip count down.

 

The fuses are set at; L: 0xE2, H: 0xD9

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

Is AVcc tied to Vcc?

 

Does EVERY Vcc/Ground and the AVcc/Ground pin pairs have a 0.1 uF by-pass cap across the pins, as close to the uC as you can put them?

 

Does a simple "flash - the - LED" at 1 Hz program work at 3 V?

 

What does "I get junk" mean?

No rectangular pulses?

Amplitude not correct?

Leading / falling edges aren't square?

The correct pulse string, but at the wrong frequency?

etc.

 

A photo of the PCB, the 5V output, and the 3V output would help.

 

You can post jpg's using the media Icon, the Mountains, two to the left of the smilie face icon.

 

JC

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

"Working" at 5V, not at 3.3V is suggestive of excessive (too high) clock frequency.  

 

But, there are other possible reasons. Do you have any other logic running around on the board? Check the LA on that. Does it stay solid as you change from 5V to 3.3V? This chip has a CKOUT pin. Set the fuse to enable that and check whether it stays solid as the voltage changes.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

ka7ehk wrote:

"Working" at 5V, not at 3.3V is suggestive of excessive (too high) clock frequency.  

 

But, there are other possible reasons. Do you have any other logic running around on the board? Check the LA on that. Does it stay solid as you change from 5V to 3.3V? This chip has a CKOUT pin. Set the fuse to enable that and check whether it stays solid as the voltage changes.

 

Jim

Thanks Postman, I guess I need to back through and check everything again because I put the code on an identical board but without the external xtal and it works fine. 

The thing is I also had an MCP23S17 set up to scan a 4X4 keypad, I know overkill but it worked on the original board without external xtal and it wouldn't work on the board with the external xtal either.

 

When I said I was getting junk I meant random 1's and 0's on the MOSI, MISO, CLK and CS pins when I was expecting normal data.  They were square waves and yes I have caps on several places on the board were provided.  I have used this board extensively and I know it to be stable that's why the original question.

 

Thanks y'all

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

I would recommend you restore the fuses to use the external crystal, but also program CKDIV8. This will cause the AVR to power up at 2 MHz. Then early in main() you can tickle CLKPR to set a prescaler of /2 to run at 8 MHz. This will give you the stability and accuracy of a crystal clock source.
By the way, what is the extended fuse? That sets the BOD. If it is set for too-high a threshold, the AVR will be kept in reset and all the pins will be floating and appear 'random'.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Wed. Nov 11, 2015 - 08:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:
I would recommend you restore the fuses to use the external crystal, but also program CKDIV8. This will cause the AVR to power up at 2 MHz. Then early in main() you can tickle CLKPR to set a prescaler of /2 to run at 8 MHz. This will give you the stability and accuracy of a crystal clock source. By the way, what is the extended fuse? That sets the BOD. If it is set for too-high a threshold, the AVR will be kept in reset and all the pins will be floating and appear 'random'.

 

Hadn't thought of that, good eye!

 

Thanks y'all for the expertise!