<?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: High-Speed GPIO Access?</title>
		<link>http://forums.leaflabs.com/topic.php?id=774</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:08: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=774" rel="self" type="application/rss+xml" />

		<item>
			<title>hans leuthold on "High-Speed GPIO Access?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=774&amp;page=3#post-13733</link>
			<pubDate>Wed, 12 Sep 2012 12:06:28 +0000</pubDate>
			<dc:creator>hans leuthold</dc:creator>
			<guid isPermaLink="false">13733@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;ala42 - I guess you hit the nail right on the head, the while loop running exactly once up to exactly twice, I could not see the forest because of the trees.....&#60;/p&#62;
&#60;p&#62;thanks for the hint on SPI, I will check that out
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ala42 on "High-Speed GPIO Access?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=774&amp;page=3#post-13647</link>
			<pubDate>Tue, 11 Sep 2012 19:50:53 +0000</pubDate>
			<dc:creator>ala42</dc:creator>
			<guid isPermaLink="false">13647@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The reaction time of the while loop is not constant, so you must get a jitter. If you have any doubt about this, just use some fixed calculations instead the while loops to be convinced :)&#60;/p&#62;
&#60;p&#62;Btw, you could read the data via SPI, so you do not need to follow the clock line in your code. Just read the SPI data when ready and evaluate it. This leaves you much more time for analyzing the data stream.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "High-Speed GPIO Access?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=774&amp;page=3#post-13643</link>
			<pubDate>Tue, 11 Sep 2012 19:01:45 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">13643@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;You're also assuming that the 72MHz is exact. There will be jitter because of the design of the system. It's using a 8MHz reference into a clock multiplier to give a speed of 72MHz.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>hans leuthold on "High-Speed GPIO Access?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=774&amp;page=3#post-13639</link>
			<pubDate>Tue, 11 Sep 2012 18:01:54 +0000</pubDate>
			<dc:creator>hans leuthold</dc:creator>
			<guid isPermaLink="false">13639@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;the reduced code as suggested by gbulmer runs&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;void loop() {
  while (!CHECK_SCK_PIN); // wait for raising edge of the input clock
  OCK_PIN_LOW; // send output shown on scope 290ns to 512ns after the rising edge

  while (CHECK_SCK_PIN); // wait for falling edge
  // in the real thing there will be some more code here
  OCK_PIN_HIGH; // send output shown on scope 235ns to 445ns after the falling edge
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I read this result with a 72MHz cpu clock as&#60;br /&#62;
1st snippet is 21 to 37 cycles - this is a 16 cycles jitter&#60;br /&#62;
2nd snippet is 17 to 32 cycles - this is also a 16 cycles jitter&#60;/p&#62;
&#60;p&#62;in reality this would translate into about 4 cycles for loop() and 17 to 32 cycles while waiting for a transition and the output&#60;/p&#62;
&#60;p&#62;there are only 2 things that I can come up with as an explanation&#60;br /&#62;
1) interrupts that cannot be disabled&#60;br /&#62;
2) electrical noise on the input pin, board side&#60;/p&#62;
&#60;p&#62;any other ideas ?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "High-Speed GPIO Access?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=774&amp;page=3#post-13636</link>
			<pubDate>Tue, 11 Sep 2012 16:03:29 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">13636@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;hans leuthold - have you reduced the loop() to:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;void loop() {
  while (!CHECK_SCK_PIN); // wait for raising edge of the input clock
  OCK_PIN_LOW; // send output shown on scope 560ns to 700ns after the rising edge

  while (CHECK_SCK_PIN); // wait for falling edge
  // in the real thing there will be some more code here
  OCK_PIN_HIGH; // send output shown on scope 552ns to 700ns after the falling edge
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;What is the jitter? I'd expect it to be better. &#60;/p&#62;
&#60;p&#62;I'd expect the path length, i.e. the number of instruction, to differ in loop(), because of the &#60;code&#62;if&#60;/code&#62; tests.&#60;br /&#62;
This would show up as jitter. 140ns is about 10 instructions.&#60;/p&#62;
&#60;p&#62;You might try 'decompiling' the program using &#60;code&#62;objdump&#60;/code&#62;, which would let you see the number of ARM instructions&#60;br /&#62;
See the GCC binutils documentation &#60;a href=&#34;http://sourceware.org/binutils/docs-2.22/&#34; rel=&#34;nofollow&#34;&#62;http://sourceware.org/binutils/docs-2.22/&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;I was hacking with PDP-11's, and microprocessor development boards more than 30 years ago, but I don't think of myself as grandpa.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>hans leuthold on "High-Speed GPIO Access?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=774&amp;page=3#post-13631</link>
			<pubDate>Tue, 11 Sep 2012 14:11:46 +0000</pubDate>
			<dc:creator>hans leuthold</dc:creator>
			<guid isPermaLink="false">13631@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;- you are evidently right! - thanks&#60;/p&#62;
