ATSAM4E16E TC_Handler problem

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

Hi all.
I write a code without ASF. I succesfuly lanched TC3 in simply wave mode with RC top value with CV reset, on which is Interrupt generated.

 

I want to do this when it come:

 

void TC3_Handler(void){
    if(((PIOA->PIO_ODSR)&((0x1)<<30))!=0){
        PIOA->PIO_CODR = ((0x1u) << 30);
    }else{
        PIOA->PIO_SODR = ((0x1u) << 30);    
        }
    return;
}

 

But when interrupt came, it jump to Dummy_Handler.....

 

in Interrupt Program Status Register (IPSR) is value 0x28... which may be TC3_Handler

 

please help I dont have much exps with SAMs only AVRs

Atmel-ICE
Atmel Studio 7.0

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

Problem its more "dificult" then I thinked.
 

 

Second signal is pin TIOB3 which is switched when RC compare of TC3 come, but the first signal may be the same Interruption in the same moment...

 

Every pulse is running this handler.

 

void Dummy_Handler(void)
{
    if(NVIC_GetActive(TC3_IRQn)){
        //if(k==0){
        PIOA->PIO_SODR = ((0x1u) << 30);
        k=1;
    //}else{
        PIOA->PIO_CODR = ((0x1u) << 30);
        k=0;    
        //}
        }
}

 

It dont make TC3_Handler but this :( could anyone help?

Why that interruption came so offen?

 

Here are necesary parts of code:

 

void PinInit(void){
    PIOA->PIO_OER = 0xE03F0000;
    PIOA->PIO_CODR = 0xE03F0000;
    PIOC->PIO_WPMR = 0x50494F00;
    PIOB->PIO_PDR = 0x0C;
    PIOB->PIO_ABCDSR[0] = 0x0C;
    PIOB->PIO_ABCDSR[1] = 0x0C;
    PIOC->PIO_PDR = 0x0D000000;
    PIOC->PIO_ABCDSR[0] = 0x0D000000;
    PIOC->PIO_ABCDSR[1] = 0x0C000000;
    PIOC->PIO_WPMR = 0x50494F01;
    return;
}

 

void TimerInit(void){
    REG_TC1_IER0 = 0x10u;
    REG_TC1_WPMR = 0x54494D00;
    REG_TC1_RC0 = 0x00FF;
    REG_TC1_CMR0 = 0x0C00C400;
    REG_TC1_WPMR |= 0x54494D01;
    PMC->PMC_PCER0 = ((0x1u)<<24);
    return;
}

 

int main(void)
{
    SystemInit();
    PinInit();
    TimerInit();

    NVIC_DisableIRQ(TC3_IRQn);
    NVIC_ClearPendingIRQ(TC3_IRQn);
    NVIC_SetPriority(TC3_IRQn, 10);
    NVIC_EnableIRQ(TC3_IRQn);
    REG_TC1_CCR0 = 0x5;  // launch of TC3
    
    while (1)
    {
       
    }
}

Atmel-ICE
Atmel Studio 7.0

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

You configure TC1, you have to use TC1_Handler

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

No .. Becouse there are m modules TC0 TC1 and TC2 and everyone is divided to 3 counters and handlers are TC0_Handler to TC8_Handler ... :)

Atmel-ICE
Atmel Studio 7.0

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

You need to read the status register

void TC3_Handler(void)
{
  status = REG_TC1_SR0;
  if (k == 0)
  {
    PIOA->PIO_SODR = ((0x1u) << 30);
    k = 1;
  }
  else
  {
    PIOA->PIO_CODR = ((0x1u) << 30);
    k = 0;
  }
}

Channel 4 is TIOB3

Channel 1 is PA30

Instrument screen