Configure Timer 1 for overflow and generate interrupt in SAME54P20A Microcontroller

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

Hello All, 

 

I have one function Timer_Interrupt_Init() in which I have set following registers and configure this registers to overflow timer 1. The code is as follows:- 

void Timer_Interrupt_Init()
{

REG_GCLK_CTRLA = GCLK_GENCTRL_GENEN | GCLK_PCHCTRL_GEN_GCLK0 | GCLK_PCHCTRL_CHEN;
	REG_MCLK_APBAMASK |= MCLK_APBAMASK_TC1;

	REG_TC1_CTRLA |=TC_CTRLA_PRESCALER_DIV64;

	REG_TC1_CTRLA |= TC_CTRLA_ENABLE;
	REG_TC1_CTRLBSET |= TC_CTRLBSET_CMD_NONE;
	REG_TC1_COUNT16_COUNT = 0xFF45;
	REG_TC1_COUNT16_CCBUF0 = 0x0000;
	REG_TC1_COUNT16_CCBUF1= 0x0000;

	REG_TC1_CTRLA |= TC_CTRLA_PRESCSYNC_RESYNC;

	NVIC_EnableIRQ(TC1_IRQn);

// Timer/Counter 1 Interrupt(s) initialization
	REG_TC1_INTENSET = TC_INTENSET_OVF;  /*0x01;*/
}

I am calling this function in main() and after calling this function from main, insert the while(1); loop  just below  Timer_Interrupt_Init() function, the value gets updated to 65349 (goes red) and after that it's value doesn't get updated. 

 

Please, help me what i am doing wrong over here in the above code for configuration of timer 1. 

 

Thanks in advance.

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

TC1 has no clock, you need to assign one in GCLK->PCHCTRL[TC1_GCLK_ID] (same as REG_GCLK_PCHCTRL9).

/Lars

 

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

Hi Lajon,

 

Tried adding this line to my code above but with no success:- 

 

GCLK->PCHCTRL[TC1_GCLK_ID].reg |= GCLK_PCHCTRL_GEN_GCLK9;

 

Please help. 

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

GCLK9 is not configured surly you should be using GCLK0. Are you trying this without reading the datasheet? What about

Bit 6 – CHEN Channel Enable This bit is used to enable and disable a Peripheral Channel.

/Lars

 

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

 Little confused over here. Does my code for Timer_Interrupt_init() above correct which i posted in the 1st comment, have I missed something  ??