Menu

Clock Cycle (F_CPU)

Help
2012-05-04
2012-12-09
  • Brandon Bearden

    Brandon Bearden - 2012-05-04

    I have the ATMega2560 16AU. I have noticed that when I do taskDelayFromNow(2000); there is only a one second delay. I have defined F_CPU=16000000UL in the symbols of my compiler however, the delay is still half of what is should be. I know this code was written with 8MHz in mind, what can I do to properly configure the system for 16MHz?

    Brandon

     
  • De Vlaam

    De Vlaam - 2012-05-04

    Femto OS can run perfectly on 16MHz, You need to modify the file femtoos_ATmega2560.asm in the femtoos_devices directory. Change

    /* Physical parameters */
    #define devClockFrequency 8000000LL
    

    into

    /* Physical parameters */
    #define devClockFrequency 16000000LL
    

    I know this is not a very elegant solution. In the next version you will be able to set the frequency in the configuration file.

     
  • Brandon Bearden

    Brandon Bearden - 2012-05-04

    Hmm… I have changed this and done a clean rebuild. However, the delay's are still half as long as they should be.

    For example a taskDelayFromNow(2000); will delay for only 1 second.

     
  • De Vlaam

    De Vlaam - 2012-05-05

    Probably you are aware of this, but just to be certain: you know that the software can only scale down the frequency and that the maximum frequency the internal oscillator can run is 8MHz. So, in order to run at 16 MHz on the ATMega2560 you need an external crystal. And of course the external voltage must be sufficient. With the 16MHz crystal mounted and the proper fuses set (see manual) this device should run at 16MHz.

    Then make sure that (in the configuration)

    #define  cfgSysClockDivider                      1
    #define  cfgSysSubTicksPerFullTick               32
    #define  cfgSysSubTickDivider                    256
    

    and you should be ok.

    The tick frequency can be deduced from

    #define defTickFrequency              (devClockFrequency / cfgSysClockDivider / cfgSysSubTickDivider/ cfgSysSubTicksPerFullTick )
    

    In this case

    16000000/1/32/256=1953
    

    so that

    taskDelayFromNow(2000)
    

    will indeed take approximately 1 sec.

    Maybe i do not get the point … ?

     
  • Brandon Bearden

    Brandon Bearden - 2012-05-05

    Ahh okay, that makes a lot of sense. I was thinking that 2000 meant 2000 milliseconds == 2 seconds. Thank you clearing this up for me. (Also, this is the R3 version of this board and it is the 16 MHz chip with a 16MHz external crystal and I sure from the factory they have set it to run at 16MHz.)

    Thanks again!

    Brandon

     

Log in to post a comment.