<?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: How come similar sentence take different time to execute?</title>
		<link>http://forums.leaflabs.com/topic.php?id=1060</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:24:14 +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=1060" rel="self" type="application/rss+xml" />

		<item>
			<title>mbolivar on "How come similar sentence take different time to execute?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1060#post-6521</link>
			<pubDate>Thu, 22 Sep 2011 10:20:21 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">6521@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Ah, good point.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "How come similar sentence take different time to execute?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1060#post-6520</link>
			<pubDate>Thu, 22 Sep 2011 10:11:27 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6520@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;mbolivar - AFAIK, the program needs to generate a 1.6MHz clock signal, and read data coming in from a pin at that rate.&#60;/p&#62;
&#60;p&#62;I think this may be exactly an SPI-style problem, but I also think an STM32F has just about enough raw horse-power to do it in software. It might migrate to SPI, or even SPI+DMA.&#60;/p&#62;
&#60;p&#62;(full disclosure: I am not a member of LeafLabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "How come similar sentence take different time to execute?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1060#post-6514</link>
			<pubDate>Thu, 22 Sep 2011 09:35:02 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">6514@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;
- a table with the values for the port pin values:&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;I have used this approach on Maple. With systick and USB disabled, it results in extremely regular timing.&#60;/p&#62;
&#60;p&#62;However, if all you're doing is toggling a pin at a predefined rate, then PWM is fastest.  See the forum posts referenced in the FAQ:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://leaflabs.com/docs/faq.html#how-do-i-write-to-a-pin-at-high-speed&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/faq.html#how-do-i-write-to-a-pin-at-high-speed&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "How come similar sentence take different time to execute?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1060#post-6506</link>
			<pubDate>Wed, 21 Sep 2011 16:45:57 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6506@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gulu2065&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;Did you want me to compare the two signal (bit(5)and bit (6))?&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Yes, on a dual trace oscilloscope.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;Their produce are the same.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;That sequence should toggle bit 6 of port B 5 times, and bit 5 once each time around the while loop.&#60;br /&#62;
