[Help] Problem using USBasp to program ATMega 328P

Go To Last Post
53 posts / 0 new

Pages

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

david.prentice wrote:

It is quite a good habit to get into.  i.e. including power.h in every program

Then you can prescale your clock speed safely e.g. use clock_div_1 when you want to run at full speed.

 

It also works with virgin chips.   They come out of the factory with 8MHz RC but the fuse is set for CLKDIV8.

 

Using clock_div_1 will ensure that you run at 8MHz whether CLKDIV8 fuse is set or not.

 

David.

 

Anyways a little bit out of topic but if I don't ask I keep thinking because I keep imagining , so my question are:

1. what is the meaning of 1MHz statement in the microcontroller? because 1MHz as far as I know it as frequency but I don't know which frequency, is it a microcontroller frequency? I want to find out but I couldn't find the answer in the datasheet

2.  what is the meaning of this statement? where do I could find the information of this function?

 clock_prescale_set(clock_div_16);  //run your 16MHz hardware at 1MHz

3. and then we frequently uses _delay_ms function. if for example "_delay_ms(1000);" does it mean that the delay always one second regarding any frequency the microcontroller works? 

 

I hope you could clarify my questions and give me good sources to read if you don't mind

 

I know I've been asking a lot of questions but really it always bother me because I don't know the meaning of it

Embedded Lover and would like to pursue my future in embedded system

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

You can see the documentation for avr/power.h on microchip webdoc

 

Chips come out of the factory with 8MHz RC and CLKDIV8 fuse.   So they run at 1MHz.   That is why tutorials always use 1MHz.

You can change the division ratio in software.

 

Older chips e.g. ATmega8 had a 1MHz RC.   You can only change the speed by changing fuses.

 

F_CPU does not change frequency.    You tell the Compiler the frequency.    Then libraries can adjust delays to match.

 

e.g. you can read the value printed on a crystal.   Declare F_CPU with the crystal value divided by any prescale.

e.g. if you use the 8MHz RC you can declare F_CPU as (8000000uL / 8) if you are dividing by 8

 

David.

Pages