delay_ms from asf on evk1101

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

Hi - I am trying to use the delay_ms function, but seem to be having a few problems;

I am using an EVK1101 board.

I have added delay routines from the ASF under services and hit apply. (I can see delay.h in the solution explorer under the delay folder)

I added delay_init(); after the main start.

I tried delay_ms(2000), but it doesn't seem to delay.

 

I got it to work by going to the delay.h file and edited:

#ifndef F_CPU
#       define F_CPU sysclk_get_cpu_hz()
#endif

to:

#ifndef F_CPU
#       define F_CPU 12000000
#endif

so it's as though sysclk_get_cpu_hz is not getting the value of the 12mhz xtal. 

 

In the conf_clock.h file I see:

#ifndef CONF_CLOCK_H_INCLUDED
#define CONF_CLOCK_H_INCLUDED

//#define CONFIG_SYSCLK_INIT_CPUMASK  (1 << SYSCLK_SYSTIMER)
//#define CONFIG_SYSCLK_INIT_PBAMASK  (1 << SYSCLK_USART0)
//#define CONFIG_SYSCLK_INIT_PBBMASK  (1 << SYSCLK_HMATRIX)
//#define CONFIG_SYSCLK_INIT_HSBMASK  (1 << SYSCLK_MDMA_HSB)

#define CONFIG_SYSCLK_SOURCE          SYSCLK_SRC_RCSYS
//#define CONFIG_SYSCLK_SOURCE        SYSCLK_SRC_OSC0
//#define CONFIG_SYSCLK_SOURCE        SYSCLK_SRC_PLL0

/* Fbus = Fsys / (2 ^ BUS_div) */
#define CONFIG_SYSCLK_CPU_DIV         0
#define CONFIG_SYSCLK_PBA_DIV         0
#define CONFIG_SYSCLK_PBB_DIV         0

 

Another point - elsewhere on the forum it was said you don't have to include delay.h at the top of the main file ??

I have to do this or else it doesn't see F_CPU and the delay routines.

What am I (obviously) doing wrong?

 I tried #include <asf.h> which doesn't give errors, but still doesn't work - which file to include?

I am new to the UC3, having worked a lot with Mega AVRs - What a learning curve! It's an ARMy of info!

 

thanks

Russell

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

It is probably 'not working' because what you think is the processor clock frequency is not what the processor is actually running at.
The default AVR32 clock is the RCOSC, (SYSCLK_SRC_RCSYS in ASF parlance), which is an internal 115 kHz clock.
With your manipulated F_CPU value of 12MHz you will wait a long time before delay_ms(2000) expires.


conf_clock.h defines some of the clock options and sysclk_init() then tries to make it happen.
It appears that you are using an external crystal (probably on OSC0) so you should do #define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_OSC0 in conf_clock.h
You specify the actual OSC0 frequency with a #define BOARD_OSC0_HZ 12000000 and that will then define the 'correct' value of F_CPU that the delay routines use.


The ASF wizard will update asf.h with the .h headers of the options/modules you have selected.
If you do not include asf.h then you will need to #include the .h files of the modules/services/etc that you are using from the ASF.

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

Hi - thanks. 

I changed the clock sources to:

//#define CONFIG_SYSCLK_SOURCE          SYSCLK_SRC_RCSYS
#define CONFIG_SYSCLK_SOURCE        SYSCLK_SRC_OSC0
//#define CONFIG_SYSCLK_SOURCE        SYSCLK_SRC_PLL0

Now the delay seems correctly slow enough.

Regards

Russell