reset TC

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

Hi all,

 

The question sounds simple, but I'm not able to reset a TC. I use a TC as quadrature decoder. It works fine. I periodically read the value of CV register to know the position. Now I'd like in my code to reset the position (to write 0 in CV). CV is read only, so not really possible.

When I do the tc_init() again, it sets TC_CCT_SWTRG, which, according to the datasheet, reset the counter. But in fact it seems the CV register goes to 0 on next clock pulse only. In my case this means wait for the next encoder pulse, which can never happen if I don't move. So counter will be reset only on next movement.

 

Is there a way to instantly (I mean without waiting externel pulse) set CV to 0?

 

Thanks,

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

I'm sure you no longer need this solution, might be useful for someone else: my approach was to set TC0 channel 0 in wave mode (basically a delay), count up until 16bit TC_CV overlaps to 0 and stop the clock, then reinitialise QDEC:

    TC0->TC_BMR = 0; //disable QDEC
    //we need to reset counter to 1 so we set it in timer mode to count for 1 clock

    TC0->TC_CHANNEL[0].TC_RC = 0; //await one clock
    tc_init(TC0, 0, TC_CMR_WAVE |
                         TC_CMR_WAVSEL_UP_RC |
                         TC_CMR_BURST_NONE |
                         TC_CMR_TCCLKS_TIMER_CLOCK4 |
                         TC_CMR_CPCSTOP); //stop counting once it reaches TC_RC
    tc_start(TC0, 0);
    while(!(TC0->TC_CHANNEL[0].TC_SR & TC_SR_CPCS)){/*do nothing*/};

    TC0->TC_BMR = ... //reinitialise encoder

 

Best regards,

David.