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

		<item>
			<title>Silntknight on "External Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=262&amp;page=2#post-2159</link>
			<pubDate>Tue, 02 Nov 2010 17:47:28 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">2159@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;I think I must be missing something. Isn't the camshaft turning at the speed needed to synchronise with the induction and exhaust cycles? If it is, can you get at it, and attach a magnet for a Hall Sensor? &#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Don't worry, you definitely aren't missing anything. I just do not want to try and mount a Hall in the crankcase. In any case, on our &#34;other&#34; topic (I guess I should consolidate to one after this post), I posted a solution. See &#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=101&#38;amp;page=4&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=101&#38;amp;page=4&#60;/a&#62;&#60;br /&#62;
Basically what I did was say, &#34;Screw trying to time everything, I'm just going to have one signal from the engine and make the Maple do the rest.&#34; So, then I decided to use solenoids to electronically control the valves. The beauty of the system is that everything can be controlled by one Hall on the flywheel, where there is already a magnet that I have easy access to. Even better, all I need for synchronization is phase shifts of the various PWMs, which is easy using direct counter inputs. Anyway, the other topic explains this MUCH better.&#60;br /&#62;
By the way, as an added benefit, I can remove the throttle plate altogether, as it creates inefficiencies. I use the intake valve and modulate how long it stays open in order to control the amount of air entering the engine. For those of you who are familiar with thermodynamic cycles, this means I do not change the initial pressure of the graph, but rather the initial volume. I go from isochoric (isovolumetric) control to isobaric, which creates more work for the same input.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "External Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=262&amp;page=2#post-2151</link>
			<pubDate>Mon, 01 Nov 2010 18:24:18 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">2151@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;Just a thought, but could I use a solenoid (linear actuator, etc.) as a switch? Basically, the engine uses pushrods to open and close the valve, these are &#34;extensions&#34; on top of the push rod. I think that if I had it connected to +5V and the pin, the metal rod would be pushed against the pushrod. Then, when the rod goes up, with significantly more force than the solenoid goes down with, it changes the impedance of the circuit. &#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Than might work, but I have no sense of how robust a solenoid is.&#60;br /&#62;
It might be worth an experiment to make a magnetic 'circuit', with the pushrod being part of a magnetic circuit, and in some positions completing the circuit, and in others breaking it. Then all the sensing could be outside the cylinder head.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;I could wrap part of the push rod in insulating material and leave part as exposed metal. Then, all I need is two metal blocks that barely touch the pushrod so that when it is at the top of its stroke the metal blocks make contact with the pushrod metal and complete the circuit.&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Again, not sure how robust a 'wrapper' would need to be. Maybe some ceramic material, the sort of material used in gas heating systems might be worth the experiment.&#60;/p&#62;
&#60;p&#62;I think I must be missing something. Isn't the camshaft turning at the speed needed to synchronise with the induction and exhaust cycles? If it is, can you get at it, and attach a magnet for a Hall Sensor?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Silntknight on "External Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=262&amp;page=2#post-2126</link>
			<pubDate>Sat, 30 Oct 2010 14:33:51 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">2126@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The only reliable info I can think of is intake/exhaust valve positions. They both have a period that is twice the engine period, unlike all of the other components. When the intake opens, I know we are on the intake stroke. When the exhaust closes, I know we are about to start the intake stroke.&#60;/p&#62;
&#60;p&#62;Just a thought, but could I use a solenoid (linear actuator, etc.) as a switch? Basically, the engine uses pushrods to open and close the valve, these are &#34;extensions&#34; on top of the push rod. I think that if I had it connected to +5V and the pin, the metal rod would be pushed against the pushrod. Then, when the rod goes up, with significantly more force than the solenoid goes down with, it changes the impedance of the circuit. It might be enough (with a resistor) to change the voltage from a HIGH to a LOW. Not sure if this would work... If not, this gave me another idea, I could wrap part of the push rod in insulating material and leave part as exposed metal. Then, all I need is two metal blocks that barely touch the pushrod so that when it is at the top of its stroke the metal blocks make contact with the pushrod metal and complete the circuit. I could use this in conjunction with a Hall to get the initial firing sequence. Basically an if loop that only runs the first 10 times the engine revolves. The kill switch would reset a counter (for the first 10 times thing I just said). I was initially concerned with the engine moving too fast for a good connection to be made, but at low speeds (idling) this *should* work.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "External Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=262&amp;page=2#post-2109</link>
			<pubDate>Fri, 29 Oct 2010 02:50:52 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">2109@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;How does the code know the initial state? What could end up happening is when I try to start the engine, the MCU doesn't know any better and it injects during the exhaust stroke. Right now the code has a 50/50 shot at working.&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Are their any otheer bits of information that can be relied upon? Even if only to get into synch correctly.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Silntknight on "External Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=262&amp;page=2#post-2105</link>
			<pubDate>Fri, 29 Oct 2010 00:09:21 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">2105@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;So I had typed quite a bit until I reread your code. I thought it wouldn't work because the code wouldn't know which cycle it was on, but the &#60;code&#62;fire = !fire&#60;/code&#62; solves that problem. I was also going to expand on your code until I realized that what you have there is really all that is needed. In plain English:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;If it wasn&#38;#39;t fired last time the Hall was triggered
  get the counter value
  reset the counter
