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

		<item>
			<title>bnewbold on "HardwareTimer refactor"</title>
			<link>http://forums.leaflabs.com/topic.php?id=153#post-1014</link>
			<pubDate>Sun, 05 Sep 2010 18:21:33 +0000</pubDate>
			<dc:creator>bnewbold</dc:creator>
			<guid isPermaLink="false">1014@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I don't think we're going to make any modifications to the silkscreen any time soon, though we are putting together a reference card/cheatsheet that could indicate the mapping.&#60;/p&#62;
&#60;p&#62;I agree that a getHardwareTimer function would be very helpful.&#60;/p&#62;
&#60;p&#62;The C timers code is so large because it's crudely written with lots of case/switch branching, which results in additional code size with no speed gains. Regardless of changes to the C++ interface I will refactor this code (maintaining the C api) which should reduce code size.&#60;/p&#62;
&#60;p&#62;W/R/T the performance of table lookups, the performance penalty would be the same as with the other C++ pin-specific functions, and I think it's on the order of the function calls down to the C functions. If the either overhead is too great, advanced users can always use the C functions directly (especially when writing libraries, which seem to be the most performance dependent). I think the performance overhead of the table lookup is proportionally small, but I would benchmark this before committing to a new API.&#60;/p&#62;
&#60;p&#62;It's true that users would still have to check a table to make sure their timer-wide configuration isn't conflicting with any PWM configuration, but I think this amounts to much less &#34;table checking&#34;. They don't need to know what the timer their chosen output-compare channel is on, just that it doesn't conflict with the PWM timer. &#60;/p&#62;
&#60;p&#62;I'll think this all through some more and post an actual proposal before changing the C++ API (feel free to propose your own!).
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "HardwareTimer refactor"</title>
			<link>http://forums.leaflabs.com/topic.php?id=153#post-991</link>
			<pubDate>Sat, 04 Sep 2010 08:07:53 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">991@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;sniglen, very good point, I wrote without enough thought.&#60;/p&#62;
&#60;p&#62;The important point to me is that the user can get much  of the important information from the silkscreen on the board, and the functions are easy to use.&#60;/p&#62;
&#60;p&#62;PWM output is fine with pinMode(pin_num, PWM), and pwmWrite(pin_num, value).&#60;br /&#62;
From my perspective that is very slightly better than analogWrite, which needs a bit of explanation about why it isn't the same as 'proper' digital to analogue conversion on an Arduino.&#60;/p&#62;
&#60;p&#62;So I agree with sniglen, the majority of the remaining timer functionality corresponds to the timer's and not the channels.&#60;/p&#62;
&#60;p&#62;There seems little point having an array of timers, e.g. Timer[1]. setCount(...) because some STM32F timers have different functionality, which may show up in different class interfaces.&#60;/p&#62;
&#60;p&#62;So, some of my issues would be fixed by adding to the silk screen the mapping from PWM pin to Timer. I don't mind how (very much), it could be an extra annotation next to each PWM pin, e.g. PWM(T1) or PWM(Timer1, ... or in a table.&#60;/p&#62;
&#60;p&#62;In the code, it might be useful to have a function, which returns the Hardware Timer which corresponds to a pin number, e.g.:&#60;/p&#62;
&#60;p&#62;HardwareTimer&#38;amp; getHardwareTimer(pin_num);&#60;br /&#62;
or&#60;br /&#62;
HardwareTimer* getHardwareTimer(pin_num);&#60;/p&#62;
&#60;p&#62;So I could write code like:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;pinMode(LED1, PWM);
getHardwareTimer(LED1)-&#38;gt;setOverflow(BLINKRATE);
pwmWrite(LED1, BLINKRATE/4);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Not perfect, but it gets the idea across&#60;/p&#62;
&#60;p&#62;I could even check in my code if pins might share a timer, and hence 'be in conflict':&#60;br /&#62;
&#60;code&#62;if (getHardwareTimer(LED1) == getHardwareTimer(SERVO1)) { ... }&#60;/code&#62;&#60;br /&#62;
I'd be happy to have macros at compile time too, but I'd like the run time function, so that I can do dynamic stuff similar to my first LED1 example.&#60;/p&#62;
&#60;p&#62;There is still some channel related functionality, such as getting the captured value when using a pin as an input capture channel. IMHO, these should be done by pin, though they could also be done by Timer1/TImer2/ etc. methods too.&#60;/p&#62;
&#60;p&#62;Summary.&#60;br /&#62;
I humbly withdraw my support for the change.&#60;br /&#62;
Propose a small annotation on the silkscreen, to give pin_number to Timer documentation on the Maple itself.&#60;br /&#62;
'Nice to have' a function to map to the right timer from a pin.&#60;br /&#62;
Channel related functionality, like input-capture to be &#60;em&#62;at least&#60;/em&#62; pin_number based, could be timer based too.&#60;/p&#62;
&#60;p&#62;PS - why are the timers so huge?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>snigelen on "HardwareTimer refactor"</title>
			<link>http://forums.leaflabs.com/topic.php?id=153#post-984</link>
			<pubDate>Sat, 04 Sep 2010 02:53:09 +0000</pubDate>
			<dc:creator>snigelen</dc:creator>
			<guid isPermaLink="false">984@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi,&#60;/p&#62;