&#60;p&#62;after replacing all the digitalRead(xPIN) with a construct of the sort&#60;br /&#62;
#define CHECK_SCK_PIN ((GPIOB_BASE)-IDR &#38;amp; BIT(y))&#60;br /&#62;
the test code is able to follow a 700kHz clock and the jitter is about 140ns.&#60;/p&#62;
&#60;p&#62;I supply my maple board with a 5V phone charger and wondered whether this remaining jitter is somehow related to noise from the power supply. However supplying it through USB does not change anything.&#60;/p&#62;
&#60;p&#62;At this stage the loop() looks as follows below. All times are measured on a digital scope at 100MS/s with a 1000 event envelop triggered by the rising input clock. The input clock is a 5V amplitude square wave signal at 700kHz&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;#define ONEREV 31U
#define MAXVAL 4095U

uint16 erotable[ONEREV+1];
uint16 eroindex;
const uint16 onerev = ONEREV;
const uint16 maxval = MAXVAL;

void setup() {..... /initializes the pins, variables &#38;amp; table
}

void loop() {
  while (!CHECK_SCK_PIN); // wait for raising edge of the input clock
  eroindex++;
  eroindex &#38;amp;= onerev;
  // in the real thing there will be some more code here
  OCK_PIN_LOW; // send output shown on scope 560ns to 700ns after the rising edge

  while (CHECK_SCK_PIN); // wait for falling edge
  if (CHECK_BS_PIN) {  // bitstream is HIGH
    if(erotable[eroindex] &#38;lt; maxval)
      erotable[eroindex]++;
  }
  else { // bitstream is LOW
    if(erotable[eroindex] &#38;gt; 0)
      erotable[eroindex]--;

  // in the real thing there will be some more code here
  OCK_PIN_HIGH; // send output shown on scope 552ns to 700ns after the falling edge
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I was hacking with PCs and single board computers 25 years ago and have not done a lot since (..so now you know, I am more like your grandpa..) I really appreciate all the hints I have gotten so far and wonder why the timing I see is what it is. I expected both code snippets including the wait for transition to be between 15 and 20 clock cycles which is roughly half of what I measure.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ala42 on "High-Speed GPIO Access?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=774&amp;page=3#post-13519</link>
			<pubDate>Mon, 10 Sep 2012 19:50:35 +0000</pubDate>
			<dc:creator>ala42</dc:creator>
			<guid isPermaLink="false">13519@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;You have already noticed that digitalWrite is slow, but still use two digitalReads in your loop.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>hans leuthold on "High-Speed GPIO Access?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=774&amp;page=3#post-13517</link>
			<pubDate>Mon, 10 Sep 2012 19:08:49 +0000</pubDate>
			<dc:creator>hans leuthold</dc:creator>
			<guid isPermaLink="false">13517@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;- thanks: cutting interrupts reduced the jitter by over 80%&#60;/p&#62;
&#60;p&#62;now the test code is able to follow a 220kHz clock and the jitter is 680ns, this is still the equivalent of 49CPU clock cycles&#60;/p&#62;
&#60;p&#62;need to change over to programmable logic, I guess
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ala42 on "High-Speed GPIO Access?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=774&amp;page=3#post-13322</link>
			<pubDate>Fri, 07 Sep 2012 19:54:35 +0000</pubDate>
			<dc:creator>ala42</dc:creator>
			<guid isPermaLink="false">13322@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;#include &#34;nvic.h&#34;&#60;br /&#62;
...&#60;br /&#62;
nvic_globalirq_disable();
&#60;/p&#62;</description>
		</item>
		<item>
			<title>hans leuthold on "High-Speed GPIO Access?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=774&amp;page=2#post-13321</link>
			<pubDate>Fri, 07 Sep 2012 19:15:43 +0000</pubDate>
			<dc:creator>hans leuthold</dc:creator>
			<guid isPermaLink="false">13321@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;hi gbulmer,&#60;br /&#62;
I am scoping out a piece of code which should (once everything is ironed out) eliminate 2 stationary signals out of a bitstream, like a comb filter. The bitstream is clocked. The input clock SCK should in the end be around 500kHz.&#60;/p&#62;
&#60;p&#62;To test this out, a 80kHz digital signal is on pin 31, the main loop waits for the rising edge, executes some instructions, turns on the LED, then waits for the falling edge, executes some more instructions, turns off the LED, and exits.&#60;/p&#62;
&#60;p&#62;'&#60;br /&#62;
#define ONEREV 31U&#60;br /&#62;
#define SCK_PIN 31&#60;br /&#62;
#define BS_PIN 30&#60;/p&#62;
&#60;p&#62;#define OCK_PIN_HIGH (GPIOA_BASE)-&#38;gt;BSRR = BIT(5) // simulate using LED&#60;br /&#62;
#define OCK_PIN_LOW  (GPIOA_BASE)-&#38;gt;BRR  = BIT(5)&#60;/p&#62;
&#60;p&#62;int clockState = LOW;&#60;br /&#62;
uint16 erotable[ONEREV+1];&#60;br /&#62;
uint16 eroindex = 0;&#60;br /&#62;
const uint16 onerev = ONEREV;&#60;/p&#62;
&#60;p&#62;void setup() // does all the pin initializations and some prep work on tables&#60;/p&#62;
&#60;p&#62;void loop() {&#60;br /&#62;
  while((clockState = digitalRead(SCK_PIN)) == LOW);&#60;br /&#62;
  eroindex++;&#60;br /&#62;
  eroindex&#38;amp;=onerev;&#60;br /&#62;
  // the real thing will have some more code here..&#60;br /&#62;
  OCK_PIN_LOW;&#60;/p&#62;
&#60;p&#62;  while((clockState = digitalRead(SCK_PIN)) == HIGH);&#60;br /&#62;
  if ((bsState = digitalRead(BS_PIN)) == HIGH) {&#60;br /&#62;
    if (erotable[eroindex] &#38;lt; MAXVAL)&#60;br /&#62;
       erotable[eroindex]++;&#60;br /&#62;
  }&#60;br /&#62;
  else {  // bistream is LOW&#60;br /&#62;
    if (erotable[eroindex] &#38;gt; 0)&#60;br /&#62;
       erotable[eroindex]--;&#60;br /&#62;
  }&#60;br /&#62;
  // the real thing will have some more code here..&#60;br /&#62;
  OCK_PIN_HIGH;&#60;br /&#62;
}`&#60;/p&#62;
&#60;p&#62;I measure the timing with a scope that is triggered by the incoming clock signal. What I observed is that the time between a state change of the clock and the corresponding LED change is typically 0.6us for the rising edge and 1.5us for the falling edge. Either of these times may increase by as much as 3.9us sporadically.&#60;/p&#62;
&#60;p&#62;What I am trying to figure is whether there is a routine that would allow me to turn the interrupts you mention off.&#60;/p&#62;
&#60;p&#62;thanks&#60;br /&#62;
Hans
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "High-Speed GPIO Access?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=774&amp;page=2#post-13320</link>
			<pubDate>Fri, 07 Sep 2012 17:41:58 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">13320@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;hans leuthold - how are you measuring the loop time variability? &#60;/p&#62;
&#60;p&#62;There should be no variability in loop time because the instructions are constant and a fixed duration, but there are interrupts happening 'in the background' which may be measured as variability. &#60;/p&#62;
&#60;p&#62;Specifically, there is a clock interrupt which provides the underlying event for delay() and millis(), and there is also the USB interrupt. Both of these will increase the apparent time of some iterations of loop().&#60;/p&#62;
&#60;p&#62;(Full disclosure: I am not a member of LeafLabs staff.)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>hans leuthold on "High-Speed GPIO Access?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=774&amp;page=2#post-13319</link>
			<pubDate>Fri, 07 Sep 2012 16:22:19 +0000</pubDate>
			<dc:creator>hans leuthold</dc:creator>
			<guid isPermaLink="false">13319@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I ran a test to compare digitalWrite(bitX) with (GPIOy_BASE)-&#38;gt;BSRR = BIT(bitX). Using this more direct approach saves 0.3us or about 21 cpu clock cycles&#60;/p&#62;
&#60;p&#62;One question though - does anybody have some hints how to reduce the impact that the &#34;Arduino/Maple OS&#34; has on the execution time of loop()? My little test shows that loop times can vary by as much as 3.9us&#60;/p&#62;
&#60;p&#62;thanks&#60;br /&#62;
Hans
&#60;/p&#62;</description>
		</item>
		<item>
			<title>SDL on "High-Speed GPIO Access?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=774&amp;page=2#post-4930</link>
			<pubDate>Thu, 02 Jun 2011 01:41:15 +0000</pubDate>
			<dc:creator>SDL</dc:creator>
			<guid isPermaLink="false">4930@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi robodude666&#60;/p&#62;
&#60;p&#62;I don't know is it useful for you, but you may have a look and the stm's appnote:&#60;/p&#62;
&#60;p&#62;QVGA TFT-LCD direct drive&#60;br /&#62;
using the STM32F10xx FSMC peripheral&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/APPLICATION_NOTE/CD00278141.pdf&#34; rel=&#34;nofollow&#34;&#62;http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/APPLICATION_NOTE/CD00278141.pdf&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;They're using 16 bit line though and they get 40 fps for the static image but their lcd does not have an onboard memory.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "High-Speed GPIO Access?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=774&amp;page=2#post-4813</link>
			<pubDate>Thu, 26 May 2011 04:35:15 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">4813@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;I reviewed the ST documentation and they themselves say the GPIO cannot be toggled any faster than 18MHz. It is possible to get 36MHz, but that's for a single access. If you do two accesses back-to-back, the requests get buffered and are delayed by another instruction i.e.&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;I think it is important that the speed quoted is for changing the pin state twice because the instruction timing might mislead folks to thinking it is 2 cycles for the first write, then 1 for subsequent writes, which isn't the case. I read toggling as two state changes.&#60;/p&#62;
&#60;p&#62;Oak would be a way to drive this LCD at maximum speed, assuming Oak's FPGA could completely take over all the address, data and control pins. I would expect an FPGA to be significantly faster than 10Mpixels/second for things like drawing lines, and for 'bitblit' with fast memory.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "High-Speed GPIO Access?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=774&amp;page=2#post-4771</link>
			<pubDate>Tue, 24 May 2011 19:56:44 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">4771@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;good to know about single versus double transactions
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
