How to clear TC INTFLAG reg ? (Solved)

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

Hi

 

I am trying to use CC0 and CC1 with different values in order to toggle two GPIOs delayed from each other.

 

The problem i encounter is that everytime the interrupt handler is called and i read the INTFLAG register there , the MC0 and MC1 are always set , which can not be. They can not be set at the same time.

 

Then i try to clear those two flags by reading the CC0 and CC1 register in order to clear the INTFLAG register but nothing happens here as well.

 

 

Here is the interrupt handler code , what am i doing wrong ?

 

void TC1_Handler()
{
	int int_fl_var ,cc_var;

	int_fl_var = TC1->COUNT16.INTFLAG.reg;       // reading INTFLAG register before clearing attempt   returns 0x38
        cc_var = TC1->COUNT16.CC[0].reg;
	cc_var = TC1->COUNT16.CC[1].reg;
	int_fl_var = TC1->COUNT16.INTFLAG.reg;       // reading INTFLAG register after clearing attempt    returns 0x38

        if((int_fl_var & TC_INTFLAG_MC0) == TC_INTFLAG_MC0)
	{
		tgl_pin(0 ,4);
		tgl_pin(0 ,4);
	}	

	if((int_fl_var & TC_INTFLAG_MC1) == TC_INTFLAG_MC1)
	{
		tgl_pin(0 ,5);
		tgl_pin(0 ,5);
	}

}

 

UPDATE :

 

Nevermind. i found my mistake. somehow i looked at the wrong place in the tc.h file.

What i wrote code wise above is completely wrong.

 

if anybody is interested this is the right code...

 

 

void TC1_Handler()
{
	int int_fl_var ,int_fl_var2;
	
	int_fl_var = TC1->COUNT16.INTFLAG.reg;          // read INTFLAG register before clearing MC0 and MC1
	TC1->COUNT16.INTFLAG.reg |= TC_INTFLAG_MC0;     // clear MC0
	TC1->COUNT16.INTFLAG.reg |= TC_INTFLAG_MC1;     // clear MC1
	int_fl_var2 = TC1->COUNT16.INTFLAG.reg;         // read INFLAG register again to check its value in debugger
	
	
	if((int_fl_var & TC_INTFLAG_MC0) == TC_INTFLAG_MC0)
	{
		tgl_pin(0 ,4);
		__delay_ms(50);
		tgl_pin(0 ,4);
	}	
	
	if((int_fl_var & TC_INTFLAG_MC1) == TC_INTFLAG_MC1)
	{
		tgl_pin(0 ,5);
		__delay_ms(50);
		tgl_pin(0 ,5);
	}
	
}

 

 

 

 

 

Last Edited: Mon. Apr 15, 2019 - 02:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You probably don’t want to do |= to clear the bits. Just use =.

Also doing == TC_INTFLAG_MCx is superfluous. The result of the & will be true or false, no need to test for equality.