SAMD20 - config timer as counter?

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

Hey dear people here!
Since days I try to configure a timer with AS7 and ASF on a SAMD20J18 as a simple counter. So the timer/counter is incremented at every edge of an external pin.
Unfortunately, I already found out, you can't directly set an external pin to a timer clock input.
Now I'm desperately trying how to control the clock generator 7 via its external pin and again control the timer from this clock generator 7.
Unfortunately it doesn't work.
My current code:

void configure_tc_rpm_counter(void)
{
	struct tc_config config_tc_rpm_counter;
	tc_get_config_defaults(&config_tc_rpm_counter);
	config_tc_rpm_counter.counter_size    = TC_COUNTER_SIZE_16BIT;
	config_tc_rpm_counter.clock_source    = GCLK_GENERATOR_7;
	config_tc_rpm_counter.clock_prescaler = TC_CLOCK_PRESCALER_DIV1;
	config_tc_rpm_counter.wave_generation = TC_WAVE_GENERATION_NORMAL_FREQ;
	tc_init(&tc_instance_rpm_counter, TC5, &config_tc_rpm_counter);
	tc_enable(&tc_instance_rpm_counter);
}

void configure_pinmux_rpm(void)
{
	struct system_pinmux_config config_pinmux;
    system_pinmux_get_config_defaults(&config_pinmux);
    config_pinmux.mux_position = PINMUX_PA23H_GCLK_IO7;
    config_pinmux.direction    = SYSTEM_PINMUX_PIN_DIR_INPUT;
    system_pinmux_pin_set_config(PIN_PA23H_GCLK_IO7, &config_pinmux);
}

/* Configure GCLK generator 7     -->>  für rpm Messung*/
#  define CONF_CLOCK_GCLK_7_ENABLE                true //false
#  define CONF_CLOCK_GCLK_7_RUN_IN_STANDBY        true //false
#  define CONF_CLOCK_GCLK_7_CLOCK_SOURCE          SYSTEM_CLOCK_SOURCE_GCLKIN
#  define CONF_CLOCK_GCLK_7_PRESCALER             1
#  define CONF_CLOCK_GCLK_7_OUTPUT_ENABLE         false

 

Or is this only possible via the event system?

Last Edited: Thu. Nov 7, 2019 - 12:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm most familiar with SAMD21, which is very similar to your SAMD20, so my answer may be inappropriate 

You could generate an event on the appropriate signal flank and use it to increment the counter

Jerry

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

Event based counting is likely better than trying to clock the counter from the external signal. At least I imagine there will be register synch problems if the external signal is not a reliable clock (and also if it is slow).

/Lars