Change the state of &#38;quot;fire&#38;quot;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Now I did think of a problem. How does the code know the initial state? What could end up happening is when I try to start the engine, the MCU doesn't know any better and it injects during the exhaust stroke. Right now the code has a 50/50 shot at working. Still, I like this better than mounting the Hall inside the crankcase and fitting a magnet to the camshaft. The flywheel already has a magnet. I'll try to think of a way to make it reliable 100% of the time.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "External Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=262&amp;page=2#post-2094</link>
			<pubDate>Thu, 28 Oct 2010 06:36:36 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">2094@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The Hall Sensor could trigger an interrupt.&#60;br /&#62;
I don't understand why it would have to be polled?&#60;br /&#62;
Hall sensors have no moving parts, so they deal with high speed quite well;&#60;br /&#62;
4000rpm = 4000/60 = 67Hz, i.e. 15mS, which is plenty slow for a Hall effect sensor. I bought some yesterday that claim a switching speed of 1.5uS, for under a $.&#60;/p&#62;
&#60;p&#62;Dividing the number of cycles by two, i.e. only firing on alternate cycles could be handled by keeping track of what happened last time in a Boolean variable:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;volatile bool fire = true;
//...
void sparkinterrupt() {
   if (fire( {
     // do firing stuff
   }
   fire = !fire;
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>Silntknight on "External Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=262&amp;page=2#post-2089</link>
			<pubDate>Wed, 27 Oct 2010 22:28:06 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">2089@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Gbulmer, I thought about using a Hall or a reed switch, but the problem then becomes that I have to infer the stroke based on another factor, the easiest being an valve sensor. A Hall or reed will be triggered EACH time the engine makes a revolution. The intake opens once every TWO revolutions. I could use both in conjunction to provide verification, but that would make the code more complicated. Just off the top of my head it would be something like:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;void hall() {
  if (digitalRead(valveSensor) == HIGH); {
    //interrupt stuff//
  }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;This then raises the issue of timing, because it has to poll the pin for the valve's position. By that time, the valve could have closed again. Even if I place the Hall a few degrees in advance of the time when the valve opens and closes, I would still run into issues because I have a large speed range (400-4000 rpm).&#60;/p&#62;
&#60;p&#62;Poslathian, I will do so as soon as I can. I just found out that the lab I work at has a pulse generator (I'd just have to stick a pot on it to get to 3.3V from 5V) and a scope so I can look at both my PWMs and other stuff as necessary. I'll probably just hold the switch and shake it around like it's on the engine. Otherwise, I've been looking into other solutions like a laser &#34;tripwire&#34; or sonar. Both have their problems, but would be MUCH more accurate if it works. The other thing I might try is mounting the switch in the crankcase, provided it is adequately shielded from the oil. There should be fewer vibrations there.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "External Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=262#post-2085</link>
			<pubDate>Wed, 27 Oct 2010 20:04:27 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">2085@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;my recommendation would be to run it, and scope this input. See if it is glitchy (alot of bouncing). Based on what the scope tells you, we can think up the right way to interpret the signal.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "External Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=262#post-2082</link>
			<pubDate>Wed, 27 Oct 2010 19:41:34 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">2082@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Silntknight - could you use a Hall sensor instead? They are physically quite robust (no moving parts) and I believe some have some mitigation over switch bounce.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Silntknight on "External Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=262#post-2074</link>
			<pubDate>Wed, 27 Oct 2010 17:50:13 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">2074@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Poslathian, I like the idea of debouncing, but I have a switch that is (surprisingly) more critical than the kill switch. It monitors whether the intake valve is open or closed. I have an interrupt that runs off of this and actually controls the entire circuit. The switch will be mounted literally on top of an engine and will experience lots of vibrations. I can't think of any way to debounce this, however. Should I configure the switch to be in a position where it is on most of the time or off most of the time. My reasoning is that if it is on mostly, then the connectors are closed by significant pressure, thus the connectors cannot literally bounce. The interrupt (if the button is configured to be normally on, or an NC circuit) would then be triggered by the rising action. Even if in the milliseconds it is open (anywhere from 5ms to 60ms) it bounces, it only becomes a stable RISING input when it is closed by the pressure of the valve on it.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Silntknight on "External Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=262#post-2069</link>
			<pubDate>Wed, 27 Oct 2010 15:02:20 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">2069@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Ok, I think for my purposes a simple delay in the code and a recheck would suffice. Obviously the engine would stop if the connection is successful. Also, missing one cycle isn't terrible. This means the lightest program that can do the job is probably adequate. I was thinking something like&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;if (digitalRead(3) == LOW) {
  //loop//
} else {
  delayMicroseconds(5);
  if (digitalRead(3) == LOW) {
    delay(1000);
  }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Just so you know, I am using some hefty toggle switches. We use these for normal engine kills (by grounding the spark) and we've never had trouble with it. It is unlikely that the connections would be made inadvertently. Thanks for the suggestion though; the code isn't hard to implement and can only help!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "External Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=262#post-2061</link>
			<pubDate>Wed, 27 Oct 2010 13:36:51 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">2061@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;yep thats what I was thinking. &#60;/p&#62;
&#60;p&#62;Remember to debounce your buttons for critical things (like a kill switch!)&#60;/p&#62;
&#60;p&#62;debouncing: &#60;a href=&#34;http://www.ganssle.com/debouncing.htm&#34; rel=&#34;nofollow&#34;&#62;http://www.ganssle.com/debouncing.htm&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;TLDR:&#60;br /&#62;
   Switches will often rapidly toggle when you open/close them because of mechanical vibrations right at the contact point. This means if you did something like:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;bool buttonDown = False;
int cnt =0;
while(1) {
    if (buttonDown) {
       if (!readPin(button)) buttonDown=False;
    } else {
       if (readPin(button)) {
          cnt++;
          buttonDown = True;
       }
    }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;and you hit the button ONCE, you might very well get a count of 10 or 100. Which you obviously dont want. So you want to bake into your switch-check loop some sort of &#34;downtime&#34; &#60;/p&#62;
&#60;p&#62;that is, you dont set buttonDown until the button has been reading consistently as &#34;down&#34; for some number of cycles.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Silntknight on "External Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=262#post-2024</link>
			<pubDate>Mon, 25 Oct 2010 22:03:32 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">2024@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;This was my original code for a LOW interrupt:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;void kill() {
  while (true)
  ;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;If I had made it:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;void kill() {
  delayMicroseconds(5000000);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Your solution might have worked. The original code had an infinite loop that would only be run if the switch was LOW. If I did RISING with that code, I would never leave the loop. Also, running delays in an interrupt is (apparently) unwise, so the second isn't the best solution. In the end, I realized that I could just make an if statement at the start of the loop:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;void loop() {
  if (digitalRead(pin) == LOW) {
    //loop//
  }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;In this way, as long as the switch is open (or closed if I wanted), the loop runs. Otherwise, it just keeps checking the switch's state.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "External Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=262#post-2019</link>
			<pubDate>Mon, 25 Oct 2010 20:43:44 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">2019@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;hmm. So youre engine is running, the kill switch is not thrown. You want to kill the engine as soon as the kill switch is thrown. So why not interrupt on the low to high transition and kill the engine?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Silntknight on "External Interrupts"</title>
			<link>http://forums.leaflabs.com/topic.php?id=262#post-2010</link>
			<pubDate>Mon, 25 Oct 2010 20:08:32 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">2010@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;I never fully understood the purpose of an on-low interrupt, does this just continually fire as long as the pin is low?&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;If I understand you correctly, yes. To provide an example, I intended to run a code that control an engine. When I wanted to run the engine, I would have the kill switch closed. Then, when I wanted t kill it, I would open the switch. The LOW interrupt would keep it &#34;killed&#34; as long as the switch was open. I was able to replace this with a simple if statement, but for an operation that couldn't do that, LOW (or HIGH) is almost necessary. Going back to my example, I couldn't use CHANGE or else the engine would never run. I also couldn't use RISING or FALLING because the code-stop was an infinite loop. Again, my example could have used a delay(100) command and either RISING or FALLING, but there could be others with different needs.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
