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

		<item>
			<title>bnewbold on "Bug in Timer Code?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=124#post-965</link>
			<pubDate>Thu, 02 Sep 2010 21:30:59 +0000</pubDate>
			<dc:creator>bnewbold</dc:creator>
			<guid isPermaLink="false">965@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Fixed and commited: &#60;a href=&#34;http://github.com/leaflabs/libmaple/commit/1c6f9a9b5e9f1896a6c3d1faa895af74b6c7e3e1&#34; rel=&#34;nofollow&#34;&#62;http://github.com/leaflabs/libmaple/commit/1c6f9a9b5e9f1896a6c3d1faa895af74b6c7e3e1&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bnewbold on "Bug in Timer Code?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=124#post-771</link>
			<pubDate>Thu, 19 Aug 2010 11:09:47 +0000</pubDate>
			<dc:creator>bnewbold</dc:creator>
			<guid isPermaLink="false">771@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I think you're right CarlO, I just have a sloppy off-by-one error there; I will update the library with bounds checking and test the output for accuracy.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "Bug in Timer Code?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=124#post-761</link>
			<pubDate>Wed, 18 Aug 2010 15:08:47 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">761@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Interesting find, nice catch! Let me think about it some more. The way you have it seems to make it possible to set overflow to -1...&#60;/p&#62;
&#60;p&#62;I think perhaps the source of your off by 1 error was from doing an integer divide on 71 by 2, which will probably end up as a shift right operation, which is 35 - not 36.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>CarlO on "Bug in Timer Code?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=124#post-757</link>
			<pubDate>Wed, 18 Aug 2010 11:26:56 +0000</pubDate>
			<dc:creator>CarlO</dc:creator>
			<guid isPermaLink="false">757@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Update:&#60;/p&#62;
&#60;p&#62;I modified my local copy of HardwareTimer.cpp as follows.&#60;/p&#62;
&#60;p&#62;Line 84 was:&#60;/p&#62;
&#60;p&#62;    setOverflow((microseconds*72)/ps);&#60;/p&#62;
&#60;p&#62;Line 84 modified to:&#60;/p&#62;
&#60;p&#62;    setOverflow(((microseconds*72)/ps)-1);&#60;/p&#62;
&#60;p&#62;This seems to fix the timer accuracy.&#60;/p&#62;
&#60;p&#62;Does anyone see any problems with fixing the code this way?&#60;/p&#62;
&#60;p&#62;Carl
&#60;/p&#62;</description>
		</item>
		<item>
			<title>CarlO on "Bug in Timer Code?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=124#post-755</link>
			<pubDate>Tue, 17 Aug 2010 22:09:49 +0000</pubDate>
			<dc:creator>CarlO</dc:creator>
			<guid isPermaLink="false">755@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hey LeafLabs folks,&#60;/p&#62;
&#60;p&#62;Thanks for a great product.&#60;/p&#62;
&#60;p&#62;I may have found a bug in the code for the Timers.&#60;/p&#62;
&#60;p&#62;The following code produces a nearly perfect square wave at 999.986KHz, well within the tolerance for the crystal.&#60;/p&#62;
&#60;p&#62;  pinMode(9,PWM);&#60;br /&#62;
  Timer4.setPrescaleFactor(1);&#60;br /&#62;
  Timer4.setOverflow(71);&#60;br /&#62;
  pwmWrite(9,36);&#60;/p&#62;
&#60;p&#62;The next piece of code, however, returns an Overflow value of 72 and produces a nearly square wave at 986.098KHz&#60;/p&#62;
&#60;p&#62;  pinMode(9,PWM);&#60;br /&#62;
  int Overflow = Timer4.setPeriod(1);&#60;br /&#62;
  pwmWrite(9,Overflow/2);&#60;/p&#62;
&#60;p&#62;I have similar results using a period of 2 etc.  The frequency is off by a proportion equal to the overflow value off by 1.  Are you accounting for the timer count starting at zero?&#60;/p&#62;
&#60;p&#62;Thanks for your help,&#60;/p&#62;
&#60;p&#62;Carl
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
