Frequency limit for Timer?

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

I'm new with the SAM processors. So, please forgive me if my question is too basic.

I've been trying for more than 2 weeks now to generate an output from a TC timer on a SAMD21 Explained board with no success. I can get it to output a maximum frequency of 54,631 Hz. But, I need to increase it to 200,000 Hz.

I'm working with ASF and this is the code I have:

void configure_tc(void)
{
	//! [setup_config]
	struct tc_config config_tc;
	
	tc_get_config_defaults(&config_tc);
	//! [setup_config_defaults]

	//! [setup_change_config]
	config_tc.counter_size = TC_COUNTER_SIZE_8BIT;
	config_tc.clock_source = GCLK_GENERATOR_0;
	config_tc.clock_prescaler = TC_CLOCK_PRESCALER_DIV1;
	config_tc.counter_8_bit.period = 255;
	config_tc.count_direction=TC_COUNT_DIRECTION_UP;
	tc_init(&tc_instance, CONF_TC_MODULE, &config_tc);
	tc_enable(&tc_instance);
}

With the period set to 255 I get a frequency of 15575 Hz which makes sense since 8MHz divided by 256 divided by 2 is 15625.

However as I decrease the period I get to a maximum frequency at a value of 72. Any value lower than that gives me the same number!

 

This is the code I have for the callbacks:

void configure_tc_callbacks(void)
{
	//! [setup_register_callback]
	tc_register_callback(&tc_instance, tc_callback_to_toggle_led,
	TC_CALLBACK_OVERFLOW);
	tc_enable_callback(&tc_instance, TC_CALLBACK_OVERFLOW);
}

void tc_callback_to_toggle_led(struct tc_module *const module_inst)
{
	port_pin_toggle_output_level(LED0_PIN);//Set to pin PB30
}

Which should toggle the output pin PB30 everytime the counter overflows.

The GCLK_GENERATOR_0 is set to 8Mhz.

If I change to GCLK_GENERATOR_1 which is set to 32KHz then everything works according to calculations.

 

So, can anybody figure out what I'm doing wrong that limits the maximum frequency to 54,631 Hz?

I would really appreciate any pointers,

Regards

Arturo

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

Up!!!!

 

We are in the same boat friend, I need to generate 64Khz out. 

 

It is important. 

 

Atmel pleasee!! Here!!

 

I tried everything but the MAX Freq out is this:

 

 

 

Franc

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

Pin toggle in ASF is slow, so using a callback to toggle the port pin is not going to be good. The timers can toggle a port bit in hardware, so set the timer for that. The timers are pretty simple, so you can just access the registers directly rather than using ASF.