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

		<item>
			<title>oliver on "Timer Library Problem"</title>
			<link>http://forums.leaflabs.com/topic.php?id=762#post-4612</link>
			<pubDate>Sun, 15 May 2011 04:18:23 +0000</pubDate>
			<dc:creator>oliver</dc:creator>
			<guid isPermaLink="false">4612@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thank very much you for your answers, i've finally done it :)&#60;br /&#62;
with &#60;code&#62;usbSendBytes()&#60;/code&#62; it seems to work very well:&#60;/p&#62;
&#60;p&#62;here is the code without using a library:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;#include &#38;quot;usb.h&#38;quot;&#60;/code&#62;&#60;br /&#62;
&#60;code&#62;int toggle = 0;&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;&#60;code&#62;uint8 sendBuf[7] = &#38;quot;Hallo\n&#38;quot;;&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;&#60;code&#62;void core(void);&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;&#60;code&#62;void setup()&#60;/code&#62;&#60;br /&#62;
&#60;code&#62;{&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;&#60;code&#62;pinMode(13, OUTPUT);&#60;/code&#62;&#60;br /&#62;
&#60;code&#62;Timer2.setChannel1Mode(TIMER_OUTPUTCOMPARE);&#60;/code&#62;&#60;br /&#62;
&#60;code&#62;Timer2.setPeriod(50000); // in microseconds&#60;/code&#62;&#60;br /&#62;
&#60;code&#62;Timer2.setCompare1(1);      // overflow might be small&#60;/code&#62;&#60;br /&#62;
&#60;code&#62;Timer2.attachCompare1Interrupt(core);&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;&#60;code&#62;}&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;&#60;code&#62;void loop()&#60;/code&#62;&#60;br /&#62;
&#60;code&#62;{&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;&#60;code&#62;delay(1);&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;&#60;code&#62;}&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;&#60;code&#62;void core(void){&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;&#60;code&#62;toggle ^= 1;&#60;/code&#62;&#60;br /&#62;
&#60;code&#62;digitalWrite(13,toggle);&#60;/code&#62;&#60;br /&#62;
&#60;code&#62;uint32 bytes_sent = usbSendBytes(sendBuf,6);&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;&#60;code&#62;}&#60;/code&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "Timer Library Problem"</title>
			<link>http://forums.leaflabs.com/topic.php?id=762#post-4576</link>
			<pubDate>Thu, 12 May 2011 14:58:07 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">4576@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;first, make sure that you can send bytes over USB at all by throwing a SerialUSB.println(&#34;hi&#34;);delay(1000); into your main loop. &#60;/p&#62;
&#60;p&#62;next, try using the lower level usb routine to send bytes asynchronously:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;#include &#38;quot;usb.h&#38;quot;

.
.
.
uint8 sendBuf[5] = {1,2,3,4,5};
uint32 bytes_sent = usbSendBytes(sendBuf,1); // send one byte nonblocking&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;does that work?&#60;/p&#62;
&#60;p&#62;my *guess* is that since SerialUSB.print is a blocking send, your program is getting hung up on that function, and then the interrupt rolls around again, interrupting from the interrupt so to speak, and breaking things. you might try disabling the timer interrupt as the first thing in your timer interrupt, and then re-enabling it on the way out. you loose your 50ms guarantee, but this may be a helpful debugging element. ex:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;void core(void) {
   Timer1.Pause()
   // other code
   Timer1.Resume()
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Timer Library Problem"</title>
			<link>http://forums.leaflabs.com/topic.php?id=762#post-4567</link>
			<pubDate>Wed, 11 May 2011 16:28:55 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">4567@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I agree, it is so slow that it isn't likely a timer conflict.&#60;/p&#62;
&#60;p&#62;Looking at your code, do you provide your own main() or do you use setup() and loop()? If you do provide your own main, are you calling all of the USB initialisation?&#60;/p&#62;
&#60;p&#62;If the LED works, and USB initialisation is  taken care of, then I think the problem is trying to use SerialUSB within an interrupt service routine. &#60;/p&#62;
&#60;p&#62;There have been problems, but I thought it had been improved, so I don't understand why this causes any. &#60;/p&#62;
&#60;p&#62;My 'knee-jerk' is to reduce interaction with USB to a minimum. E.g. send only one character using print instead of println; maybe bel (0x07) if it makes a noise would do as a test. Characters will get flushed when the buffer fills, which isn't exactly what you want, but the problem needs to be hunted down first.&#60;/p&#62;
&#60;p&#62;(full disclosure: I am not a member of Leaflabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>oliver on "Timer Library Problem"</title>
			<link>http://forums.leaflabs.com/topic.php?id=762#post-4541</link>
			<pubDate>Tue, 10 May 2011 00:52:00 +0000</pubDate>
			<dc:creator>oliver</dc:creator>
			<guid isPermaLink="false">4541@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks for your answer i have tested it to switch on and off LED 13 and it Works fine.&#60;br /&#62;
But as i add the Row:&#60;/p&#62;
&#60;p&#62;SerialUSB.println(&#34;huuu!&#34;);&#60;/p&#62;
&#60;p&#62;into the core function,&#60;br /&#62;
The LED stops flickering and the Maple does not send.&#60;/p&#62;
&#60;p&#62;I've tested it with Timer1 - Timer4 and non of them does his Job &#60;/p&#62;
&#60;p&#62;50milliseconds is very slow so i think there is no Timer-conflict with sysclock or others
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Timer Library Problem"</title>
			<link>http://forums.leaflabs.com/topic.php?id=762#post-4540</link>
			<pubDate>Mon, 09 May 2011 17:30:03 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">4540@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Have you tested flashing an LED instead of sending characters over USB?&#60;br /&#62;
That is so simple, that it is likely to work.&#60;/p&#62;
&#60;p&#62;Typically there is a conflict between the interrupts, but an interrupt every 50 millisecond are so slow that it's likely some other problem.&#60;/p&#62;
&#60;p&#62;(full disclosure: I am not a member of LeafLabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>oliver on "Timer Library Problem"</title>
			<link>http://forums.leaflabs.com/topic.php?id=762#post-4533</link>
			<pubDate>Mon, 09 May 2011 14:09:38 +0000</pubDate>
			<dc:creator>oliver</dc:creator>
			<guid isPermaLink="false">4533@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello,&#60;br /&#62;
i have been trying to write a Library, which sends me a Message over USB every few milliseconds ... but it does not work&#60;br /&#62;
is Timer2 needed for USB Connection? &#60;/p&#62;
&#60;p&#62;- - - - - - - - - - - - - - - - - - -timerlib.h:&#60;/p&#62;
&#60;p&#62;  &#60;code&#62;#ifndef timerlib_h&#60;/code&#62;&#60;br /&#62;
   &#60;code&#62;#define timerlib_h&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;  &#60;code&#62;#include &#38;quot;WProgram.h&#38;quot;&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;   &#60;code&#62;void core();&#60;/code&#62;&#60;br /&#62;
   &#60;code&#62;void start();&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;   &#60;code&#62;#endif&#60;/code&#62;&#60;/p&#62;
&#60;p&#62; - - - - - - - - - - - - - - - - - - - -timerlib.cpp:&#60;/p&#62;
&#60;p&#62;   &#60;code&#62;#include &#38;lt;timerlib.h&#38;gt;&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;   &#60;code&#62;void core(void){&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;	&#60;code&#62;SerialUSB.println(&#38;quot;hello!&#38;quot;);&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;   &#60;code&#62;}&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;   &#60;code&#62;void start(void){&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;	&#60;code&#62;Timer2.setChannel1Mode(TIMER_OUTPUTCOMPARE);&#60;/code&#62;&#60;br /&#62;
	&#60;code&#62;Timer2.setPeriod(50000); // in microseconds&#60;/code&#62;&#60;br /&#62;
	&#60;code&#62;Timer2.setCompare1(1);      // overflow might be small&#60;/code&#62;&#60;br /&#62;
	&#60;code&#62;Timer2.attachCompare1Interrupt(core);&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;   &#60;code&#62;}&#60;/code&#62;
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
