SAM D21 / external clock for TC3

Discussions around product based on ARM Cortex M0+ core.
This forum will be discontinued soon.

Moderator: nferre

rubear
Posts: 5
Joined: Mon Nov 30, 2015 12:55 am

SAM D21 / external clock for TC3

Wed Nov 23, 2016 6:46 pm

I am trying to clock TC3 with an input on PA15 and output on PA14.
When I clock with GCLK_GENERATOR_1 and if GCLK_GENERATOR_1 = SYSTEM_CLOCK_SOURCE_OSC8M, I do get the output on PA14.
But if I change GCLK_GENERATOR_1 = GCLK_SOURCE_GCLKIN, I get no output. Freq in = 12.3 MHz.
It hangs on

Code: Select all

while (tc_is_syncing(module_inst)){}

My initialization code is:

Code: Select all

/* Configure GCLK generator 1 */
#  define CONF_CLOCK_GCLK_1_ENABLE                       true
#  define CONF_CLOCK_GCLK_1_RUN_IN_STANDBY       false
#  define CONF_CLOCK_GCLK_1_CLOCK_SOURCE          GCLK_SOURCE_GCLKIN
#  define CONF_CLOCK_GCLK_1_PRESCALER                 1
#  define CONF_CLOCK_GCLK_1_OUTPUT_ENABLE         false

 void configure_tc(void)
 {
	 struct tc_config config_tc;
	
	 tc_get_config_defaults(&config_tc);
	
	 config_tc.counter_size = TC_COUNTER_SIZE_8BIT;
	 config_tc.clock_source =  GCLK_GENERATOR_1;
	 config_tc.clock_prescaler = TC_CLOCK_PRESCALER_DIV1;
	 config_tc.counter_8_bit.period = 3;
	 config_tc.counter_8_bit.compare_capture_channel[0] = 2; // not used
	 config_tc.counter_8_bit.compare_capture_channel[1] = 2; // not used		 

	 config_tc.wave_generation = TC_WAVE_GENERATION_NORMAL_FREQ;
	 config_tc.pwm_channel[TC_COMPARE_CAPTURE_CHANNEL_0].pin_out = PIN_PA14E_TC3_WO0;
	 config_tc.pwm_channel[TC_COMPARE_CAPTURE_CHANNEL_0].pin_mux = MUX_PA14E_TC3_WO0;
	 config_tc.pwm_channel[TC_COMPARE_CAPTURE_CHANNEL_0].enabled = true;

	 tc_init(&tc_instance, TC3, &config_tc);
	 tc_enable(&tc_instance);	
 }
Any help would be greatly appreciated!
-Robert

Update:
The code below fixes it.
The macro expansion of PINMUX_PA15H_GCLK_IO1 is a 32 bit value.
config_pinmux.mux_position is an 8 bit type.

I used PIN_PA15H_GCLK_IO1 instead of PINMUX_PA15H_GCLK_IO1.

Code: Select all


	struct system_pinmux_config config_pinmux;	

	system_pinmux_get_config_defaults(&config_pinmux);
	config_pinmux.mux_position = PIN_PA15H_GCLK_IO1;
	config_pinmux.direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
	config_pinmux.input_pull = SYSTEM_PINMUX_PIN_PULL_NONE;
	system_pinmux_pin_set_config(PIN_PA15H_GCLK_IO1, &config_pinmux);

Return to “SAM D20 Cortex-M0+ MCU”

Who is online

Users browsing this forum: No registered users and 1 guest