Altera_Forum
Honored Contributor
20 years agoCYGNUM_HAL_RTC_CONSTANTS
Hi!
I am trying to use the RTC constants (in order to calculate time from ticks), and I've seen something strange with them. In the file altera\kits\nios2\components\ecos\ecos-2.0\packages\devs\sopc\altera_avalon_timer\v2_0\include\altera_avalon_timer.h there are the current definitions: # define ALT_SYS_CLK_PERIOD_MULT ((ALT_SYS_CLK_PERIOD_UNITS != ALT_AVALON_TIMER_PERIOD_UNITS_S) ? ((ALT_SYS_CLK_PERIOD_UNITS != ALT_AVALON_TIMER_PERIOD_UNITS_MS) ? ((ALT_SYS_CLK_PERIOD_UNITS != ALT_AVALON_TIMER_PERIOD_UNITS_US ) ? 1 : 1) : 1000) : 1000000) # define ALT_SYS_CLK_PERIOD_DIV ((ALT_SYS_CLK_PERIOD_UNITS == ALT_AVALON_TIMER_PERIOD_UNITS_NS ) ? 1000 : 1) /* * Having extracted the timer constants, use these to contruct the real time clock constants * required for eCos. */ # define CYGNUM_HAL_RTC_CONSTANTS (1)# define CYGNUM_HAL_RTC_NUMERATOR (1000000000)# define CYGNUM_HAL_RTC_DENOMINATOR (ALT_SYS_CLK_PERIOD * ALT_SYS_CLK_PERIOD_MULT / ALT_SYS_CLK_PERIOD_DIV) From the ecos documentation: "The NUMERATOR divided by the DENOMINATOR gives the number of nanoseconds per tick" If the NUMERATOR is 10^9 (fixed), the DENOMINATOR should be the ticks per second. that is, the frequency of the timer we are using. If we look at the denominator calculation, is ALT_SYS_CLK_PERIOD * ALT_SYS_CLK_PERIOD_MULT / ALT_SYS_CLK_PERIOD_DIV then, the frequency of a timer should be calculated from FREQUENCY_OF_THE_UNITS / CLOCK_PERIOD. For a 100 Hz timer, or 10 ms period, this would be 1000 ms / 10 = 100 Hz. If we now look at the calculation done in the altera file, it is ALT_SYS_CLK_PERIOD (10) * ALT_SYS_CLK_PERIOD_MULT (1000) = 10000, which I think is not correct. Also note than when we have millisecs as units, the ALT_SYS_CLK_PERIOD_MULT definition is correct, but I think is incorrect with all the other units. So... am I right? Or have I missed anything? Alex Bueno