[SAME70] TC with PCK6

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

Hi,

 

I'm trying to do a quite simple thing: Configure a timer (ID_TC1) and get an interrupt when RC is reached.

My code is this one:

 

pmc_enable_periph_clk(ID_TC1);

tc_find_mck_divisor(desired_freq, ul_sysclk, &ul_div, &ul_tc_clks, ul_sysclk);
tc_init(TC0, 1, ul_tc_clks | TC_CMR_WAVSEL_UP_RC | TC_CMR_WAVE);
tc_write_rc(TC0, 1, (ul_sysclk / ul_div) / desired_freq);

NVIC_SetPriority(ID_TC1, IRQ_PRIOR_ENCODER);
NVIC_EnableIRQ((IRQn_Type)ID_TC1);
tc_enable_interrupt(TC0, 1, TC_IER_CPCS);
tc_start(TC0, 1);

 

 

tc_find_mck_divisor find correct values : ul_tc_clks = 0, ul_div = 2.

 

TCCLKS = 0 means timer is clocked with PCK6, which is at 150MHz.

 

The problem is that it seems the timer never starts.

If I change the tc_init to:

tc_init(TC0, 1, 1 | TC_CMR_WAVSEL_UP_RC | TC_CMR_WAVE);

 

Here I use MCK/8 as timer clock, then timer starts and my TC1_Handler is correctly called.

 

Any idea what I'm doing wrong with this so simple timer configuration?

 

This topic has a solution.
Last Edited: Tue. May 10, 2016 - 11:19 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmm I think I found the solution. I had to enable PCK6 myself (but PMC_PCK_6 is not defined in pmc.h. Only defined for SAMG55). I was inspired by the code in mcan_init which uses PMC_PCK_5. I added that (after defining PMC_PCK_6 to 6):

pmc_disable_pck(PMC_PCK_6);
pmc_switch_pck_to_mck(PMC_PCK_6, PMC_PCK_PRES(1));
pmc_enable_pck(PMC_PCK_6);