Go Down

Topic: Timers - Setting TIOAx-TIOBx to low when disabling a timer. (Read 704 times) previous topic - next topic

PlasticPelican

Hello.

I'm working on a project that use timers and I have ran into a problem.

I need to be able to disable a timer, but when I run:
Code: [Select]
TC2->TC_CHANNEL[0].TC_CCR = TC_CCR_CLKDIS;
TIOA6 stays in the last mode it was in, so if it is _SET when the timer is disabled the pin stays high.

I can't find anything in the datasheet/header files about how to clear the pin when the timer is disabled.

Do I actually have to transfer control of the pin to the PIO to disable it and then transfer control back, or what am I missing?

ard_newbie

One way to clear TIOB6 pin (PC26) is obviously to give back control of the pin to the GPIO:

PIOC->PIO_PER |= PIO_PER_P26;
PIOC->PIO_OER |= PIO_OER_P26;

then clear PC26 if necessary:

PIOC->PIO_CODR |= PIO_CODR_P26;


Another one might be to stop TC6 clock(not tested though):

PMC->PMC_PCDR1 |= PMC_PCDR1_PID33;

PlasticPelican

Stopping the clock didn't work.

I tried the pioc method:

Code: [Select]
 
  TC2->TC_CHANNEL[0].TC_CCR = TC_CCR_CLKDIS;
  REG_PIOC_PER |= PIO_PER_P25;
  REG_PIOC_OER |= PIO_OER_P25;
  PIOC->PIO_CODR = PIO_CODR_P25;
  // stuff
  REG_PIOC_PDR |= PIO_PDR_P25; 


The weird part is that it works fine where it says " // stuff ", but as soon as control is handed back to the timer the pin goes high, even when the clock is disabled.

ard_newbie


PlasticPelican

Ok. I managed to get it to work.


Just added:

Code: [Select]
TC2->TC_CHANNEL[0].TC_CMR |= TC_CMR_ASWTRG_CLEAR;

(clear TIOA on software-trigger) and then replaced the
TC2->TC_CHANNEL[0].TC_CCR = TC_CCR_CLKDIS;
with:
Code: [Select]
TC2->TC_CHANNEL[0].TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKDIS;

Luckily I didn't need the software trigger for anything else.

Go Up