Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

clockspeed- the meaning of #ifndef F_CPU, #define F_CPU

Status
Not open for further replies.

Nahian

Member level 3
Joined
Aug 1, 2007
Messages
64
Helped
6
Reputation
12
Reaction score
0
Trophy points
1,286
Activity points
1,604
clockspeed

hello,
what is the meaning when we write

#ifndef F_CPU
#define F_CPU 16000000UL
#endif

at begining of a program, when my µ controller is running on external or internal RC crystal of different clockspeed. Say Atmega32 running on internal 1 mhz... no fuse bit has been changed. whats the effect of writing this?[/b]
 

nandhu015

Advanced Member level 5
Joined
Feb 11, 2006
Messages
1,965
Helped
300
Reputation
600
Reaction score
224
Trophy points
1,353
Location
India
Activity points
9,825
clockspeed

#define F_CPU is for defining clock speed of the processor.

While your micro is running at 1MHz and you are defining 16MHz make the programme run 16times slower.

Nandhu
 

    Nahian

    points: 2
    Helpful Answer Positive Rating

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,699
Helped
4,804
Reputation
9,625
Reaction score
4,585
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
125,225
Re: clockspeed

Should add that this is a program directive, not something to set fuses.

The probable reason it is being used is because somewhere in the program, there is a calculation which is dependent on the processor clock speed. This might be a delay routine or possibly setting timer values. Without it, the program would have no knowledge of the speed you are using in your hardware.

The 'UL' at the end is just to signify the value is an 'Unsigned Long' type.

Brian.
 

    Nahian

    points: 2
    Helpful Answer Positive Rating

Nahian

Member level 3
Joined
Aug 1, 2007
Messages
64
Helped
6
Reputation
12
Reaction score
0
Trophy points
1,286
Activity points
1,604
Re: clockspeed

thnx to both of u. I have just too many confusions about clockspeed. ya i know its not a matter of fusebit. i just wanna ensure u that me using internal oscillator of mega32.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top