I use ATMEGA256rfr2 . I would like to read the external crystal. its operating frequency is 16mhz. In xtal1 and xtal2 ,there are 8pF capacitors attached and grounded respectivley. I use Atmelstudio 7.How can I read the external crystal ? Any ideas? thanks

What do you mean by "read"? You cannot read crystals. Do you mean you want to activate it so it is used? You do that with the CKSEL fuse bits - but make sure you know what you are doing before changing them!!

...its operating frequency is 16mhz...How can I read the external crystal ?

If you know the frequency then why do you need to read it?

pika wrote:

...two 8pF capacitors attached and grounded respectivley.

That seems awfully low.

pika wrote:

How can I read the external crystal ? Any ideas? thanks

If you are asking 'how can I measure what frequency an unknown crystal connected to my AVR is' the answer is...you can't unless you provide another reference frequency to measure against. This could be the other 32.768kHz crystal or even the local mains.

"This forum helps those that help themselves."

"How have you proved that your chip is running at xxMHz?" - Me

"If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

The datasheet for the chip will tell you what CKSEL (and SUT) fuses there are and how to set them for various clocks. Make sure you pick "crystal" not "clock" and set the SUT to the longest possible. If the device has something called CKOPT make sure it is enabled. Crystals over 8MHz need high power drive.

I have attached a picture of the settings. Should i do any other changes?

You have not read all of the above posts have you?

Pay attention to post #10.

"This forum helps those that help themselves."

"How have you proved that your chip is running at xxMHz?" - Me

"If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

Actually , I did read and I'm pretty sure I did not understand fully. My doubt is , the CKSEL was the one thing that can be changed on the debugger settings. http://www.atmel.com/Images/Atme... ,from pg 177, I found this information and there is in CKOPT present in this device. So,is this enough? or should I do anyother changes ? With the power connection,Shall I will try with 5volts?

His point was that I said you must choose "crystal" and not "clock" but your picture shows you picked a "clock" option. This is wrong and if you go ahead with the settings like that you will make it quite difficult to be able to contact the AVR again as it will then be looking for a clock source that does not exist. (crystal != clock !)

This has been coming up regularly ever since I started reading Freaks. I don't think either the datasheet or the programming tools makes it clear enough to beginners what a clock is and what a crystal is. I suppose the argument goes "these things are for professionals - they don't want hand holding" (though this has never stopped Microsoft / Apple adding "Fischer-Price" interfaces to their supposedly professional software!). Perhaps the programming dialog should be:

So does it mean that when I want to choose the external crystal for its operation (not clock) and I choose "external clock " (for crystal also I choose the clock but with the picture of a crystal must be available on the right side) .Is this right ? I do not get any picture like that. Maybe my external crystal is not detected ?

The point being that most "crystals" are in some kind of package with (usually!) 2 pins while 4 or more pins probably means you have a "clock" (aka "oscillator")

In the AVR set the fuses to "crystal" if you have a crystal and "clock" if you have a clock. If you make the mistake of selecting "crystal" and you actually have a clock you will likely get away with it. However if you make the mistake of selecting "clock" when what you have is a crystal you may be in for a bit of a fun ride. That was the point I was making in #10

I think we're all missing something here. Fortunately, the OP pika is around, so I'm going to ask:

To pika: Do you want the AVR itself to determine if there is an external crystal it can use?

I can see this as a useful bit of programming, because AVRs set to use external crystals when plugged into boards that don't have external crystals don't work real well (at all, actually). I don't know how to do it exactly, but I have some ideas (on AVRs with other functions on XTAL pins). Actually measuring the frequency does rely on another reference, as was pointed out before (Brian Fairchild, post #5). If you're just fiddling about with external clocking, the LED flash routine will tell you everything you need to know.

I would suggest that's because no one has ever determined a way to do it.

When Atmel switched from tiny/mega to xmega they took a leap of faith and made a chip that always starts up at 2MHz on the internal oscillator. The programmer can then configure various other clock sources at run time. Wiat for them to "settle" then switch them active.

Tiny/Mega simply don't have anything like that. The clock source choice for tiny/mega is made at power on from the fixed setting of some fuse bits. To make a "dynamic switch" the AVR would presumably need to be set to "internal RC" (the only one guaranteed to work), it would then probe for / decide what clock is really required and then here comes the clever bit - it would need to reprogram it's own fuses and then force a power cycle so that, at the restart, the new CKSEL setting was read and acted upon.

