"TCC1 - Channel 2" can't work normally at SAMC21 pin PA08

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

Hi all,

 

I meet a problem , the SAMC21 - PA08 pin can't work normally when I configure it to "TCC1 - Channel 2".

The PA08 pin is also a NMI pin , I'm not sure if the NMI function is required to be disabled before I configuring PA08 to TCC function.

Below is my code , and PA08 did not change its status when the code start running.

 

#define LIGHT_PIN			PIN_PA08
#define LIGHT_MUX			MUX_PA08F_TCC1_WO2
#define LIGHT_MODULE			TCC1
#define LIGHT_CC_WO			2
#define LIGHT_CC_CHANNEL		TCC_MATCH_CAPTURE_CHANNEL_2

int main (void)
{
	struct tcc_module tcc_instance_lightn;
	struct tcc_config config_tcc;
	tcc_get_config_defaults(&config_tcc, LIGHT_MODULE);

	config_tcc.counter.clock_source = PERIPHERAL_CLOCK_SOURCE;
	config_tcc.counter.period = 1000;
	config_tcc.compare.wave_generation = TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM;

	// Tail Light
	config_tcc.compare.wave_polarity[LIGHT_CC_CHANNEL] = TCC_WAVE_POLARITY_0;
	config_tcc.compare.match[LIGHT_CC_CHANNEL] = 0;
	config_tcc.pins.enable_wave_out_pin[LIGHT_CC_WO] = true;
	config_tcc.pins.wave_out_pin[LIGHT_CC_WO] = LIGHT_PIN;
	config_tcc.pins.wave_out_pin_mux[LIGHT_CC_WO] = LIGHT_MUX;

	tcc_init(&tcc_instance_lightn, LIGHT_MODULE, &config_tcc);
	tcc_enable(&tcc_instance_lightn);

	while(1)
	{
		tcc_set_compare_value(&tcc_instance_lightn, LIGHT_CC_CHANNEL, 1000);   /// <========== seems no effect
		delay_ms(500);

		tcc_set_compare_value(&tcc_instance_lightn, LIGHT_CC_CHANNEL, 0);   /// <========== seems no effect
		delay_ms(500);
	}
}

Thanks.

This topic has a solution.
Last Edited: Thu. Oct 19, 2017 - 02:09 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you have a debugger/programmer you could look at the relevant TCC registers after the tcc_set_compare_value() calls, then compare them with the expected values using the datasheet. This is a bit complicated...

Best wishes, Jerry

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

I took the trouble to look at the datasheet for the SAMC21. You want to configure TCC1, but the SAMC21 only has one TCC, TCC0. The table 7-1 on p. 23 shows that you can only multiplex TCC0/WO[0] to pin PA08. 

The moral of the tale: ASF can't replace the datasheet, which one should always accompany programming

Jerry

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

jerryr wrote:
but the SAMC21 only has one TCC
Hmmm... I don't think so...

According to Atmel-42365J-SAM-C21_Datasheet_Complete-10/2016:

37.1. Overview
The device provides three instances of the Timer/Counter for Control applications (TCC) peripheral,
TCC[2:0].

David (aka frog_jr)

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

Hello frog_jr,

   Hmm... as well. I was reading the summary at http://ww1.microchip.com/downloa...

You're right, he complete data sheet which you mentioned says that it has three TCCs, and that you can multiplex TCC1/WO[2] to PA08

Very odd!

Jerry

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Try
#define LIGHT_CC_CHANNEL TCC_MATCH_CAPTURE_CHANNEL_0

The reason you have problems is that there is no compare channel 2 on TCC1 (TCC0 has 4, TCC1 and TCC2 only 2 each).
So why is there a WO2 you may ask, well one can remap the outputs using the output matrix in the "Waveform Extension". This has a default configuration that should apply in this case
 

Configuration 0x0 is the default configuration. The channel location is the default one, and channels
are distributed on outputs modulo the number of channels. Channel 0 is routed to the Output matrix
output OTMX[0], and Channel 1 to OTMX[1]. If there are more outputs than channels, then channel
0 is duplicated to the Output matrix output OTMX[CC_NUM], channel 1 to OTMX[CC_NUM+1] and
so on.

So channel 0 output should be duplicated on WO2.
Having written and pasted all that it looks like TCC1 does not actually have a waveform extension!
Still, could be the default output mapping applies so it's worth a try (if there is to be any use of  WO2 and WO3 for TCC1 it better work).
But you still have other options to get output on PA08, e.g., use TCC0 compare channel 0 and WO0.

/Lars

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

Thanks, Lajon. You are right !  

 

From the specification document , TCC1 and TCC2 have only two Match/Compare trigger source.

All pins are assigned at my SAMC21 MCU , and TCC0 channel 0~3 are all used.

I will keep finding the method to drive PA08 with TCC1.

 

Thank all replier.

Last Edited: Thu. Oct 19, 2017 - 02:15 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

TCC1 has only two compare channel , and according to the description at the specification :

 

The output matrix (OTMX) configuration :

0x0 is the default configuration. The channel location is the default one, and channels

are distributed on outputs modulo the number of channels. Channel 0 is routed to the Output matrix
output OTMX[0], and Channel 1 to OTMX[1]. If there are more outputs than channels, then channel
0 is duplicated to the Output matrix output OTMX[CC_NUM], channel 1 to OTMX[CC_NUM+1] and
so on.

 

If OTMX register is configured to 0 , WO2 will output the signal which compared by channel 0.

 

PA08 could change status normally after I modifying the definition as below.

#define LIGHT_CC_CHANNEL       TCC_MATCH_CAPTURE_CHANNEL_0