If it doesn't, there is something going wrong.&#60;/p&#62;
&#60;p&#62;To avoid confusion:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;while (1) {
    GPIOB_BASE-&#38;gt;BSRR = BIT(6) &#124; BIT(5);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6+16);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6+16);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6+16);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6+16);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6+16) &#124; BIT(5+16);
}&#60;/code&#62;&#60;/pre&#62;
&#60;blockquote&#62;&#60;p&#62;Do you have any other ideas to generate a 1.6 Mhz clock and at the same time generate several bits (less than 20) which is synchronously with the 1.6Mhz?&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;You could use:&#60;br /&#62;
- a similar code sequence, but with all the signal encoded so there is no loop, or&#60;br /&#62;
- SPI (running as a slave, with a timer to generate the correct baud rate), or&#60;br /&#62;
- a timer and DMA to write bit patterns to the port pins, or&#60;br /&#62;
- a table with the values for the port pin values:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;uint32 pinValues[] = {
    BIT(6) &#124; BIT(5);
    BIT(6+16);
    BIT(6) &#124; BIT(5);
    BIT(6+16);
    BIT(6) &#124; BIT(5);
    BIT(6+16);
    BIT(6) &#124; BIT(5);
    BIT(6+16);
    BIT(6) &#124; BIT(5);
    BIT(6+16) &#124; BIT(5+16);
    ...
};
...
for (int i=0; i&#38;lt;sizeof(pinValues[])/sizeof(uint32); ++i) {
    GPIOB_BASE-&#38;gt;BSRR = pinValues[i];
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Edit: I made a mistake, the types should be uint32, and not uint16. I have corrected that in the code above.&#60;/p&#62;
&#60;p&#62;(full disclosure: I am not a member of LeafLabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gulu2065 on "How come similar sentence take different time to execute?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1060#post-6505</link>
			<pubDate>Wed, 21 Sep 2011 16:06:08 +0000</pubDate>
			<dc:creator>gulu2065</dc:creator>
			<guid isPermaLink="false">6505@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer,&#60;br /&#62;
I am a little confused by this&#60;br /&#62;
     Then you might see the delay due to the loop on the display on bit 5 trace.&#60;br /&#62;
Did you want me to compare the two signal (bit(5)and bit (6))? Their produce are the same.&#60;/p&#62;
&#60;p&#62;Do you have any other ideas to generate a 1.6 Mhz clock and at the same time generate several bits (less than 20) which is synchronously with the 1.6Mhz?&#60;br /&#62;
Thanks
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "How come similar sentence take different time to execute?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1060#post-6503</link>
			<pubDate>Wed, 21 Sep 2011 15:31:58 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6503@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gulu2065 - I have done similar code. There are only two explanations I can think of:&#60;br /&#62;
1. other interrupts are casing the signal to jitter.&#60;br /&#62;
If you are observing this on a normal oscilloscope, the interrupts will be quite rare (about 1 ms) compared to the signal, so that might not be the cause.&#60;/p&#62;
&#60;p&#62;2. The actual instruction sequence might not have enough registers to hold all of the constant values, so the sequence has an extra load register or two between them.&#60;br /&#62;
Test that  hypothesis with the simpler sequence:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;while (1) {
    GPIOB_BASE-&#38;gt;BSRR = BIT(6) &#124; BIT(5);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6+16);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6) &#124; BIT(5);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6+16);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6) &#124; BIT(5);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6+16);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6) &#124; BIT(5);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6+16);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6) &#124; BIT(5);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6+16) &#124; BIT(5+16);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Are you checking on a dual trace oscilloscope?&#60;br /&#62;
If you are, you might be able to get the 5 cycles (bit 6) of that sequence on one trace, and the other signal (bit 5) on the other.&#60;br /&#62;
Then you might see the delay due to the loop on the display on bit 5 trace.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gulu2065 on "How come similar sentence take different time to execute?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1060#post-6501</link>
			<pubDate>Wed, 21 Sep 2011 15:22:59 +0000</pubDate>
			<dc:creator>gulu2065</dc:creator>
			<guid isPermaLink="false">6501@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer,&#60;br /&#62;
what I mean is the difference between each  GPIOB_BASE-&#38;gt;BSRR = ... Not related to loop or while().&#60;br /&#62;
I mean,&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6) &#124; BIT(5);&#60;br /&#62;
set both high and&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6+16) &#124; BIT(5+16);&#60;br /&#62;
set both low&#60;br /&#62;
...&#60;br /&#62;
...&#60;br /&#62;
when repeat this, I hope I can see a regular signal with the same delay between the several bits. While the delay seems irregular and do not make sense.&#60;br /&#62;
Thanks
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "How come similar sentence take different time to execute?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1060#post-6500</link>
			<pubDate>Wed, 21 Sep 2011 14:55:05 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6500@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The overhead for calling loop() is quite significant compared to the time between two &#60;code&#62;GPIOB_BASE-&#38;gt;BSRR = ...&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;There is really a function called main() which is roughly:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;int main(...) {
    ...
    setup();

    while (1) loop();
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;That &#60;code&#62;while&#60;/code&#62; and call of loop() will be much slower than the goto, or:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;while (1) {
    GPIOB_BASE-&#38;gt;BSRR = BIT(6) &#124; BIT(5);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6+16) &#124; BIT(5+16);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6) &#124; BIT(5);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6+16) &#124; BIT(5+16);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6) &#124; BIT(5);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6+16) &#124; BIT(5+16);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6) &#124; BIT(5);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6+16) &#124; BIT(5+16);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6) &#124; BIT(5);
    GPIOB_BASE-&#38;gt;BSRR = BIT(6+16) &#124; BIT(5+16);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;You might adjust the timing between each &#60;code&#62;GPIOB_BASE-&#38;gt;BSRR = ...&#60;/code&#62; with &#60;code&#62;__asm__(&#38;quot;nop\n\t&#38;quot;);&#60;/code&#62; as mentioned in one of the other threads. That would allow you to get close to having the jump instructions for the goto or while match the gaps between the &#60;code&#62;GPIOB_BASE-&#38;gt;BSRR = ...&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;SPI is worth looking at.&#60;/p&#62;
