Electronics > Microcontrollers

ATSAMC21 with Harmony 3 using timers...

(1/1)

NivagSwerdna:
I'm trying to use TC2 to time an interval...

The idea was...

--- Code: ---    TC2_Compare16bitCounterSet(0);
    TC2_CompareStart();

  // do stuff

    TC2_CompareStop();

    uint16_t timer_count = TC2_Compare16bitCounterGet();
--- End code ---


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

ataradov:
Enabling and stopping are two separate operations. Stopping is done through the CTRLBSET.CMD = STOP (0x2).

Navigation

[0] Message Index

There was an error while thanking
Thanking...
Go to full version