<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: What is systick counting?</title>
		<link>http://forums.leaflabs.com/topic.php?id=74164</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:17:50 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=74164" rel="self" type="application/rss+xml" />

		<item>
			<title>hihohoho on "What is systick counting?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74164#post-104973</link>
			<pubDate>Sun, 24 Nov 2013 06:11:01 +0000</pubDate>
			<dc:creator>hihohoho</dc:creator>
			<guid isPermaLink="false">104973@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Yes, it switches off interrupts either side (before timing is started). It does occasionally take a lot longer if the USB does it's thing. &#60;/p&#62;
&#60;p&#62;I presume if I run off battery the usb interrupts won't occur?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "What is systick counting?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74164#post-104972</link>
			<pubDate>Sat, 23 Nov 2013 21:50:26 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">104972@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;hihohoho - &#60;em&#62;&#34;The top code of 200 nops runs in 203 systicks not 201&#34;&#60;/em&#62;&#60;/p&#62;
&#60;p&#62;Very interesting. Thank you for sharing your results.&#60;/p&#62;
&#60;p&#62;I had expected 200 NOP's + the &#60;code&#62;systick_get_count()&#60;/code&#62; to take 202cycles (assuming the registers are loaded with the SysTick timers value register), or a lot more than 202 if the SysTick interrupt is taken while timing, or even more if the USB interrupt is taken while timing. Does the code switch off interrupts while timing?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>hihohoho on "What is systick counting?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74164#post-104971</link>
			<pubDate>Sat, 23 Nov 2013 15:50:31 +0000</pubDate>
			<dc:creator>hihohoho</dc:creator>
			<guid isPermaLink="false">104971@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Small update. The top code of 200 nops runs in 203 systicks not 201 (I can't count), which sounds about right as 1 clock for get_syst_getcount() 1 clock to get 'a' and then another to perform calculation? Well, without looking at the assembly produced I can only guess. Never-the-less, useful to know about get_sys_getcount() in getting timings correct.&#60;/p&#62;
&#60;p&#62;Rather confusingly. The result of&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;int a=systick_get_count();
int b=systick_get_count();
int c=b-a;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;is c=-1. Every time. ? Oh. Of course. systick counts down.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "What is systick counting?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74164#post-104970</link>
			<pubDate>Sat, 23 Nov 2013 14:52:33 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">104970@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;hihohoho - I guess your post, and my edit/post overlapped.&#60;/p&#62;
&#60;p&#62;SysTick is running at 72MHz (HCLK), not 9MHz (HCLK/8).&#60;/p&#62;
&#60;p&#62;Yes, the Cortex-M3 should run NOP in 1 clock at 72MHz. Flash memory can't run at 72MHz, and so might run with wait states. However I think the memory pre-fetch unit should hide the latency of Flash. &#60;/p&#62;
&#60;p&#62;Cortex-M3 'within CPU' instructions take 1 cycle, but memory access takes two clocks.&#60;br /&#62;
FWIW AVR isn't always 1 instruction = 1 cycle, for example Load Indirect from Data Space (LD) can take 1, 2 or 3 cycles.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>hihohoho on "What is systick counting?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74164#post-104969</link>
			<pubDate>Sat, 23 Nov 2013 13:54:37 +0000</pubDate>
			<dc:creator>hihohoho</dc:creator>
			<guid isPermaLink="false">104969@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Ok, just noticed you edit. Makes more sense now. I'll have a look through systick.h. My first read through yesterday didn't make much sense but you've given a few more clues to understand now. Thanks!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>hihohoho on "What is systick counting?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74164#post-104967</link>
			<pubDate>Sat, 23 Nov 2013 12:50:43 +0000</pubDate>
			<dc:creator>hihohoho</dc:creator>
			<guid isPermaLink="false">104967@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer, many thanks. &#60;/p&#62;
&#60;p&#62;I'll have a read through that when I'm more awake. Not fully in gear today. Though.... a quick read through leaves me puzzled. If systick is 9mhz but 1 nop is 1 clock then... I'm confused. Can the arm chip run at 72 mips (for a nop) or is it a more complicated chip than I am assuming? I've got used to the avr's being 1mhz=1mips.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "What is systick counting?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74164#post-104966</link>
			<pubDate>Sat, 23 Nov 2013 10:16:49 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">104966@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The systick timer is described in &#34;PM0056 Programming manual: STM32F10xxx/20xxx/21xxx/L1xxxx Cortex-M3 programming manual&#34;:&#60;br /&#62;
&#60;a href=&#34;http://www.st.com/st-web-ui/static/active/en/resource/technical/document/programming_manual/CD00228163.pdf&#34; rel=&#34;nofollow&#34;&#62;http://www.st.com/st-web-ui/static/active/en/resource/technical/document/programming_manual/CD00228163.pdf&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Section &#34;4.5 SysTick timer (STK)&#34; says&#60;br /&#62;
&#34;The processor has a 24-bit system timer, SysTick, that counts down from the reload value to zero, reloads (wraps to) the value in the LOAD register on the next clock edge, then counts down on subsequent clocks.&#34;&#60;/p&#62;
&#60;p&#62;RM0008, section &#34;7.2 Clocks&#34; adds:&#60;br /&#62;
&#34;The RCC feeds the Cortex System Timer (SysTick) external clock with the AHB clock (HCLK) divided by 8. The SysTick can work either with this clock or with the Cortex clock (HCLK), configurable in the SysTick Control and Status Register.&#34;&#60;br /&#62;
EDIT:&#60;br /&#62;
I read systick.h systick.h. SysTick is driven by HCLK (&#60;strong&#62;not HCLK/8&#60;/strong&#62;). So with a 72MHz core clock, SysTick is driven at 72MHz. If you read the SysTick timer directly, that's what you'll see, a timer which runs fast enough to time instructions. Then a reload value of 71999 (SYSTICK_RELOAD_VAL is N-1 ticks) gives a 1ms 'tick'. &#60;/p&#62;
&#60;p&#62;The speed of the general purpose timers is constrained by the clock source, it could be from the bus (see the clock tree in RM0008 Figure 8) or an external source. Reading the STM32F103B datasheet (5.3.15 TIM timer characteristics) the external clock source is limited to 36MHz, and bus is 72MHz.&#60;/p&#62;
&#60;p&#62;However, the actual frequency fed to the advanced timer (TIM1), and the group of general purpose timers (2, 3, 4), can be different. Those clocks are set by a bunch of bits in control registers. Look at RM0008, section &#34;7.2 Clocks&#34; to see the possibilities.&#60;br /&#62;
mlundinse explains here &#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=15451#post-30954&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=15451#post-30954&#60;/a&#62; that they are all set to the SYSCLK which is 72MHz.&#60;/p&#62;
&#60;p&#62;I'd have to check the details for NOP. However, assuming it is a 16bit instruction, then pre-fetch should keep up okay for 'straight-line' code. Hence I'd expect a series of X NOPs to run in X clocks.&#60;br /&#62;
Even an inline call to something, e.g. systick_get_count(), I expect will take 2 cycles to read from memory (the systick peripheral).&#60;br /&#62;
Try:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;int a=systick_get_count();
int b=systick_get_count();
int c=b-a;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;and see what the value of &#60;code&#62;c&#60;/code&#62; is.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>hihohoho on "What is systick counting?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74164#post-104964</link>
			<pubDate>Fri, 22 Nov 2013 12:27:11 +0000</pubDate>
			<dc:creator>hihohoho</dc:creator>
			<guid isPermaLink="false">104964@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello,&#60;/p&#62;
&#60;p&#62;I'm using systick_get_count() to return the exact value of systick, but what exactly is systick counting? What is it's overall frequency? Is it every clock pulse so 72Mhz? 36Mhz?&#60;/p&#62;
&#60;p&#62;I had a look/search at the arm m3 docs but it only shows what it can be used for, i.e. micros() not what it is. &#60;a href=&#34;http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0179b/ar01s02s08.html&#34; rel=&#34;nofollow&#34;&#62;http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0179b/ar01s02s08.html&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;While on the subject, what is the fastest timer clock speed? Is it also 72 or maybe 36? &#60;/p&#62;
&#60;p&#62;Also...(sorry) how many clock cycles would a nop operation perform in? 1 or 2? (because of flash). I've used systick_get_count() to hopefully count this and I'm getting 201 systicks for 200 nop operations but I guess the calculations take up 1. It seems to take 3-4 micro seconds according to micros() but that depends on when you take a sample of micros(). &#60;/p&#62;
&#60;p&#62;The code is :-&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;int a=systick_get_count();

	asm(&#38;quot;	nop&#38;quot;);
	asm(&#38;quot;	nop&#38;quot;);
	asm(&#38;quot;	nop&#38;quot;);
	asm(&#38;quot;	nop&#38;quot;);

        etc .repeat until 200 nops

	a=systick_get_count()-a;&#60;/code&#62;&#60;/pre&#62;</description>
		</item>

	</channel>
</rss>
