<?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: Maple Native getting HOT when operating transistors</title>
		<link>http://forums.leaflabs.com/topic.php?id=1184</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:07:19 +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=1184" rel="self" type="application/rss+xml" />

		<item>
			<title>gbulmer on "Maple Native getting HOT when operating transistors"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1184#post-7265</link>
			<pubDate>Wed, 30 Nov 2011 16:13:05 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">7265@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;rosendo&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;Although the second one has &#34;i&#34; and &#34;j&#34; while the first one has only &#34;state&#34;, I believe the second is better because &#34;i&#34; and &#34;j&#34; are 1 byte each, while &#34;state&#34; has 4 bytes.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;I think it is difficult to deduce much without looking in detail at the code generated by the compiler, and doing some measurements. I would definitely advise everybody to avoid jumping to conclusions, and get some evidence instead.&#60;/p&#62;
&#60;p&#62;if RAM is an issue, then:&#60;br /&#62;
&#60;code&#62;for (uint16 state = 0x0001;  state != 0;  state &#38;lt;&#38;lt;= 1) {&#60;/code&#62;&#60;br /&#62;
uses the same amount as:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;byte j=31;
for (byte i = 0; i &#38;lt; 16; i++) {&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;(One 4 byte variable would use less than two 1 byte variables if the compiler flag for 'word alignment of variables' is used.)&#60;/p&#62;
&#60;p&#62;My reading of RM0008 9.2.5 &#34;Port bit set/reset register (GPIOx_BSRR) (x=A..G)&#34; is all 16 bits in a port are cleared by a&#60;br /&#62;
&#60;code&#62;GPIOx_BASE-&#38;gt;BSRR = 0xffff0000;&#60;/code&#62;&#60;br /&#62;
but an assignment to one of the bottom 16 'set' bits takes precedence.&#60;/p&#62;
&#60;p&#62;So to set BIT(i) on, and clear every other bit, in a 16bit port:&#60;br /&#62;
&#60;code&#62;GPIOx_BASE-&#38;gt;BSRR = 0xffff0000 &#124; BIT(i);&#60;/code&#62;&#60;br /&#62;
would clear all 16 bits in the port except BIT(i).&#60;br /&#62;
There is no need for &#34;&#60;code&#62;BIT(i) &#124; BIT(j)&#60;/code&#62;&#34; or &#34;&#60;code&#62;state = 0x00010002&#60;/code&#62;&#34;.&#60;/p&#62;
&#60;p&#62;Redoing the bit-shifting version gives:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;void loop() {
    for (uint16 state = 0x0001;  state != 0;  state &#38;lt;&#38;lt;= 1) {
        GPIOD_BASE-&#38;gt;BSRR = 0xffff0000 &#124; state;  // clear all 16 bits, except the bit set by state
        GPIOE_BASE-&#38;gt;BSRR = 0xffff0000 &#124; state;
        GPIOF_BASE-&#38;gt;BSRR = 0xffff0000 &#124; state;
        GPIOG_BASE-&#38;gt;BSRR = 0xffff0000 &#124; state;
        delay(400);
    }
    GPIOD_BASE-&#38;gt;BSRR = 0xffff0000;  // switch all 16 port bits off
    GPIOE_BASE-&#38;gt;BSRR = 0xffff0000;
    GPIOF_BASE-&#38;gt;BSRR = 0xffff0000;
    GPIOG_BASE-&#38;gt;BSRR = 0xffff0000;

}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I haven't dumped the assembler, but I'd expect the bit-shift to be smaller than the code:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;void loop() {
    byte j=31;
    for (byte i = 0; i &#38;lt; 16; i++) {
        GPIOD_BASE-&#38;gt;BSRR = BIT(i) &#124; BIT(j);
        GPIOE_BASE-&#38;gt;BSRR = BIT(i) &#124; BIT(j);
        GPIOF_BASE-&#38;gt;BSRR = BIT(i) &#124; BIT(j);
        GPIOG_BASE-&#38;gt;BSRR = BIT(i) &#124; BIT(j);
        j = i+16;
        delay(400);
    }
    GPIOD_BASE-&#38;gt;BSRR = BIT(31);
    GPIOE_BASE-&#38;gt;BSRR = BIT(31);
    GPIOF_BASE-&#38;gt;BSRR = BIT(31);
    GPIOG_BASE-&#38;gt;BSRR = BIT(31);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;which I'd expect to be bigger because &#60;code&#62;BIT(i) &#124; BIT(j)&#60;/code&#62; expressions are calculated at run time, and it does &#60;code&#62;j+=16&#60;/code&#62; extra and 'i&#38;lt;16&#60;code&#62;instead of&#60;/code&#62;state != 0&#60;code&#62;. It is possible the compiler is smart enough to convert this counting version into bit shifting (and the compiler can be very smart, so I would need to examine the assembler to be sure). But it won&#38;#39;t know enough to convert to&#60;/code&#62;0xffff0000 &#124; BIT(i);`.&#60;/p&#62;
&#60;p&#62;Of course, if this code makes more sense to you, use it, but I don't think it is 'better' than bit-shifting in any technical sense.&#60;/p&#62;
&#60;p&#62;If we look at the assembler code generated, we might find that there are several other issues to consider before judging something 'better'.&#60;/p&#62;
&#60;p&#62;One which is potentially more important than RAM, is the number of registers consumed.&#60;br /&#62;
If i and j are stored in two registers, whereas state consumes one, the code sequence for a function using i and j may be bigger because the code might need to move register values back to memory to free-up registers more often, or the code needs to use 32-bit instructions to manage the registers.&#60;/p&#62;
&#60;p&#62;Further, slightly longer code inside a &#60;code&#62;for&#60;/code&#62; loop might force the compiler to use a different, larger instruction to branch back around a loop because a compact branch can't jump far enough.&#60;/p&#62;
&#60;p&#62;Summary: IMHO it is more important to write clear code, and measure performance if it becomes an issue, than making assumptions.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>rosendo on "Maple Native getting HOT when operating transistors"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1184#post-7261</link>
			<pubDate>Tue, 29 Nov 2011 22:23:53 +0000</pubDate>
			<dc:creator>rosendo</dc:creator>
			<guid isPermaLink="false">7261@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks for the advice! I will take a look and see if I can buy one of these!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>becker on "Maple Native getting HOT when operating transistors"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1184#post-7255</link>
			<pubDate>Mon, 28 Nov 2011 20:33:40 +0000</pubDate>
			<dc:creator>becker</dc:creator>
			<guid isPermaLink="false">7255@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I'm curious why you didn't select MOSFETs for the output drivers, instead of bipolar transistors.  Parts with a 2V or 2.5V threshold can be directly driven without dropping resistors, and consume essentially no power when not switching.&#60;/p&#62;
&#60;p&#62;Admittedly the best parts are available only in SO8 and smaller packages, but you can find acceptable through-hole parts.&#60;/p&#62;
&#60;p&#62;Better, search for &#34;inductive load drivers&#34; which include gate protection and an internal zener diode pair to handle the turn-off 'freewheel' spike.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>rosendo on "Maple Native getting HOT when operating transistors"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1184#post-7240</link>
			<pubDate>Thu, 24 Nov 2011 21:20:21 +0000</pubDate>
			<dc:creator>rosendo</dc:creator>
			<guid isPermaLink="false">7240@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer, I used your solution to create a &#34;One bit at a time&#34; solution, which is as follows (Just remember that before using it YOU SHOULD COMMENT THE FLASH.LD FILE to free the SRAM from the output pins)&#60;/p&#62;
&#60;p&#62;void loop() {&#60;br /&#62;
    //delay(30);&#60;br /&#62;
    for (unsigned int state = 0x00010002;  state != 0x80010000;  state &#38;lt;&#38;lt;= 1) {&#60;br /&#62;
      GPIOD_BASE-&#38;gt;BSRR = state;&#60;br /&#62;
      GPIOE_BASE-&#38;gt;BSRR = state;&#60;br /&#62;
      GPIOF_BASE-&#38;gt;BSRR = state;&#60;br /&#62;
      GPIOG_BASE-&#38;gt;BSRR = state;&#60;br /&#62;
      delay(200);&#60;br /&#62;
    }&#60;br /&#62;
    GPIOD_BASE-&#38;gt;BSRR = 0xf0000001;&#60;br /&#62;
    GPIOE_BASE-&#38;gt;BSRR = 0xf0000001;&#60;br /&#62;
    GPIOF_BASE-&#38;gt;BSRR = 0xf0000001;&#60;br /&#62;
    GPIOG_BASE-&#38;gt;BSRR = 0xf0000001;&#60;br /&#62;
    delay(200);&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;In which I could also compare to another fast writing method:&#60;/p&#62;
&#60;p&#62;void loop() {&#60;br /&#62;
  byte j=31;&#60;br /&#62;
  for (byte i = 0; i &#38;lt; 16; i++) {&#60;br /&#62;
    GPIOD_BASE-&#38;gt;BSRR = BIT(i) &#124; BIT(j);&#60;br /&#62;
    GPIOE_BASE-&#38;gt;BSRR = BIT(i) &#124; BIT(j);&#60;br /&#62;
    GPIOF_BASE-&#38;gt;BSRR = BIT(i) &#124; BIT(j);&#60;br /&#62;
    GPIOG_BASE-&#38;gt;BSRR = BIT(i) &#124; BIT(j);&#60;br /&#62;
    j = i+16;&#60;br /&#62;
    delay(400);&#60;br /&#62;
  }&#60;br /&#62;
  GPIOD_BASE-&#38;gt;BSRR = BIT(31);&#60;br /&#62;
  GPIOE_BASE-&#38;gt;BSRR = BIT(31);&#60;br /&#62;
  GPIOF_BASE-&#38;gt;BSRR = BIT(31);&#60;br /&#62;
  GPIOG_BASE-&#38;gt;BSRR = BIT(31);&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;Although the second one has &#34;i&#34; and &#34;j&#34; while the first one has only &#34;state&#34;, I believe the second is better because &#34;i&#34; and &#34;j&#34; are 1 byte each, while &#34;state&#34; has 4 bytes. I hope this is useful for anybody that wishes to use all these 62 pins offered by Ports DEFG, leaving Ports A and B for Analog Input and C for the SDcard.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>rosendo on "Maple Native getting HOT when operating transistors"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1184#post-7239</link>
			<pubDate>Thu, 24 Nov 2011 20:14:21 +0000</pubDate>
			<dc:creator>rosendo</dc:creator>
			<guid isPermaLink="false">7239@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer, I forgot to delete the last &#34;b&#34; from that stateb, but I already tried your solution and works like a charm! Thank you, man!&#60;/p&#62;
&#60;p&#62;Now I'm operating 32 valves and the chip is warmer than when it is off (which I believe is natural). The book looks interesting and I`m really thinking about buying it.&#60;/p&#62;
&#60;p&#62;Thanks so much man, and I wish there were more tutorials on how to use all these outputs that this board has to offer. There are not so many boards with 100+ outputs around the internet.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Maple Native getting HOT when operating transistors"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1184#post-7238</link>
			<pubDate>Thu, 24 Nov 2011 18:20:28 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">7238@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;rosendo - A good source for Electronic Design is The Art of Electronics, by Paul Horowitz and Winfield Hill:&#60;br /&#62;
&#60;a href=&#34;http://en.wikipedia.org/wiki/The_Art_of_Electronics&#34; rel=&#34;nofollow&#34;&#62;http://en.wikipedia.org/wiki/The_Art_of_Electronics&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;They recommend that you don't skimp on base current, because if you are using a transistor as a switch, you want it to switch quickly. Switching slowly will have the device in an 'in between' state (not fully on, or fully off) where it dissipates more heat.&#60;/p&#62;
&#60;p&#62;I think tcd218's calculations are likely accurate, but if the transistors are getting hot, you might want to *reduce* the base-resitance to see if the transistors need to be driven faster.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Maple Native getting HOT when operating transistors"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1184#post-7237</link>
			<pubDate>Thu, 24 Nov 2011 18:09:20 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">7237@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;rosendo - does that code actually work? Maybe you have pasted the wrong version?&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;void loop() {
    for (int i = 0; i &#38;lt; 32; i++) {
        GPIOD_BASE-&#38;gt;BSRR = state;
        GPIOE_BASE-&#38;gt;BSRR = state;
        GPIOF_BASE-&#38;gt;BSRR = state;
        GPIOG_BASE-&#38;gt;BSRR = state;
        stateb &#38;lt;&#38;lt;= 1; //Changing the state moving one bit to the side
        delay(20);
    }
    if(int i=32){
        //state = 0x00000001;
    }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;&#60;code&#62;stateb&#60;/code&#62; isn't declared, so the compiler should print an error, and give up, never loading the program into your Maple.&#60;br /&#62;
Further, &#60;code&#62;stateb &#38;lt;&#38;lt;= 1;&#60;/code&#62; isn't effecting any of the output pins, because they all use &#60;code&#62;state&#60;/code&#62;, so the pattern should not change.&#60;br /&#62;
Also the test &#60;code&#62;if(int i=32)&#60;/code&#62; is always true ...&#60;/p&#62;
&#60;p&#62;IMHO, a more elegant approach might be something like:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;void loop() {
    for (unsigned int state = 0x00000001;  state != 0;  state &#38;lt;&#38;lt;= 1) {
        GPIOD_BASE-&#38;gt;BSRR = state;
        GPIOE_BASE-&#38;gt;BSRR = state;
        GPIOF_BASE-&#38;gt;BSRR = state;
        GPIOG_BASE-&#38;gt;BSRR = state;
        delay(20);
    }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;&#60;code&#62;for&#60;/code&#62; loops aren't restricted to counting, any expressions can be used to update variables.&#60;br /&#62;
(WARNING: I haven't compiled and checked that code)&#60;/p&#62;
&#60;p&#62;(full disclosure: I am not a member of LeafLabs staff.)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>rosendo on "Maple Native getting HOT when operating transistors"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1184#post-7232</link>
			<pubDate>Thu, 24 Nov 2011 00:14:08 +0000</pubDate>
			<dc:creator>rosendo</dc:creator>
			<guid isPermaLink="false">7232@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks man! I could prove that this board is dumb-proof! If it still didn&#60;code&#62;t blow up with me, it won&#60;/code&#62;t blow with anybody else!&#60;/p&#62;
&#60;p&#62;I tried 1.2 k and it worked fine! There are no snubbers here and I will leave like this for a while. If some transistor blows up, I`ll think about it!&#60;/p&#62;
&#60;p&#62;Just in case it is helpful for anybody, the commenting at the flash.ld file was:&#60;/p&#62;
&#60;p&#62;/* Commented to avoid using the external RAM&#60;br /&#62;
_lm_heap_start = 0x60000000;&#60;br /&#62;
_lm_heap_end = 0x60100000;*/&#60;/p&#62;
&#60;p&#62;Usually this part is not commented, so doing this will avoid using the 1Mb RAM, allowing you to use the 56-100 GPIO.&#60;/p&#62;
&#60;p&#62;For the programming I`m using fast GPIO writing:&#60;/p&#62;
&#60;p&#62;int state = 0x00000001;  //This is just an integer with which I change the states of outputs&#60;/p&#62;
&#60;p&#62;void setup() {&#60;br /&#62;
    for (int i = 56; i &#38;lt; 101; i++) {    //Just telling the board that I will output throughout the FSMC&#60;br /&#62;
        // initialize the output pins:&#60;br /&#62;
        pinMode(i, OUTPUT);&#60;br /&#62;
    }&#60;/p&#62;
&#60;p&#62;void loop() {&#60;br /&#62;
  for (int i = 0; i &#38;lt; 32; i++) {&#60;br /&#62;
    GPIOD_BASE-&#38;gt;BSRR = state;&#60;br /&#62;
    GPIOE_BASE-&#38;gt;BSRR = state;&#60;br /&#62;
    GPIOF_BASE-&#38;gt;BSRR = state;&#60;br /&#62;
    GPIOG_BASE-&#38;gt;BSRR = state;&#60;br /&#62;
  stateb &#38;lt;&#38;lt;= 1;  //Changing the state moving one bit to the side&#60;br /&#62;
    delay(20);&#60;br /&#62;
  }&#60;br /&#62;
  if(int i=32){&#60;br /&#62;
  //state = 0x00000001;&#60;br /&#62;
  }&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;Thanks for the help tdc218, and for the guys in Maple thanks for the board (and the candy!)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>tdc218 on "Maple Native getting HOT when operating transistors"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1184#post-7231</link>
			<pubDate>Wed, 23 Nov 2011 23:46:33 +0000</pubDate>
			<dc:creator>tdc218</dc:creator>
			<guid isPermaLink="false">7231@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;2k would probably be fine.  Here's some transistor design 101:&#60;/p&#62;
&#60;p&#62;According to the C1815 data sheet, it has the following characteristics:&#60;br /&#62;
Maximum collector current:  150mA (.15A)&#60;br /&#62;
Minimum gain:  70&#60;br /&#62;
Base-Emitter saturation voltage 1v&#60;/p&#62;
&#60;p&#62;So, Ohm's law is R=E/I&#60;/p&#62;
&#60;p&#62;The minimum base current we need is .15/70 = .00214A (2.14ma).  This is I&#60;br /&#62;
The voltage is the output voltage of the Maple 3.3v - the B-E voltage of the transistor 1v = 2.3v&#60;/p&#62;
&#60;p&#62;R = 2.3 / .00214 = 1075 ohms.  1k might be better, however in most cases you won't be drawing the max current of the transistor (I hope) and it's gain will be higher than minimum, so a higer resistor, like your 2k, would be fine.&#60;/p&#62;
&#60;p&#62;And just because I'm an electronics geek from way back, do you have snubbers on your pneumatic valves to protect the transistor from the voltage spike when it turns off?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>rosendo on "Maple Native getting HOT when operating transistors"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1184#post-7230</link>
			<pubDate>Wed, 23 Nov 2011 23:34:47 +0000</pubDate>
			<dc:creator>rosendo</dc:creator>
			<guid isPermaLink="false">7230@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hehehe... No, I didn't. Accepting suggestions! 2k is ok?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>tdc218 on "Maple Native getting HOT when operating transistors"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1184#post-7229</link>
			<pubDate>Wed, 23 Nov 2011 23:33:24 +0000</pubDate>
			<dc:creator>tdc218</dc:creator>
			<guid isPermaLink="false">7229@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;You do have a resistor between the output pin of the Maple and the base of the transistor, don't you?  If you don't, you need one and I'm surprised you haven't blown anything up yet.  If you do, what value is it?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>rosendo on "Maple Native getting HOT when operating transistors"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1184#post-7228</link>
			<pubDate>Wed, 23 Nov 2011 22:59:03 +0000</pubDate>
			<dc:creator>rosendo</dc:creator>
			<guid isPermaLink="false">7228@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;As we all know Maple Native has many GPIO pins. Although some are related to the SRAM, I could manage to &#34;unleash&#34; them by modifying the flash.ld file, so that only the internal 64k RAM is used. (There is some post on this forum about it, and it works!)&#60;/p&#62;
&#60;p&#62;Happy for seeing all my 3.3V outputs working at the same time and the program still running, I decided I wanted to operate my 12V pneumatic valves, so I plugged 32 of these bad boys to 32 transistors and while the valves are working just fine I touched the ARM chip and he was really HOT! I could`t leave my finger on it for more than 1 sec!&#60;/p&#62;
&#60;p&#62;So I thought that maybe I screwed up and used the PORTC (pins 7-22) to operate only 16 of them, and it was still HOT (less hot than before, but still pretty HOT).&#60;/p&#62;
&#60;p&#62;Since the first trial was at some circuit board, I thought that maybe I did something wrong. Then I changed to my breadboard and still HOT. &#60;/p&#62;
&#60;p&#62;The battery is cold and the transistor I`m using is C1815. Am I doing anything wrong or the microcontroller really gets this hot?
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