Tiny/Mega cannot reprogram their own fuses from code running within them.

I could see a possible solution involving two AVR chips where one acts as an "ISP"er to the other. So after the decision was made the non mainline chip would get some kind of message as to how the fuses must be set then it performs ISP on the other chip to change its clock source and power cycle it. But this would be "fraught" !

I could see a possible solution involving two AVR chips where one acts as an "ISP"er to the other. So after the decision was made the non mainline chip would get some kind of message as to how the fuses must be set then it performs ISP on the other chip to change its clock source and power cycle it. But this would be "fraught" !

Highly clever, though. And you could use a dinky little one as the 'clock-setter' while a much bigger AVR did the heavy lifting.

In short, pika, at this time I think you get to decide as a human being (or small mountain rodent?) what your AVRs will use for timing at the time you program them.

S.

PS - If you're up for all that sort of rot, just stick a crystal and a couple caps on the board already. Seriously, dudes! S.

But I do not know , if itself can determine the presence of the external crystal or should we configure it through debugger

Your question is still vague. Do you really mean the 256rfr2 should "auto detect" if there is a crystal there and use it if present, otherwise revert to using the internal RC (that can be relied upon)? As I have just explained this is not possible with an ATmega chip such as 256RFR2. You, the designer have to make a design time decision as to whether your circuit/design is OK using the inaccurate internal RC or do you need a crystal. Once you have made that decision (and assuming the answer is crystal) then you perform a one-time ISP session on the chip to set the CKSEL bits (but making sure it is "crystal" for crystal and "clock" for clock!) and then when you next power on that AVR it will start to use the currently selected source (if present).

Sounds a lot like you have decided to use crystal. You have the (probably 2 pin) crystal component (and two 12..20pF capacitors) and you are going to connect them to the XTAL1/XTAL2 pins of the chip. Once you have done that you can perform the ISP operation then power cycle the circuit and the next time the 25RFR2 starts up it will now be running using the crystal.

If you ever want to switch back (or switch to "clock") then you would wire up whatever is to be expected (or nothing if reverting the internal RC) then you would do ISp again to set CKSEL to a new setting and this time, after the next power cycle the chip would start up using the newly selected source and so on...

What I mean is, in the drop down menu of the fuses , clock select CKSEL there are many options for the clock with different SUT settings. So ,I expected that the external clock would also be an option in it and it can be chosen over the internal crystal. Is it not possible through JTAG?

I could maybe see a situation where something offered some kind of "optional extra" functionality that maybe include RTC or UART operation that would benefit from an accurate clock but you sell this without and the user can choose to upgrade. They then fit the crystal and in the next convoluted power on sequence its presence is noted (and the fact that the CKSELs have not already chosen it) so then chip 2 reprograms chip 1. How it actually detects it is another interesting challenge - perhaps a mechanical sensor or an optical sensor or something? Or if you want it really fancy: a small camera that does optical recognition and can actually "see" the difference between a 2 and 4 pin package and eve makes the crystal/clock choice too!

But this side track is probably confusing the ever living life out of OP who only wants to enable a crystal on his single AVR!

What I mean is, in the drop down menu of the fuses , clock select CKSEL there are many options for the clock with different SUT settings. So ,I expected that the external clock would also be an option in it and it can be chosen over the internal crystal. Is it not possible through JTAG?

look right down that list. I forget the exact wording but you will see a number of entries for "internal RC", then a number of "external crystal", then a number for "external clock". The point is that you want to change it from one of the "internal RC" options that it is now to one of the "external crystal" options but being very careful to avoid anything that says "external clock" such as was showing in the picture in post #14

Sounds a lot like you have decided to use crystal. You have the (probably 2 pin) crystal component (and two 12..20pF capacitors) and you are going to connect them to the XTAL1/XTAL2 pins of the chip. Once you have done that you can perform the ISP operation then power cycle the circuit and the next time the 25RFR2 starts up it will now be running using the crystal.

This is what I want to do and I have connected the two-pin crystal between xtal1 and 2. But cant this be done through ISP ?

