programming CPU Clock in Atmel Studio

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

Hello,

I`ve bought a brand new Board . This has a 7.3728Mhz Crystal and a Atmega128A Core.

Code blinking a LED on PA0:

 

#define F_CPU 73728000UL
#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
DDRA=0xFF;
while(1)
{
	// cyle 2,168s:
	_delay_ms(50);
	PORTA=0x01;
	_delay_ms(50);
	PORTA=0;
}
	return(0);
}

This works, but the period is 2,168s. Too slow. Must be 0,1s (see Appendix from scope)

 

In Projekt > properties > device I see no Speed assiged:

 

 

Now Tools > Device progamming > fuses

 

 

 

How can I program the correct Speed?

I found a tip in the datasheet page 37:

 

Default Clock

Source

The device is shipped with CKSEL = “0001” and SUT = “10”. The default clock source setting is

therefore the Internal RC Oscillator with longest startup time. This default setting ensures that all

users can make their desired clock source setting using an In-System or Parallel Programmer.

 

 

I am afraid that I will make the chip useless

What should I do?

 

friendly regards

Ellen

 

Attachment(s): 

This topic has a solution.

Senior electrical engineer

Last Edited: Thu. Mar 21, 2019 - 02:31 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define F_CPU 73728000UL

I think you overshot by 1 zero.....

it is 73.728.000Hz

 

 

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

in fact there is a zero too much

Thank You.

 

But in result no Change. The period ist still 2,15s:

 

Update

Forgot to Transfer changes into device

 

It's now running

Senior electrical engineer

Last Edited: Thu. Mar 21, 2019 - 02:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

Now generally speaking you have to configure the clock in the right way/ read about this in the datasheet. #define F_CPU does not configure the clock...please read more about this here in this forum with a simple search.

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

The fuse settings look ok...I think.  Its been a long time since I used one of those AVRs as they are pretty old.

 

I just looked in a project I had open and I also add the following to my include list as S.O.P.:

 

#include <stdio.h>
#include <stdlib.h>
#include <avr/pgmspace.h>

 

 

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user