Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

alt_timestamp() question

Hi!

I am just wondering if my understanding of the alt_timestamp is totally wrong...

My oszillator clock is 50MHz which i can see in the sopc builder and which has never changed.

I configured a 32bit/1millisec interval timer in the sopc builder (i named it "TIMER_MSEC") for my nios ii and selected it to the timestamp timer in the BSP editor.

Here are the settings:# define ALT_MODULE_CLASS_Timer_Msec altera_avalon_timer# define TIMER_MSEC_ALWAYS_RUN 1# define TIMER_MSEC_BASE 0x0# define TIMER_MSEC_COUNTER_SIZE 32# define TIMER_MSEC_FIXED_PERIOD 0# define TIMER_MSEC_FREQ 50000000u# define TIMER_MSEC_IRQ 0# define TIMER_MSEC_IRQ_INTERRUPT_CONTROLLER_ID 0# define TIMER_MSEC_LOAD_VALUE 49999ULL# define TIMER_MSEC_MULT 0.0010# define TIMER_MSEC_NAME "/dev/Timer_Msec"# define TIMER_MSEC_PERIOD 1# define TIMER_MSEC_PERIOD_UNITS "ms"# define TIMER_MSEC_RESET_OUTPUT 0# define TIMER_MSEC_SNAPSHOT 1# define TIMER_MSEC_SPAN 32# define TIMER_MSEC_TICKS_PER_SEC 1000u# define TIMER_MSEC_TIMEOUT_PULSE_OUTPUT 0# define TIMER_MSEC_TYPE "altera_avalon_timer"

# define ALT_MAX_FD 4# define ALT_SYS_CLK none# define ALT_TIMESTAMP_CLK TIMER_MSEC

At program start i use alt_timestamp_start() once.

Afterwards i do multiple read outs of alt_timestamp().

Expected behaviour:

I though the value alt_timestamp() should increase every millisec by one.

That means i should reach the limits of the 32bit timer after 49 days.

Observed behaviour:

The value of alt_timestamp() reaches the limits of 32bit after approximately 90 seconds.

Do anybody have an explanation why alt_timestamp() is so fast?

Is my understanding of the interval timer totally wrong?

What perhaps is the best way to implement a 32bit millisec clock in the nios (i would like to have a clock that can be accessed like this in code: t = GetMillisecClock())?

Regards

FredFlintstone

13 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    ... and make the values accessible as an Avalon MM slave.

    I'm a software engineer, I don't write vhdl :-)

    Actually I'm playing with some custom instructions at the moment.

    The combinatorial crc_step() function seems to work fine.

    Now trying to use a single instruction for bwap_32(), bwap_16() and some other transforms using the 'cB' field to select the transform.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Ok, the task is still to get some function like GetMillisecClock() working.

    Perhaps assigning the created interval timer to the system clock timer in the BSP will do the trick (instead of assigning it to the timestamp timer).

    I am not really sure what kind of functions do need the system clock timer. Perhaps somebody can enlighten me?

    I even stumbled over a function called alt_nticks(). Maybe this could work...

    At the moment it simply returns

    1 if alt_sys_init() was not called

    and

    0 if alt_sys_init() was called.

    (From some Altera pdf: It returns zero if there is no system

    clock available.)

    Would alt_nticks() work as a GetMillisecClock()?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Ok, now it works.

    I recreated the interval timer as in the sopc builder as 32bit/1millisec "full featured" and assigned it as system timer in the BSP editor.

    Now the function alt_nticks() returns the number of elapsed system clock ticks since reset.

    That is all i wanted...