This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Input Edge count mode not giving the expected results

Hi!

My frequency counter project is based on the wide-timer #3 input edge count mode. As a signal source I'm using a 6 MHz TCXO (± 25ppm). The signal is stable as I'm measuring it with a frequency counter instrument. I'm using the input edge count up mode with a 24 bit wide timer.

My application has an external time-gate input coming from TCXO RTC to provide a stable 1 Hz time gate. The external pin interrupt reads out the timer value and handles it over to a task which eventually sends it to the PC. The interrupt handler also zeroes the timer value register.

My problem is that I'm not getting consequent values (± 1 edge) but variance like:

5999956
5999967
5999945
5999956
5999956
5999944
5999945
5999956
5999956
5999956
5999967
5999956
5999955
5999955
5999944
5999944
5999955
5999944
5999933
5999956
5999944
5999944
5999955
5999933

The instrument however, shows no variance in the frequency so probably my method has flaws. Below is the relevant code and any help would be great as I'm probably misinterpreting something here.


#ifndef DEFCAPTURE_TIMER_H_
#define DEFCAPTURE_TIMER_H_

#define CAPTURE_TIMER_PH			SYSCTL_PERIPH_WTIMER3
#define CAPTURE_TIMER_BASE			WTIMER3_BASE
#define CAPTURE_TIMERA_INT			INT_WTIMER3A
#define CAPTURE_TIMERB_INT			INT_WTIMER3B

/* Edges to count from oscillator (5V tolerant!!!) */
/* WT3CCP0 - PD2 -#63*/
/* WT3CCP1 - PD3 -#64*/

#define EXTEDGE_PH SYSCTL_PERIPH_GPIOD
#define EXTEDGE_PIN_BASE GPIO_PORTD_BASE

#define EXTEDGE_PINA GPIO_PIN_2
#define EXTEDGE_PINB GPIO_PIN_3

#define EXTEDGE_PINA_CONFIG	GPIO_PD2_WT3CCP0
#define EXTEDGE_PINB_CONFIG	GPIO_PD3_WT3CCP1

#endif /* DEFCAPTURE_TIMER_H_ */

/***/

void Init_Capture_Timer_Pin(void){

	/*
	 * Enable and configure Timer input capture pins
	 */
	SysCtlPeripheralEnable(EXTEDGE_PH);
	GPIOPinConfigure(EXTEDGE_PINA_CONFIG);
	GPIOPinTypeTimer(EXTEDGE_PIN_BASE,EXTEDGE_PINA);
}

void Init_Capture_Timer(void){

	/*
	 * Enable Capture Timer peripherial
	 */
	SysCtlPeripheralEnable(CAPTURE_TIMER_PH);

	/*
	 * Configure 24 bit capture timer
	 */
	TimerConfigure(CAPTURE_TIMER_BASE, TIMER_CFG_A_CAP_COUNT_UP);

	/*
	 * Capture on positive edges
	 */
	TimerControlEvent(CAPTURE_TIMER_BASE, TIMER_A, TIMER_EVENT_POS_EDGE);


	/*
	 * Load and Match registers
	 */
	TimerLoadSet(CAPTURE_TIMER_BASE, TIMER_A, 0xFFFFFFFF);
	TimerMatchSet(CAPTURE_TIMER_BASE, TIMER_A, 0x00);
	/*
	 * Setup the interrupts for the timer timeouts.
	 */
	//IntEnable(CAPTURE_TIMERA_INT);
	//TimerIntEnable(CAPTURE_TIMER_BASE,  TIMER_CAPA_MATCH);

}

void Enable_Capture_Timer(void){

	TimerEnable(CAPTURE_TIMER_BASE, TIMER_A);
}

/***/

void TimeGateIntHandler(void){


	ui32EventCount = TimerValueGet(CAPTURE_TIMER_BASE, TIMER_A);
	HWREG(CAPTURE_TIMER_BASE + TIMER_O_TAV) = 0;
	
	GPIOIntClear(TIMEGATE_PIN_BASE, TIMEGATE_PIN);
	Task.Bits.FRQDRDY = 1;
}
/***/

void Task_FRQDRDY(task_t *tp){

	/*
	 * Count UP
	 */
	Init_UARTPCMSG_Struct((uint8_t*) &UartCPU2PC);

	UartCPU2PC.data = ui32EventCount;
	UartCPU2PC.tmp_int = ReadRTCSingleReg(RTC_TEMP_MSB_INT);
	UartCPU2PC.tmp_frc = ReadRTCSingleReg(RTC_TEMP_LSB_FRAC);
	
	tp->Bits.FRQDRDY = 0;
	tp->Bits.CPU2PC = 1;
	if (UartCPU2PC.data>4500000 && UartCPU2PC.data < 10000000) BlinkLED(GREEN);
		else BlinkLED(BLUE);
}

 

 

  • Greg

    What is the TIVA device you are using, what is the system frequency, information like that would be useful

    Also as you mentioned you are using the GPIO Interrupt to count the edges in the time frame of 1 sec. Any delay in the execution of the ISR would also impact the read out value, now wouldn't it.

    Amit

  • I modified the external timegate interrupt handler like this:

    void TimeGateIntHandler(void){
    
    	uint32_t status;
    
    	//ui32EventCount = TimerValueGet(CAPTURE_TIMER_BASE, TIMER_A);
    	ui32EventCount = WTIMER3_TAR_R;
    	//HWREG(CAPTURE_TIMER_BASE + TIMER_O_TAV) = 0;
    	WTIMER3_TAV_R = 0;
    	GPIOIntClear(TIMEGATE_PIN_BASE, TIMEGATE_PIN);
    	Task.Bits.FRQDRDY = 1;
    }

    And my frequency readout has a random ~± 10Hz deviation (screenshot):


    Looks like a random interrupt latency?

    EDIT: Signal source had been changed to an internal, PWM generated 5 MHz signal.

  • Hi Amit!

    Thank you for dropping by. I'm using the TIVA-C Launchpad at 50 MHz system clock. I'm using the GPIO interrupt just for the 1 sec time gate - for edge counting purposes I'm using the WTimer3 input edge counting UP function.

  • I changed the time-gate source from external RTC to an internally generated 1 sec one and now the values are fine. It seems that the RTC chip's 1 Hz square wave output pin was causing the trouble, more investigation is needed. From this point  the issue is not TIVA related anymore so I'd close the topic.

  • That is good to know that external 1 sec trigger was the source. You can use a Periodic Timer to count 1 sec worth of count and reduce a external GPIO Interrupt