What I mean is, in the drop down menu of the fuses , clock select CKSEL there are many options for the clock with different SUT settings. So ,I expected that the external clock would also be an option in it and it can be chosen over the internal crystal. Is it not possible through JTAG?

All right, quiet down, guys.

You must select CLKSEL depending upon what else there is upon your circuit board to provide a clock. If it is an external crystal oscillator, then you select 'clock'. If it is an external crystal (with capacitors) then you select 'crystal'. If you wish to go with what the chip came with inside, that's 'internal oscillator'. We deliberately chose all these terms to confuse non-English speakers.

You must select CLKSEL according to the parts on your circuit board. The AVRmega you are using cannot choose for itself. Yes, you may force it to choose any of the above by using JTAG.

You must select CLKSEL depending upon what else there is upon your circuit board to provide a clock. If it is an external crystal oscillator, then you select 'clock'. If it is an external crystal (with capacitors) then you select 'crystal'. If you wish to go with what the chip came with inside, that's 'internal oscillator'. We deliberately chose all these terms to confuse non-English speakers.

You must select CLKSEL according to the parts on your circuit board. The AVRmega you are using cannot choose for itself. Yes, you may force it to choose any of the above by using JTAG.

S.

This is perfect !

If it is an external crystal (with capacitors) then you select 'crystal'.

This crystal is not available in my menu ! Could the connection of the crystal be a problem? maybe its not connected well that the debugger does not show it?

So I guess most readers here were expecting the 256RFR2 to offer the same.

Presumably the RFR2 in the 256RFR2 name means this is a "radio chip" of some sort? In that case I guess it has tuned radio oscillators and this mysterious "Transceiver Oscillator" is something to do with that? I think (as I said in #10 in fact) that it may be time to consult the datasheet to find out what your options are. The items in the programming dialog (that come from the XML I just showed) will just reflect what is actually described in the datasheet.

As an aside I should mention that the only reason for picking a faster 'start-up time' is if your nodes (AVRs) are going to be spending a lot of their time completely powered off and only powered on for a very short period of time (seconds, if not half a second or less). If that is the case, you will need to measure just how fast your external clocks (and everything else, including RF driver amplifiers) do power up and become stable, and once you have done that you might be able to cut down the powerup time. Until then, use the longest ones. S.

Unlike other AVRs that have multiple crystal options you basically have a choice of one here. Either there is a 16MHz crystal (with 2 capacitors to Gnd) across XTAL1/XTAL2 or there isn't. After that the choices are just:

The usual advice is to use the longest startup time possible to give the crystal a chance to start resonating.

But start by reading the whole of Chapter 11 in the datasheet so you understand the whole picture.

I'm sure if you pulled any of the ATDF files you could find at least one typo error in each (which kind of makes you wonder why Atmel have never sat someone down with a spell checker and a pile of XML files!)

I'm sure if you pulled any of the ATDF files you could find at least one typo error in each (which kind of makes you wonder why Atmel have never sat someone down with a spell checker and a pile of XML files!)

Possibly because XML tags cause any spellchecker I've ever met to go into conniptions? There may be those that can overlook them.

Anyhow, advice for pika is, as I see it, set CLKSEL to 0x3F.

This presumes an external crystal with capacitors (I use 18pF on all my AVRs, and have never been disappointed, although different crystals are known to want different values) all wired up correctly. And yes, the OP must set the fuses through their debugger.

pika: What you have to do is hook up a 16MHz crystal (Xtal, 2 pins) with capacitors (2x, 10-20picofarad) to the XTAL pins (doesn't actually matter which, but see the schematic in post #20) and then set the rest of the AVR to run off the transceiver crystal. Set the CLKSEL fuses to Transceiver Oscillator, longest possible startup time.

Try that. If it doesn't work, get back to us, and we'll blizzard you once more with irrelevant trivia.

S.

PS - The original 8pF caps you had are probably too small. S.

PPS - No, you can't do RF with the AVRs internal RC. - Edit: Ref. post above, as I did without proper credit.S.

I seslcted the option : Transceiver Oscillator;Start-up time : 16K CK +65ms. The program is flashed without any errors (using Start without degugging option). Then I tried the Start debugging option,but that leads to an error like the picture below. When I tried the internal RC it works fine. What does this mean ?