how to set desired frequency on STK500 for USART

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

hi i am using STK500 with Atmega16 and would like to set the Atmega at 3.6864MHz (since i need a multiple of 1.8432M) so that i can use the USART. i looked at the STK500 manual and it tells you that the default config (software clock) max frequency is 3.6864MHz so hardware wise the frequency should be ok. How can i set it in AVRStudio? thanks.

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

In the programming dialog under the "HW Settings" tab you can adjust the frequency. Of course, you also have to set the fuses of the mega16 to actually use that frequency.

Regards,
Steve A.

The Board helps those that help themselves.

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

Note that the STK500 does not use a built-in CRYSTAL driven oscillator, so the clock freqs will not be exact (perhaps 1/2 percent or so). I noticed this once when I was trying to generate some exact waves & had happened to hook up my freq counter. So if you need 4-5 digits of accuracy, or better, you need to supply your own crystal or oscillator.

Hoyt

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

Quote:

Note that the STK500 does not use a built-in CRYSTAL driven oscillator, so the clock freqs will not be exact (perhaps 1/2 percent or so).

Well, that is true, and it isn't (AFAIK).

The STK500 onboard clock comes from (apparently) timer1 on the STK500's '8535 running in CTC mode. That chip >>is<< driven by a 7.3728MHz crystal, and any CTC output should be as close as that crystal and have no jitter.

However, if the frequency you observed was "off" but had no jitter or other anomalies, it could be because of the nature of the CTC square wave output. You get clk/2, clk/4, clk/6, etc. Let's look at clk/100 and the next step, clk/102. clk/100 is 73728Hz. clk/102 will come out to 72282Hz. The frequency should be exactly those, but you cannot get, say, 73000Hz exactly but rather will end up with one of the numbers that I listed.

The readback in AVRStudio should give you the resultant number.

Lee

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

ok here is what i have done so far.. i am testing the code that Dean has in his tutorial..here is my code:

#include  

#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((3686400 / (USART_BAUDRATE * 16UL))) - 1)

int main (void)
{
   char ReceivedByte;

   UCSRB |= (1 << RXEN) | (1 << TXEN);   // Turn on the transmission and reception circuitry
   UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes

   UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
   UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register

   for (;;) // Loop forever
   {
      while ((UCSRA & (1 << RXC)) == 0) {}; // Do nothing until data have been recieved and is ready to be read from UDR
      ReceivedByte = UDR; // Fetch the recieved byte value into the variable "ByteReceived"

      while ((UCSRA & (1 << UDRE)) == 0) {}; // Do nothing until UDR is ready for more data to be written to it
      UDR = ReceivedByte; // Echo back the received byte back to the computer
   }   
} 

i have used 3.6864MHz because that is an exact multiple of 1.8432MHz.

i have kept the jumper settings for OSCSEL and XTAL1 as the default settings. attached is my programming screen. what should i have as my frequency settings? also my hardware settings tab is disabled.

Attachment(s): 

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

ok got it i used 7372800 Hz as my frequency and selected Ext Osc 3.0M - 8.0M in my programming window with the jumper settings set to default i can echo all characters in hyperterminal at 9600 8N1 just fine. thanks for your help.