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

		<item>
			<title>mbolivar on "the future of HardwareTimer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=794#post-4957</link>
			<pubDate>Fri, 03 Jun 2011 15:07:28 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">4957@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer,&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
None of this requires a timer class, or creating a timer instance.
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;I like that.  Sounds like a good way to start moving forward.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "the future of HardwareTimer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=794#post-4876</link>
			<pubDate>Sun, 29 May 2011 20:11:43 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">4876@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;blockquote&#62;I think a nice solution would use both the Arduino output pin-number method to identify the channel (no I/O remapping supported), and expose the timer itself as a thing (a little bit of overloading?).&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;sorry, not sure what you mean here. are you saying that e.g. we would control the capture/compare value for a channel via the pin number that the channel is attached to? i'm not sure that that's distinct enough from pwmWrite().&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Assuming this is restricted to an 'Arduino-like timer', with no alternate-pin-mapping (this is for quick, simple stuff and beginners). &#60;/p&#62;
&#60;p&#62;The timer carries the pre-scaler and 'autoreload' value, so that could be deduced from a pin number.&#60;br /&#62;
Then timer output compare is unique to a pin for things like pwmWrite().&#60;/p&#62;
&#60;p&#62;I was thinking along the lines of the usual Arduino library function &#60;code&#62;pwmWrite(int pin, int value);&#60;/code&#62;&#60;br /&#62;
With either overloading for a tastefully chosen class-type which represents the timer itself, or 'magic pin numbers' (could be negative or large pin numbers?)&#60;br /&#62;
for timer-specific functionality like the counter prescaler or counter autoreload.&#60;/p&#62;
&#60;p&#62;I think a class-based timer is more complex than necessary for the purpose I'm suggesting.&#60;br /&#62;
I don't need to introduce the idea of a timer which has multiple channels to a beginner. I just introduce pwm, and initially treat the frequency and range as fixed.&#60;/p&#62;
&#60;p&#62;A key problem with timer-class-based timer is it is an unnecessary level of indirection for beginners.&#60;br /&#62;
Each timer has upto 4 output pins, how do folks get from timer 6 to the output pins?&#60;br /&#62;
IMHO, that is extra complexity, and not KISS.&#60;/p&#62;
&#60;p&#62;IMHO, it is easier base it on the simple Arduino approach e.g. &#60;code&#62;pwmWrite(pin, value);&#60;/code&#62;&#60;br /&#62;
The concept of a timer is only necessary when setting the prescaler or autoreload.&#60;/p&#62;
&#60;p&#62;That seems pretty simple to encapsulate in either 'magic' pin numbers, or a class, and derive a value from a pin number.&#60;br /&#62;
&#60;code&#62;... pwmTimer = pin_to_pwm_timer(pin);&#60;/code&#62;&#60;br /&#62;
&#60;code&#62;set_pwm_timer_prescaler(pwmTimer, 72);&#60;/code&#62;&#60;br /&#62;
&#60;code&#62;set_pwm_timer_maxcount(pwmTimer, 1000);&#60;/code&#62;   // autoreload is a poor name&#60;/p&#62;
&#60;p&#62;None of this requires a timer class, or creating a timer instance. &#34;Simples (squeak :-)&#34;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "the future of HardwareTimer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=794#post-4824</link>
			<pubDate>Thu, 26 May 2011 15:02:18 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">4824@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;sorry, didn't answer your question.&#60;/p&#62;
&#60;p&#62;AdvancedTimer would be used to control TIMER1 (and TIMER8 on high-density boards).  those are pretty awesome timers, with all sorts of cool functionality.  for example, they can do complementary outputs with dead time insertion, and it may be worthwhile to include a Wirish API for that.&#60;/p&#62;
&#60;p&#62;however, that capability is limited to timers 1 and 8.  similarly, timers 6 and 7 don't have capture/compare channels.  i don't want to break the interface up just to make learning easier (although that's a great bonus).  it's that there are actually three different kinds of timer hardware on the STM32, so it doesn't make sense to have one giant timer class that represents the union of all of their capabilities.&#60;/p&#62;
&#60;p&#62;anyway, limiting it to 3 is a little bit of an oversimplification as well, since timers 10, 11, 13, and 14 are given as &#34;general purpose&#34;, but only have one capture/compare channel, unlike timers 2, 3, 4, 5, 9, and 12, which have 4.  but as you say, i don't want the APIs to blow up and get completely out of control unnecessarily.  instead, i was thinking the docs could just clearly state this sort of restriction on the less full-featured general purpose timers.&#60;/p&#62;
&#60;p&#62;edit: typo
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "the future of HardwareTimer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=794#post-4822</link>
			<pubDate>Thu, 26 May 2011 14:45:25 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">4822@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;sure, HardwareTimer mostly just calls out to timer_foo functions.  the point is that there are many of those, and their number is only going to keep growing.  the complexity i'm saying we should hide is not the HardwareTimer wrapper, it's timer.h itself.&#60;/p&#62;