&#60;p&#62;Look at disabling the interrupts too:&#60;/p&#62;
&#60;p&#62;See &#60;a href=&#34;http://leaflabs.com/docs/lang/api/serialusb.html#lang-serialusb&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/lang/api/serialusb.html#lang-serialusb&#60;/a&#62;&#60;br /&#62;
I think it is USBSerial::end()&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://leaflabs.com/docs/libmaple/api/systick.html?highlight=systick&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/libmaple/api/systick.html?highlight=systick&#60;/a&#62;&#60;br /&#62;
void systick_disable()
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gulu2065 on "How come similar sentence take different time to execute?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1060#post-6499</link>
			<pubDate>Wed, 21 Sep 2011 14:49:18 +0000</pubDate>
			<dc:creator>gulu2065</dc:creator>
			<guid isPermaLink="false">6499@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I find even this basic repeat do not produce a regular signal!(The same time delay between each bits)   Why is that??&#60;br /&#62;
void setup ()&#60;br /&#62;
{&#60;br /&#62;
pinMode(D4, OUTPUT);&#60;br /&#62;
pinMode(D5, OUTPUT);&#60;br /&#62;
}&#60;br /&#62;
void loop(){&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6)    &#124; BIT(5);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6+16)    &#124; BIT(5+16);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6)    &#124; BIT(5);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6+16)    &#124; BIT(5+16);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6)    &#124; BIT(5);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6+16)    &#124; BIT(5+16);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6)    &#124; BIT(5);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6+16)    &#124; BIT(5+16);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6)    &#124; BIT(5);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6+16)    &#124; BIT(5+16);&#60;br /&#62;
}
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "How come similar sentence take different time to execute?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1060#post-6497</link>
			<pubDate>Wed, 21 Sep 2011 14:36:40 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6497@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;There are two interrupts, systick and USB running which may make the value jitter. You can disable them.&#60;/p&#62;
&#60;p&#62;The delay between&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;GPIOB_BASE-&#38;gt;BSRR = BIT(6+16) &#124; BIT(5);
GPIOB_BASE-&#38;gt;BSRR = BIT(6) &#124; BIT(5);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;will be different to&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;GPIOB_BASE-&#38;gt;BSRR = BIT(6+16) &#124; BIT(5);
goto myloop;
...
myloop:
GPIOB_BASE-&#38;gt;BSRR = BIT(6) &#124; BIT(5);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I can't think of much you can do about that.&#60;/p&#62;
&#60;p&#62;SPI would be more accurate if you can get the clock speed correct.&#60;/p&#62;
&#60;p&#62;(full disclosure: I am not a member of LeafLabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gulu2065 on "How come similar sentence take different time to execute?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1060#post-6493</link>
			<pubDate>Wed, 21 Sep 2011 13:35:47 +0000</pubDate>
			<dc:creator>gulu2065</dc:creator>
			<guid isPermaLink="false">6493@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I want to use the following sentence to generate several bits to configure my chip.&#60;br /&#62;
As planned, Pin 4 should output a 11001 bits synchronously with Pin 5, which is a CLK.&#60;br /&#62;
However, when I measure it on the scope, I find it take different time for each command and I get the five bits with different intervals.&#60;br /&#62;
Any suggestions?&#60;/p&#62;
&#60;p&#62;void setup ()&#60;br /&#62;
{&#60;br /&#62;
pinMode(D4, OUTPUT);&#60;br /&#62;
pinMode(D5, OUTPUT);&#60;br /&#62;
}&#60;br /&#62;
void loop(){&#60;br /&#62;
myloop:&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6)    &#124; BIT(5);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6+16)    &#124; BIT(5);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6)    &#124; BIT(5);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6+16)    &#124; BIT(5);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6)    &#124; BIT(5+16);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6+16)    &#124; BIT(5+16);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6)    &#124; BIT(5+16);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6+16)    &#124; BIT(5+16);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6)    &#124; BIT(5);&#60;br /&#62;
GPIOB_BASE-&#38;gt;BSRR = BIT(6+16)    &#124; BIT(5);&#60;br /&#62;
goto myloop;&#60;br /&#62;
}&#60;br /&#62;
Thanks a lot!
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
