Forum Discussion

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

Interval Timer Problem

Hi,

I got a system with an interval timer. Now I want to use it to to count how long the time is between two positiv flanks. But the counter won't start.

My code:

  int count_timeH=0;
    int count_timeL=0;
    IOWR_ALTERA_AVALON_TIMER_PERIODH(SYS_CLK_TIMER_BASE,0x0);
    IOWR_ALTERA_AVALON_TIMER_PERIODL(SYS_CLK_TIMER_BASE,0x0);
    //start the counter
    IOWR_ALTERA_AVALON_TIMER_CONTROL(SYS_CLK_TIMER_BASE,0x04);
    printf("Control : %x\n",IORD_ALTERA_AVALON_TIMER_CONTROL(SYS_CLK_TIMER_BASE));
    printf("Status: %x\n", IORD_ALTERA_AVALON_TIMER_STATUS(SYS_CLK_TIMER_BASE));
    count_timeL= IORD_ALTERA_AVALON_TIMER_SNAPL(SYS_CLK_TIMER_BASE);
    printf("SnapL : %d\n", count_timeL);
    count_timeH= IORD_ALTERA_AVALON_TIMER_SNAPH(SYS_CLK_TIMER_BASE);
    printf("SnapH : %d\n", count_timeH);
    //wait till the FAD gives back the right frequency
    int j;
    for ( j = 0; j < 2; ++j) {
        push_The_Button(FAD_CLOCK_BASE);
        printf("Flanke Nummer %d \n", j);
    }
    //stop the counter
    IOWR_ALTERA_AVALON_TIMER_CONTROL(SYS_CLK_TIMER_BASE,0x08);
    printf("Status: %x\n", IORD_ALTERA_AVALON_TIMER_STATUS(SYS_CLK_TIMER_BASE));
    count_timeL= IORD_ALTERA_AVALON_TIMER_SNAPL(SYS_CLK_TIMER_BASE);
    printf("SnapL : %d\n", count_timeL);
    count_timeH= IORD_ALTERA_AVALON_TIMER_SNAPH(SYS_CLK_TIMER_BASE);
    printf("SnapH : %d\n", count_timeH);
And the registers contents are:

Control : 0
Status: 1
SnapL : 9216
SnapH : 3286019
Knopf drücken!
Flanke Nummer 0 
Knopf drücken!
Flanke Nummer 1 
Status: 0
SnapL : 9216
SnapH : 3154947
So how you can see in the code I just start counting but the control register still is "0". Why the content doesn't cange?

And from which registers I can read my countsize?

Thanks in advance for your help!

13 Replies