SAMD20 PWM FREQ GENERATION

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

Hello,

 

Working with the SAMD20 and having trouble getting a frequency out to a pin. I have looked at the ASF documents for setting up a TC for frequency matching and came up with this, but I get nothing on the specified pin.

 

void config_piezo_freq(void)
{
	struct tc_config config_piezo;
	tc_get_config_defaults(&config_piezo);
	
	config_piezo.counter_size = TC_COUNTER_SIZE_16BIT;
	config_piezo.clock_source = GCLK_GENERATOR_3;

	config_piezo.wave_generation = TC_WAVE_GENERATION_MATCH_FREQ;
	config_piezo.counter_16_bit.compare_capture_channel[1] = 5;
	config_piezo.pwm_channel[1].enabled = true;
	config_piezo.pwm_channel[1].pin_out = PIN_PA25F_TC5_WO1;
	config_piezo.pwm_channel[1].pin_mux = MUX_PA25F_TC5_WO1;
	
	tc_init(&tc_instancePiezo, CONF_TC_MODULE5, &config_piezo);
	tc_enable(&tc_instancePiezo);	
}

I have a feeling I need to set up the pin outside of this as a config. Am I going in the right direction as far as I need to set it up as an output and set it to use peripheral F? Or is that already done here in the code? The ASF documentation only goes so far in descriptions. Thanks.

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

No additional pin config needed no. Are you sure about the MATCH_FREQ mode, you are not setting a channel 0 compare value so it makes sense nothing happens:

For Match Frequency Generation, the period time (T) is controlled by the CC0 register instead of PER or MAX. WO[0] toggles on each update condition.

/Lars 

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

Good to know. As far as match freq, what I gathered is that's the best option for what I want. I am trying to output a 2400Hz freq out PA25 which can be toggled on or off, and the TC on that pin is TC5/WO[1]. I am using a SAMD20J17 on a custom board. The piezo sits on pin 46 [PA25]. Thank you for the reply.

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

Hi again, I figured it out, once again with help from another question you replied upon. I set up CC0, then the pwm channel is actually channel 1. 

found it here: https://community.atmel.com/forum/samd20-xplained-pro-pwm-matched-mode-difficulty

 

Now, I want to be able to turn it on and off at will. Would I use the pwm_channel[1].enabled = true; and pwm_channel[1].enabled = false wherever I need to to do that, or is there an easier solution?

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

Actually, nevermind with this as well. I just enable or disable the tc using tc_enable. I set up a 1 second timer and on overflow it toggles the beeper using tc_enable and tc_disable. If there's a more elegant solution to this, please still let me know.