Forum Discussion
Altera_Forum
Honored Contributor
14 years agoInterval 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...
Altera_Forum
Honored Contributor
14 years agoHi cris,
thanks for the help, now it works! I just setup the timeout period to "1sec" and changed a little bit of my code: --- Quote Start --- double count_The_Frequency() { double total_time_steps=0; double calculated_time=0; double calculated_frequency=0; alt_u32 count_step_1=0x0; alt_u32 count_step_2=0x0; int a=0; //start address of the counter IOWR_ALTERA_AVALON_TIMER_PERIODH(SYS_CLK_TIMER_BASE,0xFFFF); IOWR_ALTERA_AVALON_TIMER_PERIODL(SYS_CLK_TIMER_BASE,0xFFFF); IOWR_ALTERA_AVALON_TIMER_CONTROL(SYS_CLK_TIMER_BASE,ALTERA_AVALON_TIMER_CONTROL_STOP_MSK); //total_time is in seconds but is measured in ms //the range depends on the frequency you want to have //while((total_time<=10) & (total_time>=5)){ //while((total_time<=0.001) & (total_time>=0.00065)){ //by writing to the snapregister you get the data from the counter IOWR_ALTERA_AVALON_TIMER_SNAPL(SYS_CLK_TIMER_BASE,0x1); IOWR_ALTERA_AVALON_TIMER_SNAPH(SYS_CLK_TIMER_BASE,0x2); //start the counter IOWR_ALTERA_AVALON_TIMER_CONTROL(SYS_CLK_TIMER_BASE,0x06); //wait till the FAD gives back the right frequency int j; for ( j = 0; j < 2; ++j) { push_The_Button(FAD_CLOCK_BASE); a=a+1; IOWR_ALTERA_AVALON_TIMER_SNAPL(SYS_CLK_TIMER_BASE,0x1); if(a==1){ count_step_1 = IORD_ALTERA_AVALON_TIMER_SNAPH(SYS_CLK_TIMER_BASE)<<16; count_step_1 =count_step_1|(IORD_ALTERA_AVALON_TIMER_SNAPL(SYS_CLK_TIMER_BASE)); } if(a==2){ count_step_2 = IORD_ALTERA_AVALON_TIMER_SNAPH(SYS_CLK_TIMER_BASE)<<16; count_step_2 =count_step_2|(IORD_ALTERA_AVALON_TIMER_SNAPL(SYS_CLK_TIMER_BASE)); } } //printf("SnapH : %e\n", (double)IORD_ALTERA_AVALON_TIMER_SNAPH(SYS_CLK_TIMER_BASE)); //stop the counter IOWR_ALTERA_AVALON_TIMER_CONTROL(SYS_CLK_TIMER_BASE,0x8); //printf("1; %x\n", count_step_1); // printf("2: %x \n", count_step_2); total_time_steps= (count_step_1-count_step_2); calculated_time= total_time_steps/(50000000); calculated_frequency=1/calculated_time; // printf("Frequenz: %e\n", calculated_frequency); return calculated_frequency; } --- Quote End ---