&#60;p&#62;having a SimpleTimer allows writing documentation which just presents those very basic pieces of functionality that will probably be enough for most people's purposes.&#60;/p&#62;
&#60;p&#62;personally, i often feel overwhelmed when i first open up a large API listing.  it's sometimes enough to drive me away from the interface altogether.  having a tiny SimpleTimer class with just the basics is more encouraging and beginner-friendly, at least in my mind.&#60;/p&#62;
&#60;p&#62;edit: spelling
&#60;/p&#62;</description>
		</item>
		<item>
			<title>robodude666 on "the future of HardwareTimer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=794#post-4821</link>
			<pubDate>Thu, 26 May 2011 14:34:40 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">4821@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I don't see the complexity behind the current &#60;code&#62;HardwareTimer&#60;/code&#62; class. It's just a wirish class wrapper for the c functions libmaple has to control the different aspects of the timers. Most methods in the &#60;code&#62;HardwareTimer&#60;/code&#62; class simply call one c function. The most complex one calculates the overflow/prescaler required to reach a certain period, which in itself is not very complex. I'm not understanding the benefit of breaking HardwareTimer into 3 different classes, making the API more complicated.&#60;/p&#62;
&#60;p&#62;In your &#60;code&#62;SimpleTimer&#60;/code&#62; example you haven't done anything different than what &#60;code&#62;HardwareTimer&#60;/code&#62; already can do very easily. Could you provide some examples of what the &#60;code&#62;BasicTimer&#60;/code&#62; or &#60;code&#62;AdvancedTimer&#60;/code&#62; would look like and how they'd be used?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "the future of HardwareTimer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=794#post-4820</link>
			<pubDate>Thu, 26 May 2011 14:28:32 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">4820@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer,&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
For example, pwmWrite would stay, and add its counterparts for setting the counter prescaler, overflow/reload and resetting it. It would have an interrupt service routine too. This would be an Arduino-like C-function interface.&#60;/p&#62;
&#60;p&#62;In the spirit of KISS 'keep it simple', I think that is all that the intersection of timer functionality contains.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;that's an interesting idea, and one that i hadn't thought of.  that seems like it would make an excellent first step on the learning curve.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
I think that is enough for a lot of uses of timers.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;i very much agree.  make simple things easy, after all.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
I think a nice solution would use both the Arduino output pin-number method to identify the channel (no I/O remapping supported), and expose the timer itself as a thing (a little bit of overloading?).
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;sorry, not sure what you mean here.  are you saying that e.g. we would control the capture/compare value for a channel via the pin number that the channel is attached to?  i'm not sure that that's distinct enough from pwmWrite().  as far as input capture is concerned, i do think it's a cool idea to extend pulseIn() via some overloading magic into a pulseIn(pin) that used timers for extra precision (the arduino implementation just busy-waits and uses micros()).  so if that's in line with what you're suggesting, i like it :).&#60;/p&#62;
&#60;p&#62;you're right that i should be more clear in what i've been imagining might make a better interface.  i was thinking of at least three separate timer classes; which for the purposes of this post i'll call SimpleTimer, Timer, and AdvancedTimer, corresponding respectively to basic, general purpose, and advanced STM32 timers.&#60;/p&#62;
&#60;p&#62;i was imagining that SimpleTimer would contain the basic interface that you described.  for instance, you'd be able to make the following blinky sketch (on the RET6 edition):&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;SimpleTimer timer(6); // grab a SimpleTimer wrapper around TIMER6

void setup() {
    // Configure LED
    pinMode(BOARD_LED_PIN, OUTPUT);

    // Configure prescaler and overflow for 10 ms period
    timer.setPeriod(10);
    timer.attachInterrupt(handler);
}

void loop() {
}

