<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt"><div><span>Yes, I think this sounds doable in a single chip. My sarcasm probably didn't come through in my email. On the other hand, sometimes it is fun to get all Rube Goldberg with hardware for one-off projects.</span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span><br></span></div><div><br></div>  <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 10pt;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt;"> <div dir="ltr"> <hr size="1">  <font face="Arial" size="2"> <b><span
 style="font-weight:bold;">From:</span></b> The MacDougals <paulmacd@acm.org><br> <b><span style="font-weight: bold;">To:</span></b> 'Joe Fair' <joe@fairanswers.com> <br><b><span style="font-weight: bold;">Cc:</span></b> triembed@triembed.org <br> <b><span style="font-weight: bold;">Sent:</span></b> Thursday, July 31, 2014 10:07 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [TriEmbed] IR sensor vs trigger<br> </font> </div> <div class="y_msg_container"><br><div id="yiv7670609549"><style>#yiv7670609549 #yiv7670609549 --
 
 _filtered #yiv7670609549 {font-family:Helvetica;panose-1:2 11 6 4 2 2 2 2 2 4;}
 _filtered #yiv7670609549 {font-family:Helvetica;panose-1:2 11 6 4 2 2 2 2 2 4;}
 _filtered #yiv7670609549 {font-family:Calibri;panose-1:2 15 5 2 2 2 4 3 2 4;}
 _filtered #yiv7670609549 {font-family:Tahoma;panose-1:2 11 6 4 3 5 4 4 2 4;}
#yiv7670609549  
#yiv7670609549 p.yiv7670609549MsoNormal, #yiv7670609549 li.yiv7670609549MsoNormal, #yiv7670609549 div.yiv7670609549MsoNormal
        {margin:0in;margin-bottom:.0001pt;font-size:12.0pt;}
#yiv7670609549 a:link, #yiv7670609549 span.yiv7670609549MsoHyperlink
        {color:blue;text-decoration:underline;}
#yiv7670609549 a:visited, #yiv7670609549 span.yiv7670609549MsoHyperlinkFollowed
        {color:purple;text-decoration:underline;}
#yiv7670609549 p
        {margin-right:0in;margin-left:0in;font-size:12.0pt;}
#yiv7670609549 p.yiv7670609549MsoAcetate, #yiv7670609549 li.yiv7670609549MsoAcetate, #yiv7670609549 div.yiv7670609549MsoAcetate
        {margin:0in;margin-bottom:.0001pt;font-size:8.0pt;}
#yiv7670609549 span.yiv7670609549BalloonTextChar
        {}
#yiv7670609549 span.yiv7670609549EmailStyle20
        {color:#1F497D;}
#yiv7670609549 .yiv7670609549MsoChpDefault
        {}
 _filtered #yiv7670609549 {margin:1.0in 1.0in 1.0in 1.0in;}
#yiv7670609549 div.yiv7670609549WordSection1
        {}
#yiv7670609549 </style><div><div class="yiv7670609549WordSection1"><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">The Tiny chips support pin change interrupts on all pins.  You surely do not need two chips.</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">I would definitely get rid of the 1 second timeout.  I use the interrupt to be sure that I do not</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">miss a pulse on a pin.  If the pulses are long enough, then you can just poll and not worry about</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">using interrupts.</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">  </span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">Here are fragments of code from my rain gauge that sleeps most of the time.  It wakes
 up</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">on the rain sensor changing state or on a button press.  If you want more details, let me know.</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">  </span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">---> Paul</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">  </span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">  </span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">#if defined(__AVR_ATtiny84__)</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">#include <avr/interrupt.h></span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">#endif</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">  </span></div><div
 class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">const uint8_t SW_PIN  = 4;</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">const uint8_t RAIN_PIN = 8;    // PCINT0</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">  </span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">volatile uint8_t rain_pin_state = LOW;// does not matter what it is initialized to</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">volatile uint8_t rain_count = 0;</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">  </span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">#if defined(__AVR_ATtiny84__)</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">// PA4 handler</span></div><div class="yiv7670609549MsoNormal"><span
 style="font-size:11.0pt;">ISR(PCINT0_vect) {</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">    // just wake up</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">}</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">  </span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">// PB2 handler</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">ISR(PCINT1_vect) {</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">    // see if the rain gauge has tipped</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">    uint8_t save_rain_pin_state = rain_pin_state;</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">    if (save_rain_pin_state != (rain_pin_state =
 digitalRead(RAIN_PIN)))</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">        rain_count++;</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">}</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">#endif</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">  </span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">#ifndef cbi</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">#endif</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">#ifndef sbi</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">#define sbi(sfr, bit) (_SFR_BYTE(sfr) |=
 _BV(bit))</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">#endif</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">  </span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">setup()</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">{</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">    pinMode(RAIN_PIN, INPUT_PULLUP);</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">    rain_pin_state = digitalRead(RAIN_PIN);</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">  </span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">…</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">#if defined(__AVR_ATtiny84__)</span></div><div class="yiv7670609549MsoNormal"><span
 style="font-size:11.0pt;">    sei(); // Turn on interrupts</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">    // Pin interrupt setup for rain bucket</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">    sbi(GIMSK,5); // Enable pin change interrupt 1</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">    sbi(PCMSK1,2); // Allow pin changes on PB2</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">#endif</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">…</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">}</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">  </span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">void loop()</span></div><div
 class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">{</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">    // we expect rain_count to be 0 or 1.  If it is more than 1, then it is likely a signal bounce</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">    if (rain_count) {</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">        …</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">    }</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">}</span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">  </span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">  </span></div><div class="yiv7670609549MsoNormal"><span style="font-size:11.0pt;">
  </span></div><div class="qtdSeparateBR"><br><br></div><div class="yiv7670609549yqt9437037846" id="yiv7670609549yqt65172"><div class="yiv7670609549MsoNormal"><b><span style="font-size:10.0pt;">From:</span></b><span style="font-size:10.0pt;"> TriEmbed [mailto:triembed-bounces@triembed.org] <b>On Behalf Of </b>Joe Fair<br clear="none"><b>Sent:</b> Thursday, July 31, 2014 7:15 PM<br clear="none"><b>To:</b> Jon Wolfe<br clear="none"><b>Cc:</b> triembed@triembed.org<br clear="none"><b>Subject:</b> Re: [TriEmbed] IR sensor vs trigger</span></div><div class="yiv7670609549MsoNormal">  </div><div>I think you are right, they kind of each need a chip.  I was hoping to be smart enough to not to need more hardware. <br clear="none">Does the tiny sport two interrupts?  Or maybe i can tie them together?</div><div>I guess i need to learn more about days sheets, too.<br clear="none">Joe</div><div><div class="yiv7670609549MsoNormal">On Jul 30, 2014
 10:09 PM, "Jon Wolfe" <<a rel="nofollow" shape="rect" ymailto="mailto:jonjwolfe@yahoo.com" target="_blank" href="mailto:jonjwolfe@yahoo.com">jonjwolfe@yahoo.com</a>> wrote:</div><div><div><div><div class="yiv7670609549MsoNormal" style="background:white;"><span style="font-size:10.0pt;">I agree with the others, it sounds like the trigger should get the interrupt.</span></div></div><div><div class="yiv7670609549MsoNormal"><span style="font-size:10.0pt;">  </span></div></div><div><div class="yiv7670609549MsoNormal"><span style="font-size:10.0pt;">Like Jeff said, you want your interrupt to execute in as short of a time as possible. One approach might be to just set a flag on trigger presses then process the action in the main loop. That could still leave you with 1 sec latency if you are detecting IR hits, which would probably be pretty noticeable.</span></div></div><div><div class="yiv7670609549MsoNormal"><span style="font-size:10.0pt;">
  </span></div></div><div><div class="yiv7670609549MsoNormal"><span style="font-size:10.0pt;">I have never tried this on a tiny, but I'm making it a personal mission to find a use case for it, but you could use an RTOS, like <a rel="nofollow" shape="rect" target="_blank" href="http://www.femtoos.org/">http://www.femtoos.org/</a>  Looks promising. I've used ChibiOS on Cortex M3/4's and found it pretty nice to work with, YMMV. </span></div></div><div><div class="yiv7670609549MsoNormal"><span style="font-size:10.0pt;">  </span></div></div><div><div class="yiv7670609549MsoNormal"><span style="font-size:10.0pt;">The other alternative approaches might be to try to reduce the 1 second detection loop. Or, to try to architect your own "cooperative multitasking" or coroutines. In short, write your detect loop so that instead of looping for 1 second, it just does a little bit of work and returns to the main loop, remembering where is was in the loop
 between each call. I use this approach a lot.</span></div></div><div><div class="yiv7670609549MsoNormal"><span style="font-size:10.0pt;">  </span></div></div><div><div class="yiv7670609549MsoNormal"><span style="font-size:10.0pt;">I will say that you should try to handle debouncing the trigger in hardware as much as you can. I've tried software debouncing mechanical encoders in interrupt driven routines, and I can attest that it is maddening.</span></div></div><div><div class="yiv7670609549MsoNormal"><span style="font-size:10.0pt;">  </span></div></div><div><div class="yiv7670609549MsoNormal"><span style="font-size:10.0pt;">Lastly, you *could* always just buy a separate tiny for the detection, but I have no ulterior motive or bias there ;)</span></div></div><div><div class="yiv7670609549MsoNormal"><span style="font-size:10.0pt;">  </span></div></div><div><div class="yiv7670609549MsoNormal"><span style="font-size:10.0pt;">
  </span></div></div><div><div class="yiv7670609549MsoNormal"><span style="font-size:10.0pt;">  </span></div></div><div><div class="yiv7670609549MsoNormal" style="background:white;"><span style="font-size:10.0pt;">  </span></div></div><div><div><div><div class="yiv7670609549MsoNormal" style="text-align:center;background:white;" align="center"><span style=""></span><hr align="center" size="1" width="100%"></div><div class="yiv7670609549MsoNormal" style="background:white;"><b><span style="">From:</span></b><span style=""> Joe Fair <<a rel="nofollow" shape="rect" ymailto="mailto:joe@fairanswers.com" target="_blank" href="mailto:joe@fairanswers.com">joe@fairanswers.com</a>><br clear="none"><b>To:</b> <a rel="nofollow" shape="rect" ymailto="mailto:triembed@triembed.org" target="_blank" href="mailto:triembed@triembed.org">triembed@triembed.org</a> <br clear="none"><b>Sent:</b> Saturday, July 26, 2014 4:09 PM<br clear="none"><b>Subject:</b>
 [TriEmbed] IR sensor vs trigger</span><span style=""></span></div></div><div><div class="yiv7670609549MsoNormal" style="background:white;"><span style="">  </span></div><div><div><div class="yiv7670609549MsoNormal" style="background:white;"><span style="">Ok.  I'm pretty close on getting my home made laser tag with at tiny 85s going, but now i have a question about design.</span></div></div><div><div class="yiv7670609549MsoNormal" style="background:white;"><span style="">The loop I'm using detects a trigger pull, then a hit on the sensors.  however, The pulse in function I'm using to sense IR ha a timeout of 1 second.  If there is no inbound signal it is only checking got a trigger pull once a second.</span></div></div><div><div class="yiv7670609549MsoNormal" style="background:white;"><span style="">So i need to use an interrupt, but does it matter if i use one on the trigger pull or the ir sensor? </span></div></div><div><div
 class="yiv7670609549MsoNormal" style="background:white;"><span style="">Joe</span></div></div></div><div class="yiv7670609549MsoNormal" style="margin-bottom:12.0pt;background:white;"><span style=""><br clear="none">_______________________________________________<br clear="none">Triangle, NC Embedded Computing mailing list<br clear="none"><a rel="nofollow" shape="rect" ymailto="mailto:TriEmbed@triembed.org" target="_blank" href="mailto:TriEmbed@triembed.org">TriEmbed@triembed.org</a><br clear="none"><a rel="nofollow" shape="rect" target="_blank" href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br clear="none">TriEmbed web site: <a rel="nofollow" shape="rect" target="_blank" href="http://triembed.org/">http://TriEmbed.org</a><br clear="none"><br clear="none"></span></div></div></div></div></div></div></div></div></div></div></div><br><div class="yqt9437037846"
 id="yqt81316">_______________________________________________<br clear="none">Triangle, NC Embedded Computing mailing list<br clear="none"><a shape="rect" ymailto="mailto:TriEmbed@triembed.org" href="mailto:TriEmbed@triembed.org">TriEmbed@triembed.org</a><br clear="none"><a shape="rect" href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br clear="none">TriEmbed web site: <a shape="rect" href="http://triembed.org/" target="_blank">http://TriEmbed.org</a><br clear="none"></div><br><br></div> </div> </div>  </div></body></html>