Can't change PWM output pin on SAMC21

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

I modified the TCC_QUICK_START example project for the Xplained Pro to use pin PA20 instead of PA15 (which is the on board LED) and can't get it to work.  Following the "I/O Multiplexing and Considerations" section of the datasheet, I changed these 2 lines:

 

config_tcc.pins.wave_out_pin[CONF_PWM_OUTPUT]      = CONF_PWM_OUT_PIN;
config_tcc.pins.wave_out_pin_mux[CONF_PWM_OUTPUT]  = CONF_PWM_OUT_MUX;

 

to this:

 

config_tcc.pins.wave_out_pin[CONF_PWM_OUTPUT]        = PIN_PA20F_TCC0_WO6;
config_tcc.pins.wave_out_pin_mux[CONF_PWM_OUTPUT]    = MUX_PA20F_TCC0_WO6;    

 

These two items,  CONF_PWM_OUT_PIN, and  CONF_PWM_OUT_MUX boil down to PIN_PA15F_TCC0_WO5 an MUX_PA15F_TCC0_WO5.

Interestingly enough, if I change the pin to PA23, which also uses TCC0/WO[5] it works.  My target board has to use PA20 so I need to get it working.  What am I missing?  Here is the full code:

 

 

/**
 * \file
 *
 * \brief SAM Timer/Counter Driver for Control Applications Basic Quickstart
 *
 * Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.
 *
 * \asf_license_start
 *
 * \page License
 *
 * Subject to your compliance with these terms, you may use Microchip
 * software and any derivatives exclusively with Microchip products.
 * It is your responsibility to comply with third party license terms applicable
 * to your use of third party software (including open source software) that
 * may accompany Microchip software.
 *
 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
 * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
 * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
 * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
 * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
 * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT
 * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
 * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
 * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
 *
 * \asf_license_stop
 *
 */

/*
 * Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
 */

#include <asf.h>
#include <conf_quick_start.h>

static void configure_tcc(void);

//! [module_inst]
struct tcc_module tcc_instance;
//! [module_inst]

//! [setup]
static void configure_tcc(void)
{
	//! [setup_config]
	struct tcc_config config_tcc;
	//! [setup_config]
	//! [setup_config_defaults]
	//tcc_get_config_defaults(&config_tcc, CONF_PWM_MODULE);
	tcc_get_config_defaults(&config_tcc, TCC0);
	//! [setup_config_defaults]

	//! [setup_change_config]
	config_tcc.counter.clock_source = GCLK_GENERATOR_0;  // 48Mhz
	config_tcc.counter.clock_prescaler = TCC_CLOCK_PRESCALER_DIV1;
	config_tcc.counter.period = 0x5000;   // fpwm = BUS_CLOCK/(N*(PERIOD + 1)) = 48E6/(1*(0x5000 + 1)) = 2.344Khz
	config_tcc.compare.wave_polarity[CONF_PWM_CHANNEL] = TCC_WAVE_POLARITY_1;		

	config_tcc.compare.wave_generation = TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM;
	config_tcc.compare.match[CONF_PWM_CHANNEL] = (0x5000 / 2);  // 50% duty cycle	

	//! [setup_change_config]

	//! [setup_change_config_pwm]
	config_tcc.pins.enable_wave_out_pin[CONF_PWM_OUTPUT] = true;
	config_tcc.pins.wave_out_pin[CONF_PWM_OUTPUT]        = PIN_PA20F_TCC0_WO6;
	config_tcc.pins.wave_out_pin_mux[CONF_PWM_OUTPUT]    = MUX_PA20F_TCC0_WO6;
	//config_tcc.pins.wave_out_pin[CONF_PWM_OUTPUT]      = CONF_PWM_OUT_PIN;
	//config_tcc.pins.wave_out_pin_mux[CONF_PWM_OUTPUT]  = CONF_PWM_OUT_MUX;
	//! [setup_change_config_pwm]

	//! [setup_set_config]
	//tcc_init(&tcc_instance, CONF_PWM_MODULE, &config_tcc);
	tcc_init(&tcc_instance, TCC0, &config_tcc);
	//! [setup_set_config]

	//! [setup_enable]
	tcc_enable(&tcc_instance);
	//! [setup_enable]
}
//! [setup]

int main(void)
{
	system_init();	

	//! [setup_init]
	configure_tcc();
	//! [setup_init]
	uint16_t count = 1;

//! [main]
	//! [main_loop]
	while (true) {
		/* Infinite loop */	

	}
	//! [main_loop]
//! [main]
}

 

This topic has a solution.
Last Edited: Sun. Mar 10, 2019 - 09:15 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

By default channel 0 will output WO0 and WO4, channel 1 WO1 and WO5 etc. You will have to use channel 2 to get something on WO6.

/Lars

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

Thanks Lars!  The Signal Description table in the data sheet is a little cryptic:

 

37.4. Signal Description
Pin Name Type Description
TCCx/WO[0] Digital output Compare channel 0 waveform output
TCCx/WO[1] Digital output Compare channel 1 waveform output
… ... ...
TCCx/WO[WO_NUM-1] Digital output Compare channel n waveform output