NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Basic Electronics » 14.7465 to 20.0000 mhz

November 16, 2009
by Farmerjoecoledge
Farmerjoecoledge's Avatar

What's the reason behind having to program with the 14.7465mhz, but you can run with a 20.0000mhz?

November 16, 2009
by Rick_S
Rick_S's Avatar

I'm by no means any kind of expert but this was what I've read and come to understand on the subject.

The Nerdkits guys chose that crystal speed to get a more precise timer base for serial communications. The uart is running at 115200 bps and that crystal speed is evenly divisible by that (14745600/115200 = 128). With a 20mhz crystal, it would not divide evenly possibly preventing reliable communications at the 115200 bps speed. (20000000/115200=173.611)

Being that the Nerdkit is programmed through a serial bootloader, accurate serial communications is a must. If the chip were programmed through another means such as an ISP programmer, and the uart was not being used, 20Mhz would be fine.

Rick

November 16, 2009
by Farmerjoecoledge
Farmerjoecoledge's Avatar

Hi Rick,

I'm finally begining to understand this Mr. uart guy. So he's the fussy one. Ok Mr uart were going to shut you off, temporarily.

I've got somemore reading to do. I've got an isp programmer coming and don't quite follow "if uart is not being used" part. I'm still very much a beginner with this stuff.

The serial bootloader is also a static serial bootloader too. Very good, i did know that, either.

farmer

November 16, 2009
by Rick_S
Rick_S's Avatar

By the "If the chip were programmed through another means such as an ISP programmer, and the uart was not being used, 20Mhz would be fine." statement, I meant this.

If you were to program the chip without the use of the Nerdkit bootloader through An ISP connected programmer, And the program you were running on your MCU did not do serial communications through the onboard UART or I guess technically on these its a USART (Universal Synchronous/Asynchronous Receiver/Transmitter) (pins 2 & 3 on the atmega168) then a 20Mhz crystal would be fine.

Of course, this also depends on the baud rate you were to communicate at. For a better grasp of Crystal frequency to Baud rate error, look at the data sheet for the mcu pages 200 thru 203 on the current datasheet from Atmel or pages 196 thru 199 on the datasheet in the Nerdkits download section. That may give you what you are looking for.

Rick

November 16, 2009
by tech20
tech20's Avatar

If you are going to use a ISP programmer, and still want easy uart communication, use a "magic number" crystal. For higher frequencies, you can check around the internet, but you are going into overclocking the MCU(risky). If your up to it, i might be able to find a seller for crystals of 29.4912MHz. As a note, i have heard of people working with the frequency on AVRFreaks.net.

November 16, 2009
by Farmerjoecoledge
Farmerjoecoledge's Avatar

Gotchya! I'm smarter now than i was 5min ago. I guess an example of a program that doesn't utilize Mr uart would be the ledarray2.c the serial communication is handled by python-listener.py, for the array,right? thx

November 17, 2009
by Rick_S
Rick_S's Avatar

Not really. Python-listner is the PC side software. The chip still uses it's serial communications to talk to the PC in LEDARRAY2.

This code in the main() function tell us this:

// init serial port
uart_init();
FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
stdin = stdout = &uart_stream;

An example of a non serial program would be a stand alone application in the MCU that does not interface with a pc via and rs232 serial cable such as a simple LED blinking program.

Rick

November 17, 2009
by mcai8sh4
mcai8sh4's Avatar

If I may add to this question.... if you use the faster crystal, the MCU runs faster. So if I had a program, that doesn't use UART comunication, and is programmed via an ISP, the program instructions would execute quicker. After looking at the delay functions from the libnerdkits directory, I see that these functions basically consist of 'NOP's which I assume are 'No operation' that takes a certain amount of time to do nothing. So running the program with a faster crystal would result in the delay functions executing faster.

Whilst I can't see any reason for anyone to use the delay functions for a 'critical' part of their program, using a faster chip may cause some problems regarding this.

From that assumption, does that also mean that the timer counters would count up faster.... so basically any code that relied on timing would (or could) be effected (PWM?) ?

If my thoughts are correct (it would be the first time today!), woohoo, if I'm wrong, then please do help me understand.

-Steve

November 17, 2009
by Rick_S
Rick_S's Avatar

From what I understand anything that uses crystal frequency for a timebase would have issue if the timebase wasn't adjusted for automatically. I haven't looked over the nerdkit delay module but if it doesn't adjust the number of NOP's based on crystal frequency, you would be correct.

November 19, 2009
by mikedoug
mikedoug's Avatar

mcai8sh4, you are absolutely correct. ALL things will happen faster in the MPU if you clock it faster. You will have to adjust all things with the clock scalers and other forms of trickery, and in the case of NOPs add more. It's all math.

I don't have any time to go into it further right now -- need to take a 5 year old to school. :)

MikeDoug

Post a Reply

Please log in to post a reply.

Did you know that you can connect digital calipers to a microcontroller? Learn more...