&#60;p&#62;I understand what you mean by &#34;Arduino-ish&#34;, but there is no way to do this in the &#34;Arduino language&#34; (Of course you can do &#34;TCNT1 = 123&#34;, but thats a on lower level). And the &#60;/p&#62;
&#60;p&#62;&#38;gt; Timers.setCount(D12, 200); // Changed to D12, there is no PWM on D13 :-)&#60;/p&#62;
&#60;p&#62;construct gives the impression that a timer is bound to one pin, when it in fact can be bound to 0-4 pins. And it hides the fact that this statement will affect up to four pins.&#60;br /&#62;
And it isn't really that hard to look up the timer to pin-map in the pwm documentation on this site.&#60;br /&#62;
So I'm with CarlO here, keep it like it is now. Timers can be used for more things than just PWM.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "HardwareTimer refactor"</title>
			<link>http://forums.leaflabs.com/topic.php?id=153#post-982</link>
			<pubDate>Fri, 03 Sep 2010 21:05:49 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">982@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;I'm thinking about refactoring the Timer system to be pin-based instead of timer/compare based. Having so many different functions is really clunky and it would be pretty easy to just lookup the necessary info in a table so that, for instance, you could write:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;Timers.setCount(D13, 200);&#60;/code&#62;&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;I like your proposal.&#60;br /&#62;
The Timer1, Timer2, etc. is so clunky &#60;em&#62;I&#60;/em&#62; am put off (and I read the STM32F manuals most days of the week, if I can't get to sleep:-).&#60;/p&#62;
&#60;p&#62;As you say the proposal is much more &#34;Arduino-ish&#34;, i.e. key documentation is on the Maple's silkscreen for the pins, and users don't need to go digging through STM32F manuals, and trying to map to the Maple headers.&#60;/p&#62;
&#60;p&#62;Having said that, I do appreciate CarlO's point. I sometimes end up writing my own functions for the Arduino to get performance by side-stepping the framework. But, I can do that, and it's often quite easy when the library source code is available.&#60;/p&#62;
&#60;p&#62;It would be nice to have the two layers that CarlO describes, but if there is a near-term compromise, make the 'public', 'Arduino-like' interface simple and easy to use.&#60;/p&#62;
&#60;p&#62;My $0.02
&#60;/p&#62;</description>
		</item>
		<item>
			<title>CarlO on "HardwareTimer refactor"</title>
			<link>http://forums.leaflabs.com/topic.php?id=153#post-971</link>
			<pubDate>Fri, 03 Sep 2010 01:38:31 +0000</pubDate>
			<dc:creator>CarlO</dc:creator>
			<guid isPermaLink="false">971@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;bnewbold&#60;/p&#62;
&#60;p&#62;My vote would be to not break the current functions.  Can't you wrap the current functions with higher level functions that can do the pin look-up and set pin modes etc?  One of the things I have noticed on the Arduino, is that the abstraction to pin numbers comes at a cost in speed.  It takes time to do the look-up and check/set the pin mode with every call.  If for example you wanted to modify your timer count frequently in your sketch, every time you set the count to a new value, the framework code still has all the overhead of looking up the timer, setting the pin mode etc, rather than just setting a new value in the timer register.&#60;/p&#62;
&#60;p&#62;CarlO.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bnewbold on "HardwareTimer refactor"</title>
			<link>http://forums.leaflabs.com/topic.php?id=153#post-963</link>
			<pubDate>Thu, 02 Sep 2010 19:46:52 +0000</pubDate>
			<dc:creator>bnewbold</dc:creator>
			<guid isPermaLink="false">963@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I'm thinking about refactoring the Timer system to be pin-based instead of timer/compare based. Having so many different functions is really clunky and it would be pretty easy to just lookup the necessary info in a table so that, for instance, you could write:&#60;/p&#62;
&#60;p&#62;Timers.setCount(D13, 200);&#60;/p&#62;
&#60;p&#62;I could create macro aliases like TIMER2_COMPARE4 so one could still use timers without having to look up which pins are associated with timers.&#60;/p&#62;
&#60;p&#62;This would make it much clearer which pins would possibly be in conflict, and help save a huge amount of memeory (the timers are a few kb right now, most peripherals are a few hundred bytes). This also strikes me as more &#34;Arduino-ish&#34;. &#60;/p&#62;
&#60;p&#62;Any thoughts? This change would break any code built on top of the HardwareTimer system right now, though it should be possible to release the current version as a library for compatibility.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
