<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forums.obdev.at/app.php/feed/topic/9482" />

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2014-11-17T20:48:56+02:00</updated>

	<author><name><![CDATA[Objective Development Forums]]></name></author>
	<id>https://forums.obdev.at/app.php/feed/topic/9482</id>

		<entry>
		<author><name><![CDATA[alasdairc]]></name></author>
		<updated>2014-11-17T20:48:56+02:00</updated>

		<published>2014-11-17T20:48:56+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=9482&amp;p=28746#p28746</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=9482&amp;p=28746#p28746"/>
		<title type="html"><![CDATA[Re: Enabling interrupt causes device enumeration problem]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=9482&amp;p=28746#p28746"><![CDATA[
Hey there,<br /><br />Thanks for the advice, this has completely solved the problem!<br /><br />I've been struggling with this little circuit for a long time now, and can finally relax and just make use of it.<br /><br /> <img class="smilies" src="./../../../images/smilies/icon_biggrin.gif" alt=":D" title="Very Happy" /><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=20851">alasdairc</a> — Mon Nov 17, 2014 8:48 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[blargg]]></name></author>
		<updated>2014-11-17T10:23:33+02:00</updated>

		<published>2014-11-17T10:23:33+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=9482&amp;p=28733#p28733</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=9482&amp;p=28733#p28733"/>
		<title type="html"><![CDATA[Re: Enabling interrupt causes device enumeration problem]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=9482&amp;p=28733#p28733"><![CDATA[
V-USB is unreliable if you disable interrupts for more than 25 cycles (and Murphy's Law means that it'll seem to work on one computer rather than fail consistently on all). In your case you can make your ISR non-blocking by having it begin with an SEI to re-enable interrupts: ISR(TIM1_COMPA_vect,ISR_NOBLOCK). This ensures that interrupts are only disabled for a few cycles when your interrupt occurs. You must be sure you don't get another of your interrupts while your ISR is executing or it'll become be re-entered and likely screw up your state. Note that your interrupt can be delayed by 100us or more by the V-USB interrupt. You might be just as well off by polling the interrupt flag for your interrupt rather than using an ISR.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=20076">blargg</a> — Mon Nov 17, 2014 10:23 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[alasdairc]]></name></author>
		<updated>2014-11-17T02:01:17+02:00</updated>

		<published>2014-11-17T02:01:17+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=9482&amp;p=28732#p28732</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=9482&amp;p=28732#p28732"/>
		<title type="html"><![CDATA[Re: Enabling interrupt causes device enumeration problem]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=9482&amp;p=28732#p28732"><![CDATA[
ATTINY84 is running at 12MHz with an external crystal.<br /><br />I have 10uF electrolytic and 100nF ceramic cap between 5V and GND.<br /><br />This device works perfectly with another host computer.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=20851">alasdairc</a> — Mon Nov 17, 2014 2:01 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[alasdairc]]></name></author>
		<updated>2014-11-17T01:59:07+02:00</updated>

		<published>2014-11-17T01:59:07+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=9482&amp;p=28731#p28731</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=9482&amp;p=28731#p28731"/>
		<title type="html"><![CDATA[Enabling interrupt causes device enumeration problem]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=9482&amp;p=28731#p28731"><![CDATA[
I have a circuit based around an ATTINY84 and the V-USB stack which works perfectly on one computer but not another.<br /><br />I have tracked the problem down to this function call and the ISR which it starts:<br /><br /><div class="codebox"><p>Code: </p><pre><code>void enableIRIn() {<br /><br />  // setup pulse clock timer interrupt<br />  //Prescale /8 (16M/8 = 0.5 microseconds per tick)<br />  // Therefore, the timer interval can range from 0.5 to 128 microseconds<br />  // depending on the reset value (255 to 0)<br />  TCCR1A = 0;<br />  TCCR1B = _BV(WGM12) | _BV(CS10);<br />  OCR1A = F_CPU * USECPERTICK / 1000000;<br />  TCNT1 = 0;<br /><br />  //Timer1 Overflow Interrupt Enable<br />  TIMSK1 = _BV(OCIE1A);<br /><br />  // initialize state machine variables<br />  irparams.rcvstate = STATE_IDLE;<br />  irparams.rawlen = 0;<br /><br />  // set pin modes<br />  IRREAD_DDR &amp;= ~(1 &lt;&lt; IRREAD_POS);<br />}</code></pre></div><br /><br /><div class="codebox"><p>Code: </p><pre><code>ISR(TIM1_COMPA_vect)<br />{<br /><br />  irparams.timer++; // One more 50us tick<br />  if (irparams.rawlen &gt;= RAWBUF) {<br />    // Buffer overflow<br />    irparams.rcvstate = STATE_STOP;<br />  }<br />  switch(irparams.rcvstate) {<br />  case STATE_IDLE: // In the middle of a gap<br />    if (bit_is_clear(IRREAD_PIN, IRREAD_POS)) {<br />      if (irparams.timer &lt; GAP_TICKS) {<br />        // Not big enough to be a gap.<br />        irparams.timer = 0;<br />      }<br />      else {<br />        // gap just ended, record duration and start recording transmission<br />        irparams.rawlen = 0;<br />        irparams.rawbuf&#91;irparams.rawlen++&#93; = irparams.timer;<br />        irparams.timer = 0;<br />        irparams.rcvstate = STATE_MARK;<br />      }<br />    }<br />    break;<br />  case STATE_MARK: // timing MARK<br />    if (bit_is_set(IRREAD_PIN, IRREAD_POS)) {   // MARK ended, record time<br />      irparams.rawbuf&#91;irparams.rawlen++&#93; = irparams.timer;<br />      irparams.timer = 0;<br />      irparams.rcvstate = STATE_SPACE;<br />    }<br />    break;<br />  case STATE_SPACE: // timing SPACE<br />    if (bit_is_clear(IRREAD_PIN, IRREAD_POS)) { // SPACE just ended, record it<br />      irparams.rawbuf&#91;irparams.rawlen++&#93; = irparams.timer;<br />      irparams.timer = 0;<br />      irparams.rcvstate = STATE_MARK;<br />    }<br />    else { // SPACE<br />      if (irparams.timer &gt; GAP_TICKS) {<br />        // big SPACE, indicates gap between codes<br />        // Mark current code as ready for processing<br />        // Switch to STOP<br />        // Don't reset timer; keep counting space width<br />        irparams.rcvstate = STATE_STOP;<br />      }<br />    }<br />    break;<br />  case STATE_STOP: // waiting, measuring gap<br />    if (bit_is_clear(IRREAD_PIN, IRREAD_POS)) { // reset gap timer<br />      irparams.timer = 0;<br />    }<br />    break;<br />  }<br />}</code></pre></div><br /><br />I was presuming that perhaps the host computer was waiting too long, but then thinking about it, the InraRed ISR is triggering every 50us, while the usb polling only runs every 4ms, so in theory the IR receiver shouldn't be causing any issues. I also call usbPoll twice in the main loop.<br /><br />If I clear the contents of ISR(TIM1_COMPA_vect), leaving just an empty function block  then the device is recognized correctly.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=20851">alasdairc</a> — Mon Nov 17, 2014 1:59 am</p><hr />
]]></content>
	</entry>
	</feed>
