TC2 won't start

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

I am trying to generate 200us interrupt using TC2 channel 0 on the SAM4E-EK development board. I loaded a simple ASF project "GETTING-STARTED1" that used TC0 to toggle an LED on the board and it works fine. I changed all TC0 references to TC2 and the timer does not start. I have also tried using TC1 and it does not work either.  configure_tc() happens after the sysclk_int() and board_init() are called. With TC0 after pmc_enableperiph_clk() is called the TC_SR0 register has MTIOB, MTIOA, RXBUFF and ENDRX bits are enabled. THese bits do not enable when trying to use TC1 or TC2. the attached code show TC1 and there are no modification to the SAM4e-EK board. I am clearly missing something simple but I can't find it. Thanks Larry

static void configure_tc(void)
{
	uint32_t ul_div;
	uint32_t ul_tcclks;
	uint32_t ul_sysclk = sysclk_get_cpu_hz();

	/* Configure PMC */
	pmc_enable_periph_clk(ID_TC1);
#if SAMG55
	/* Enable PCK output */
	pmc_disable_pck(PMC_PCK_3);
	pmc_switch_pck_to_sclk(PMC_PCK_3, PMC_PCK_PRES(0));
	pmc_enable_pck(PMC_PCK_3);
#endif

	/** Configure TC for a 4Hz frequency and trigger on RC compare. */
	tc_find_mck_divisor(5125, ul_sysclk, &ul_div, &ul_tcclks, ul_sysclk);
	tc_init(TC1, 0, /*ul_tcclks*/TC_CMR_TCCLKS_TIMER_CLOCK1 | TC_CMR_CPCTRG);
	tc_write_rc(TC1, 0, (ul_sysclk / ul_div) / 5125);

	/* Configure and enable interrupt on RC compare */
	NVIC_EnableIRQ((IRQn_Type) ID_TC1);
	tc_enable_interrupt(TC1, 0, TC_IER_CPCS);

#ifdef LED1_GPIO
	/** Start the counter if LED1 is enabled. */
	if (g_b_led1_active) {
		tc_start(TC1, 0);
	}
#else
	tc_start(TC1, 0);
#endif
}

 

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

I'm having the exact same problem.  But I found an answer here in this post

 

For the first channel of peripheral TC1 use,

 

    pmc_enable_periph_clk(ID_TC3);                    // refer to the channel number (0 - 9), not the peripheral instance
 

 

For the first channel of peripheral TC2 use,

 

    pmc_enable_periph_clk(ID_TC6);                    // refer to the channel number (0 - 9), not the peripheral instance
 

 

Mary

Last Edited: Wed. Mar 16, 2022 - 06:48 PM