void handler() {
    toggleLED();
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;you may notice that this accomplishes the same goal as, but is far simpler than, the Arduino BlinkWithoutDelay tutorial example:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay&#34; rel=&#34;nofollow&#34;&#62;http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;i agree that the SimpleTimer interface should be extremely limited.  these are the methods i think are appropriate:&#60;/p&#62;
&#60;p&#62;void setPeriod(milliseconds)&#60;br /&#62;
void setPrescaler(prescaler)&#60;br /&#62;
void setOverflow(overflow)&#60;br /&#62;
void attachInterrupt(handler)&#60;br /&#62;
void detachInterrupt()&#60;br /&#62;
void refresh() [could also name this reset()]&#60;/p&#62;
&#60;p&#62;i think even pause()/resume() [actually, stop()/start() would probably be better names] are overkill for this &#34;primer&#34; interface, but i'm willing to hear arguments to the contrary.&#60;/p&#62;
&#60;p&#62;this is essentially the functionality you were suggesting should be on their own as C functions (i've added setPeriod() since prescalers in particular seem to be a common stumbling block).  i'm not sure which of classes and distinct functions is preferable, pedagogically.  having a class encourages thinking about the methods as interrelated, and makes it easier to view the more featureful/complicated classes as later steps in the same progression.&#60;/p&#62;
&#60;p&#62;having distinct functions is syntactically simpler and certainly doesn't preclude presenting them together.  however, because of the way our documentation is structured, this would imply having a separate docs page which referenced all of the related function API pages.  these aren't major drawbacks in my mind, and the extra simplicity may turn out to be a big enough win that it's worth it.&#60;/p&#62;
&#60;p&#62;one neat trick that having three separate classes allows is that since the SimpleTimer interface is the intersection of the capabilities of all the timers, you could construct a SimpleTimer wrapper around any of the available timers (since an instance just wraps a libmaple timer_dev), instead of requiring that you treat TIMER1 as an advanced timer.&#60;/p&#62;
&#60;p&#62;as for the other two proposed classes:&#60;/p&#62;
&#60;p&#62;i imagine that Timer would look something like HardwareTimer.  once you're familiar with SimpleTimer, adding the concept of capture/compare interrupts is a straightforward extension of the idea of basic overflow interrupts.  that gives you a toe-hold into the extra complexity.  once that's understood, you can work your way up to output compare and input capture, using the already familiar concepts of pwmWrite() and pulseIn() (though the latter has yet to be included with libmaple, the Arduino implementation will almost certainly port unchanged).&#60;/p&#62;
&#60;p&#62;finally, the AdvancedTimer could add trigger and break inputs to the Timer interface, and perhaps a straightforward timer synchronization interface.&#60;/p&#62;
&#60;p&#62;i think it would be better to leave the timer DMA capabilities out.  DMA is a nice feature, but it's conceptually unrelated, and i think putting it in to the timer interfaces would muddy the waters too much to be worthwhile.  i think there should be a separate, class-based DMA controller interface for handling all of that.&#60;/p&#62;
&#60;p&#62;there are of course other timer capabilities which we could include, but to me they don't seem like such killer apps that including them merits violating KISS.  for instance, timers 6 and 7 are useful for controlling the DAC, but i think it would be better to have a separate DACTimer interface for doing that which extends the SimpleTimer interface, and is documented to only work for timers 6 and 7.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "the future of HardwareTimer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=794#post-4818</link>
			<pubDate>Thu, 26 May 2011 05:48:30 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">4818@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;mbolivar - I agree in principle to three new interfaces, but I am not sure I understand how it will work.&#60;/p&#62;
&#60;p&#62;Can you write a few use cases, or examples for each type of interface? It might be easier for people to understand and comment.&#60;/p&#62;
&#60;p&#62;I assume common features, which use common functionality will be the same across all types of timers?&#60;br /&#62;
Are you thinking of a C++ Class-based interface, or C-function-Style, or both?&#60;/p&#62;
&#60;p&#62;Maybe there are 4. &#60;/p&#62;
&#60;p&#62;One of which is like the Arduino, which represents the intersection of functionality, and helps folks familiar with the Arduino, come up to speed. This may be the current HardwareTimer with a C-style function interface to make it easy for migrating Arduinauts (not sure what the right noun is:-).&#60;/p&#62;
&#60;p&#62;For example, pwmWrite would stay, and add its counterparts for setting the counter prescaler, overflow/reload and resetting it. It would have an interrupt service routine too. This would be an Arduino-like C-function interface.&#60;/p&#62;
&#60;p&#62;In the spirit of KISS 'keep it simple', I think that is all that the intersection of timer functionality contains. It is the basic timer with a pin-id. I think that is enough for a lot of uses of timers. I think a nice solution would use both the Arduino output pin-number method to identify the channel (no I/O remapping supported), and expose the timer itself as a thing (a little bit of overloading?).&#60;/p&#62;
&#60;p&#62;(full disclosure: I am not a member of LeafLabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Xavier on "the future of HardwareTimer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=794#post-4786</link>
			<pubDate>Wed, 25 May 2011 10:56:15 +0000</pubDate>
			<dc:creator>Xavier</dc:creator>
			<guid isPermaLink="false">4786@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;From what you wrote, i agree that having 3 different interfaces sounds good.&#60;br /&#62;
No need to deal with complicated API if a simple one is enough.&#60;br /&#62;
And smooth upgrade path.&#60;br /&#62;
Many good reasons.&#60;/p&#62;
&#60;p&#62;Xavier
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "the future of HardwareTimer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=794#post-4780</link>
			<pubDate>Wed, 25 May 2011 03:26:42 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">4780@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;i'm currently toying around with the idea of abandoning HardwareTimer altogether in favor of three separate interfaces for the basic, general purpose, and advanced timers.&#60;/p&#62;
&#60;p&#62;the advanced timers are awesome, but they're fairly complicated, especially if you're just starting out. in contrast, the basic timers (high density devices only, which limits it to RET6 Edition and Native for now) are great for getting started with the core idea of a prescalable counter which can interrupt on overflow -- and the fact that the basic timers have no capture/compare channels means that you can use them without worrying about messing up PWM and poring over the timer pin maps to make sure you've done everything right.&#60;/p&#62;
&#60;p&#62;having separate interfaces also means we can have separate documentation. this provides a smoother upgrade path for incrementally adding timer features to your bag of tricks; as soon as you've outgrown the basic timers, you can move on to general purpose ones, and from general purpose timers you can finally upgrade to advanced.&#60;/p&#62;
&#60;p&#62;for these and many other reasons, i think there's a strong case for deprecating HardwareTimer altogether.&#60;/p&#62;
&#60;p&#62;thoughts?
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
