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  [ 4 posts ] 
Author Message
 Post subject: SAM3U4 systick timer rollover?
PostPosted: Thu Jan 13, 2011 4:32 pm 
Offline

Joined: Tue May 30, 2006 4:22 pm
Posts: 14
Location: The Netherlands
Hi,

A question about the getting-started-project-at91sam3u for iar.

The leds will blink with an interval of 500ms. This with the function Wait().
But what happens when the timestamp is going from maximum value (2^32) to zero?

'elapsed' is an unsigned short, so that value becomes the value 2^32 - start and the test "while (elapsed < delay)" can be not correct.

I think it is also possible that the line "volatile unsigned int start = timestamp;" can results in another value then the 1st execute of "elapsed = timestamp;" in the do-while routine. Is that correct?

void Wait(unsigned long delay)
{
volatile unsigned int start = timestamp;
unsigned int elapsed;

do {
elapsed = timestamp;
elapsed -= start;
}
while (elapsed < delay);
}

_________________
Marien


Top
 Profile  
 
 Post subject: Re: SAM3U4 systick timer rollover?
PostPosted: Thu Jan 13, 2011 11:09 pm 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 784
Normally you'd use 32-bit math for 32-bit registers. The timing being a function of the tick granularity and the length of the counter.

Now typically you'd have a hierarchy of loops, some dealing with smaller delays (say a microsecond), and higher ones dealing with larger delays calling the lower ones.

Software timing loops are generally eschewed, the processor should be off doing more productive work and not grinding in a tight loop doing nothing for long periods.


Top
 Profile  
 
 Post subject: Re: SAM3U4 systick timer rollover?
PostPosted: Wed Jun 06, 2012 10:24 am 
Offline

Joined: Fri Jun 01, 2012 8:53 am
Posts: 11
Hello,

I encountered the same problem. You must declare the variable volatile. Otherwise, it is impossible to access in the context of the interruption and in the context of normal program.


Top
 Profile  
 
 Post subject: Re: SAM3U4 systick timer rollover?
PostPosted: Thu Jun 07, 2012 1:27 am 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 784
Technosvitman wrote:
I encountered the same problem. You must declare the variable volatile. Otherwise, it is impossible to access in the context of the interruption and in the context of normal program.

The only thing that needs to be volatile is the variable 'timestamp' because it is changed outside the scope of the subroutine. It isn't impossible to access it, the problem is that the optimizer, if enabled, will/might try not to read it every time because it assumes it's value is static, when in fact it needs to be read at each loop iteration because it might have changed.


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

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 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: