Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Timer stopping and starting, without loosing count
PostPosted: Fri Feb 19, 2010 2:12 pm 
Offline

Joined: Fri Feb 19, 2010 1:59 pm
Posts: 1
Afternoon all

I am creating a library for asynchronous soft deadline timeouts. It allows me to timerCreate(), timerStart(), timerStop and timerDelete(), and timerHasItExpired() - with various parameters to them all.

I'm relatively new to this chip, and am having some troubles with what exactly to do to correctly deal with the interrupts, and also to disable the interrupt at various points in my library.

In my ISR, should I disable the interrupt at the AIC? Then I read the status reg for TC and act on it. Should I be stopping the clock for TC0 in here? Ideally, i'd like to keep the clock running, but stop the interrupt so it cant recur while in the ISR.

So, which of these should I do?
Code:
void tc0_isr()
{
  (disable interrupt?)
  (stop clock?)
  do my work
  (start clock?)
  (enable interrupt?)
}


The second part is that I need to ensure that the ISR does not run while in the functions. If it does, it could scramble some of my structures' data.

So, for example, which of these should I do?
Code:
x timerHasItExpired(y)
{
  (disable interrupts?)
  (stop clock?)
  do my stuff, safe in the knowledge that isr wont run...
  (enable clock?)
  (enable interrupts?)
}


Seemingly I cannot _just_ start the clock by setting CLKEN, it doesnt seem to start the clock again after using CLKDIS. Only SWTRG is starting the clock again, but that resets the counter. So if I use SWTRG every time I want to restart the clock, then when I poll timerHasItExpired(), the clock never progresses to fire its interrupt.

Hope someone out there has some ideas.

Cheers

Rich


Top
 Profile  
 
 Post subject: Re: Timer stopping and starting, without loosing count
PostPosted: Fri May 07, 2010 10:45 am 
Offline

Joined: Mon Nov 14, 2005 2:22 pm
Posts: 10
Location: Germany
Switch the clocksource in the "Channel Mode Register" to an unclocked source e.g. "XC0"

Make sure that XCO ist not used!

Restart the timer by switching the CMR back to the original clocksource, e.g. "TC_CLKS_TIMER_DIV1_CLOCK" .

Works fine for my free programmable timer.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: