Count external events using TIOAx inputs fails

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to use the timer module to count pulses on a SAME70 board. For this I configured inputs TCLKx and TIOAx according to the E70 manual.

I found out that everything works as expected if TCLKx pins are used for counting. Pulses on TIOAx are ignored although I can monitor the state of this pin.

I found some former posts regarding this topic but nobody has published a solution so far.

 

According to this diagram it should be possible to use TIOAx pins for counting. I highlighted my configuration:

 

This is my code snippet tested on the SAME70-XPLD board:

 

	#define PIN_TC0_TCLK0        (PIO_PA4_IDX)
	#define PIN_TC0_TCLK1        (PIO_PA28_IDX)
	#define PIN_TC0_TCLK2        (PIO_PA29_IDX)
	#define PIN_TC0_TIOA0        (PIO_PA0_IDX)
	#define PIN_TC0_TIOA1        (PIO_PA15_IDX)
	#define PIN_TC0_TIOA2        (PIO_PA26_IDX)

	sysclk_enable_peripheral_clock(ID_PIOA);
	sysclk_enable_peripheral_clock(ID_TC0);
	sysclk_enable_peripheral_clock(ID_TC1);
	sysclk_enable_peripheral_clock(ID_TC2);

	ioport_set_pin_mode(PIN_TC0_TCLK0, IOPORT_MODE_MUX_B);	// input pin TCLK0 for TC0-C0
	ioport_set_pin_mode(PIN_TC0_TCLK1, IOPORT_MODE_MUX_B);	// input pin TCLK1 for TC0-C1
	ioport_set_pin_mode(PIN_TC0_TCLK2, IOPORT_MODE_MUX_B);	// input pin TCLK2 for TC0-C2
	ioport_set_pin_mode(PIN_TC0_TIOA2, IOPORT_MODE_MUX_B);	// input pin TIOA2 for TC0-C1
	ioport_set_pin_mode(PIN_TC0_TIOA0, IOPORT_MODE_MUX_B);	// input pin TIOA0 for TC0-C1

	tc_init(TC0, 0,  TC_CMR_TCCLKS_XC0 );	// TC0C0: Clock selected: XC0
	tc_init(TC0, 1,  TC_CMR_TCCLKS_XC1 );	// TC0C1: Clock selected: XC1
	tc_init(TC0, 2,  TC_CMR_TCCLKS_XC2 );	// TC0C2: Clock selected: XC2

	tc_set_writeprotect(TC0, 0);		// disable write protection

	// The function tc_init() must be called prior to this one.
	tc_set_block_mode(TC0,	TC_BMR_TC0XC0S_TCLK0 |		// TC0C0: Signal connected to XC0: TCLK0
				TC_BMR_TC1XC1S_TIOA2 |		// TC0C1: Signal connected to XC1: TIOA2
//				TC_BMR_TC1XC1S_TCLK1 |		// TC0C1: Signal connected to XC1: TIOA0
				TC_BMR_TC2XC2S_TCLK2 );		// TC0C2: Signal connected to XC2: TCLK2


	tc_start(TC0, 0);
	tc_start(TC0, 1);
	tc_start(TC0, 2);
	
	uint32_t ulC0, ulC1, ulC2, ulPinA2;
	while(1)
	{
		ulC0 = tc_read_cv(TC0, 0);
		ulC1 = tc_read_cv(TC0, 1);
		ulC2 = tc_read_cv(TC0, 2);

		ulPinA2 = ioport_get_pin_level(PIN_TC0_TIOA2);

		printf("Counter: %ld, %ld, %ld\n", ulC0, ulC1, ulC2);
		printf("Pin A2: %ld\n", ulPinA2);
		delay_ms(1000);
	}

I see TIOA2 changing its state but the counter of TC0-C1 is not incremented like this:

 

Counter: 13397, 0, 13397
Pin A2: 1
Counter: 13407, 0, 13407
Pin A2: 0

 

Any help is appreciated.

 

 

SAME newbie

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

if i'm not mistaken ... datasheet Atmel-11296D-ATARM-SAM E70-Datasheet_19-Jan-16 chapter 48.6.13

 

"An external event can be programmed to be detected on one of the clock sources (XC0, XC1, XC2) or TIOB. The external event selected can then be used as a trigger."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yep. This is also mentioned in chapter 48.6.6. Trigger:

 

"A trigger resets the counter and starts the counter clock. [...]

The channel can also be configured to have an external trigger. In Capture mode, the external trigger signal can be
selected between TIOA and TIOB. In Waveform mode, an external event can be programmed on one of the
following signals: TIOB, XC0, XC1 or XC2. This external event can then be programmed to perform a trigger by
setting bit ENETRG in the TC_CMR."

 

I succeeded to configure and use the TIOA pins to reset the counter but I failed to use TIOAs as a clock input.

 

Regarding the schematic above in my first post it might look like the TIOA pins can be configured as inputs and used as counter clocks same way as the "true" TCLK  inputs. 

Regarding the schematic below (figure 48-2) I think the "TIOA" signals shown in this schematic are only internal signals if BMR register is configured (what is called clock chaining?).

Then these "TIOA" signals can only used as feedback signals from the module output back to the module input and do not have a connection to the TIOA pins (PIO) I guess. Does this make sense ?

 

SAME newbie

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi! I have the same problem. The counter is not incremented selecting TI0A1 as clock input pin.

Did you solve this problem?

Thank you.

Last Edited: Wed. Feb 20, 2019 - 01:36 PM