Author Topic: ATSAMC21 with Harmony 3 using timers...  (Read 924 times)

0 Members and 1 Guest are viewing this topic.

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
ATSAMC21 with Harmony 3 using timers...
« on: May 17, 2021, 11:59:45 pm »
I'm trying to use TC2 to time an interval...

The idea was...
Code: [Select]
    TC2_Compare16bitCounterSet(0);
    TC2_CompareStart();

  // do stuff

    TC2_CompareStop();

    uint16_t timer_count = TC2_Compare16bitCounterGet();


But this always gives me ZERO! 

I did some experimentation and TC2_Compare16bitCounterGet always gives zero when the timer is stopped... that seems a bit weird.. could it be a silicon flaw?  I cannot see it listed in the errata.

PS
Start is essentially... TC2_REGS->COUNT16.TC_CTRLA |= TC_CTRLA_ENABLE_Msk;
Stop is essentially.... TC2_REGS->COUNT16.TC_CTRLA &= ~TC_CTRLA_ENABLE_Msk;
CounterGet is TC2_REGS->COUNT16.TC_CTRLBSET |= (uint8_t)TC_CTRLBSET_CMD_READSYNC; return TC2_REGS->COUNT16.TC_COUNT
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11269
  • Country: us
    • Personal site
Re: ATSAMC21 with Harmony 3 using timers...
« Reply #1 on: May 18, 2021, 12:27:58 am »
Enabling and stopping are two separate operations. Stopping is done through the CTRLBSET.CMD = STOP (0x2).
Alex
 
The following users thanked this post: NivagSwerdna


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf