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

		<item>
			<title>gbulmer on "Is digitalWriteFaster interrupt compatible?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74349#post-105440</link>
			<pubDate>Mon, 16 Jun 2014 08:42:47 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">105440@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;jappiemike - I had a quick look at the version of &#60;code&#62;digitalWriteFaster&#60;/code&#62; here:&#60;br /&#62;
&#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=737&#38;amp;page=2#post-25150&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=737&#38;amp;page=2#post-25150&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Is this where you got the code?&#60;/p&#62;
&#60;p&#62;the bit-band-addresses for Maple's output and input pin 25 is not initialised!&#60;br /&#62;
The code is:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;#elif defined (BOARD_maple_RET6) &#124;&#124; defined(BOARD_maple)
...
BB_PERIPHERAL(-1, -1), // D25
...
BB_PERIPHERAL(-1, -1), // D25&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;using the Maple GPIO table at &#60;a href=&#34;http://leaflabs.com/docs/hardware/maple.html#maple-gpios&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/hardware/maple.html#maple-gpios&#60;/a&#62;&#60;br /&#62;
it should be:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;#elif defined (BOARD_maple_RET6) &#124;&#124; defined(BOARD_maple)
...
BB_PERIPHERAL(GPIOD_ODR, 2), // D25
...
BB_PERIPHERAL(GPIOD_IDR, 2), // D25&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;That seems to be the only one missing for Maple.&#60;br /&#62;
I've corrected the code for Maple on that thread, and raised an issue at github.&#60;br /&#62;
Maple mini looks okay.&#60;br /&#62;
Maple Native may still have un-initialised values.&#60;/p&#62;
&#60;p&#62;(Overlapped with your post, but still helpful, I hope)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jappiemike on "Is digitalWriteFaster interrupt compatible?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74349#post-105439</link>
			<pubDate>Mon, 16 Jun 2014 08:00:46 +0000</pubDate>
			<dc:creator>jappiemike</dc:creator>
			<guid isPermaLink="false">105439@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;So I had a quick look at the library and there are several pins or each type of board which have a (-1,-1) entry against them and D25 is one of those pins.  I'll keep that in mind when I use this library.&#60;br /&#62;
Thank you for your time and answers, as always, I learn so much from this forum's members.&#60;/p&#62;
&#60;p&#62;Mike
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Is digitalWriteFaster interrupt compatible?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74349#post-105438</link>
			<pubDate>Mon, 16 Jun 2014 04:52:05 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">105438@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;jappiemike - &#60;code&#62;digitalWriteFaster&#60;/code&#62; should be interrupt safe.&#60;/p&#62;
&#60;p&#62;It is very simple code. &#60;/p&#62;
&#60;p&#62;ARM Cortex support a technique called 'bit band addressing'. Specific address ranges, which include all the peripheral registers, also appear in a 'shadow' bit-band address range. The difference is, every &#60;strong&#62;bit&#60;/strong&#62; of the real address range appears in the bit-band address range as a different 32-bit word (only the bottom bit is used). So this is much quicker than the 'normal' way to set a bit. The normal approach loads a word (or byte) from the register (or memory) masks off the other bits and sets the required bit, then writes the word (or byte) back.&#60;/p&#62;
&#60;p&#62;Bit-band addressing just generates the bit address in the bit band region, and reads or writes the single-bit value (0 or 1).&#60;/p&#62;
&#60;p&#62;The digitalWriteFaster library pre-calculates all of the bit band addresses for the GPIO pins (at compile time) and stores them in an array/table, arranged so that the normal Maple pin numbers are used as an index. The only 'obvious' things that can go wrong are either using an illegal pin number, or the bit-band address in the table is wrong. I wrote the original illustrative code, but not the library. I haven't checked every value in the table.&#60;/p&#62;
&#60;p&#62;(Full disclosure: I am not a member of Leaflabs staff.)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jappiemike on "Is digitalWriteFaster interrupt compatible?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74349#post-105437</link>
			<pubDate>Mon, 16 Jun 2014 02:43:54 +0000</pubDate>
			<dc:creator>jappiemike</dc:creator>
			<guid isPermaLink="false">105437@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;After further investigation it appears that setting CLK to pin 25 is the problem, if I set it to 24 the program works fine. I haven't looked at the digital fast library yet.&#60;br /&#62;
Cheers&#60;br /&#62;
Mike
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jappiemike on "Is digitalWriteFaster interrupt compatible?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=74349#post-105436</link>
			<pubDate>Mon, 16 Jun 2014 00:39:34 +0000</pubDate>
			<dc:creator>jappiemike</dc:creator>
			<guid isPermaLink="false">105436@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello again,&#60;br /&#62;
in an attempt to speed up my LED matrix code I'm trying to use the digitalWriteFaster library but it appears to be crashing my board, which it an IteadMaple clone and uses a 103RBT6 chip and I'm using the REV3+ flash board setting in the IDE version 0.0.12.&#60;br /&#62;
Here is my code which is full of extra bits as I'm trying to test as much of my code as possible.&#60;br /&#62;
[code]&#60;br /&#62;
#include &#38;lt;digitalWriteFaster.h&#38;gt;&#60;br /&#62;
#define LED_RATE 10000   //  2800 is best rate&#60;/p&#62;
&#60;p&#62;volatile int tar[]={16,16,32,64,128,256,512,1024,2048};&#60;br /&#62;
volatile byte  bam;&#60;br /&#62;
const byte NUM_COLS=10;&#60;br /&#62;
const byte NUM_ROWS=10;&#60;br /&#62;
byte Matrix[NUM_ROWS][NUM_COLS];&#60;br /&#62;
const byte HB=14; // heartbeat LED&#60;br /&#62;
// CONNECTOR PINOUTS&#60;br /&#62;
const byte SDI = 23;   //pin 2 on the tlc5917 MISO&#60;br /&#62;
const byte CLK = 25;  //pin 3 on the tlc5917 SCLK&#60;br /&#62;
const byte LE =27; //pin 4 on the tlc5917 SS set LOW to latch data&#60;br /&#62;
const byte OE=29; //pin 13 on the tlc5917 OE set LOW to enable chip&#60;br /&#62;
// Positive Power&#60;br /&#62;
//Not Connected&#60;br /&#62;
const byte CLK64=31; // clock pin for row chip&#60;br /&#62;
const byte DATA64=32; //data pin for row chip and MOSFETS&#60;br /&#62;
/*&#60;br /&#62;
 RIGHT MSGEQ7 ANALOG OUT D2&#60;br /&#62;
 LEFT MSGEQ7 ANALOG OUT D3&#60;br /&#62;
 RIGHT STROBE D32&#60;br /&#62;
 LEFT STROBE D30&#60;br /&#62;
 Not Connected&#60;br /&#62;
 Negative Connection&#60;br /&#62;
 RIGHT RESET D33&#60;br /&#62;
 LEFT RESET D31&#60;br /&#62;
 */&#60;/p&#62;
&#60;p&#62;const byte lanalogPin = 15; // read from multiplexer using analog input 0&#60;br /&#62;
const byte lstrobePin = 16; // strobe is attached to digital pin 30&#60;br /&#62;
const byte lresetPin = 17; // reset is attached to digital pin 31&#60;br /&#62;
const byte ranalogPin = 18; // read from multiplexer using analog input 1&#60;br /&#62;
const byte rstrobePin = 19; // strobe is attached to digital pin 32&#60;br /&#62;
const byte rresetPin = 20; // reset is attached to digital pin 33&#60;br /&#62;
 HardwareTimer timer(3); // for ISR&#60;/p&#62;
&#60;p&#62;void setup()&#60;br /&#62;
{&#60;br /&#62;
//  Serial.begin(9600);&#60;br /&#62;
  pinMode(13, OUTPUT);&#60;br /&#62;
  pinMode(HB, OUTPUT);&#60;br /&#62;
  pinMode(SDI, OUTPUT);&#60;br /&#62;
  pinMode(CLK, OUTPUT);&#60;br /&#62;
  pinMode(LE, OUTPUT);&#60;br /&#62;
  pinMode(OE,OUTPUT);&#60;br /&#62;
  //pinMode(SRCLR,OUTPUT);&#60;br /&#62;
  pinMode(DATA64,OUTPUT);&#60;br /&#62;
  pinMode(CLK64,OUTPUT); &#60;/p&#62;
&#60;p&#62;  pinMode(lanalogPin, INPUT_ANALOG);&#60;br /&#62;
  pinMode(lstrobePin, OUTPUT);&#60;br /&#62;
  pinMode(lresetPin, OUTPUT);&#60;br /&#62;
  pinMode(ranalogPin, INPUT_ANALOG);&#60;br /&#62;
  pinMode(rstrobePin, OUTPUT);&#60;br /&#62;
  pinMode(rresetPin, OUTPUT);&#60;/p&#62;
&#60;p&#62;  // initialize Timer&#60;br /&#62;
  // Pause the timer while we're configuring it&#60;br /&#62;
  timer.pause();&#60;br /&#62;
  // Set up period&#60;br /&#62;
  timer.setPrescaleFactor(LED_RATE); // in microseconds&#60;br /&#62;
  // Set up an interrupt on channel 1&#60;br /&#62;
  timer.setChannel1Mode(TIMER_OUTPUT_COMPARE);&#60;br /&#62;
  timer.setCompare(TIMER_CH1, 1);  // Interrupt 1 count after each update&#60;br /&#62;
  timer.setOverflow(1280);&#60;br /&#62;
  timer.attachCompare1Interrupt(upDate);&#60;br /&#62;
  // Refresh the timer's count, prescale, and overflow&#60;br /&#62;
  timer.refresh();&#60;br /&#62;
  // Start the timer counting&#60;br /&#62;
  timer.resume();&#60;/p&#62;
&#60;p&#62;}               &#60;/p&#62;
&#60;p&#62;void loop()&#60;br /&#62;
{&#60;br /&#62;
  Matrix[random(9)][random(9)]=random(255);&#60;br /&#62;
  delay(100);&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;void upDate(void)&#60;br /&#62;
{&#60;br /&#62;
  digitalWriteFaster(HB,LOW);&#60;br /&#62;
    digitalWriteFaster(13,LOW);&#60;br /&#62;
  // move data from array to shift register chips&#60;br /&#62;
  // START OF PWM ROUTINE&#60;br /&#62;
  digitalWriteFaster(CLK64,LOW); // goto first row of LEDs&#60;br /&#62;
  digitalWriteFaster(DATA64,LOW);&#60;br /&#62;
  digitalWriteFaster(CLK64,HIGH);&#60;/p&#62;
&#60;p&#62;  for(byte rowCtr=0;rowCtr&#38;lt;NUM_ROWS;rowCtr++) // write a whole page of LEDs&#60;br /&#62;
  {&#60;br /&#62;
    for(byte y=0;y&#38;lt;NUM_COLS;y++)&#60;br /&#62;
    {&#60;br /&#62;
      for(byte x=0;x&#38;lt;3;x++)&#60;br /&#62;
      {&#60;br /&#62;
        digitalWriteFaster(CLK,LOW);&#60;br /&#62;
     /*   if(bitRead(Matrix[rowCtr][y],bam)==1) // turn on LED?&#60;br /&#62;
        {&#60;br /&#62;
          digitalWriteFaster(SDI,HIGH);&#60;br /&#62;
        }&#60;br /&#62;
        else&#60;br /&#62;
        {&#60;br /&#62;
          digitalWriteFaster(SDI,LOW);&#60;br /&#62;
        }*/&#60;br /&#62;
        digitalWriteFaster(CLK,HIGH);&#60;br /&#62;
        } // end x&#60;br /&#62;
     } // end y &#60;/p&#62;
&#60;p&#62;    digitalWriteFaster(LE,LOW);&#60;br /&#62;
    digitalWriteFaster(LE,HIGH); // latch data&#60;br /&#62;
    digitalWriteFaster(LE,LOW);&#60;br /&#62;
    digitalWriteFaster(OE,HIGH);&#60;br /&#62;
    digitalWriteFaster(OE,LOW);// turn on LEDs for the max time&#60;br /&#62;
    // Select next row of LEDs&#60;br /&#62;
    digitalWriteFaster(CLK64,LOW);&#60;br /&#62;
    digitalWriteFaster(DATA64,HIGH);&#60;br /&#62;
    digitalWriteFaster(CLK64,HIGH);&#60;/p&#62;
&#60;p&#62;  }// end rowCtr&#60;br /&#62;
 /* if(++bam&#38;gt;7) // change frequency of ISR for next page write&#60;br /&#62;
  {&#60;br /&#62;
    bam=0;&#60;br /&#62;
  }&#60;br /&#62;
  timer.setOverflow(tar[bam]);*/&#60;br /&#62;
  digitalWriteFaster(HB,HIGH);&#60;br /&#62;
    digitalWriteFaster(13,HIGH);&#60;br /&#62;
} // end ISR routine&#60;br /&#62;
[code]&#60;/p&#62;
&#60;p&#62;It works fine when I change the digitalWriteFaster to digitalWrite, the ISR takes .36ms to complete and there is a gap of 177ms between ISR calls so it's not tripping over it's own feet. I could learn how to write to the pins directly but I thought the library would save me the time.&#60;/p&#62;
&#60;p&#62;Cheers&#60;br /&#62;
Mike
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
