<?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; User Favorites: kaipyroami</title>
		<link><a href='http://forums.leaflabs.com/profile.php?id=4008'>4008</a></link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:11:51 +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?profile=4008" rel="self" type="application/rss+xml" />

		<item>
			<title>nplayle on "Reading Servo Input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1380#post-9876</link>
			<pubDate>Sat, 24 Mar 2012 21:04:00 +0000</pubDate>
			<dc:creator>nplayle</dc:creator>
			<guid isPermaLink="false">9876@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi, &#60;/p&#62;
&#60;p&#62;I havent looked at your code too closely, but I worked on the same problem about two months ago. My code is as follows: it reads a PWM signal from an R/C receiver and then outputs the same pulse width on a different channel. I just briefly worked on it, but it did work for me, though I believe it could be cleaned up to function better. &#60;/p&#62;
&#60;p&#62;It checks for a rising edge on the servo channel, then sets the trigger to falling edge and starts counting. It waits for the falling edge and checks the time in between. I'm getting four input channels using one timer by using all the input channels, but only resetting the timer when the last servo value was captured. Note that you'll need to change this if you want to use a different number of channels, otherwise it won't reset the timer. &#60;/p&#62;
&#60;p&#62;Code: &#60;a href=&#34;http://pastebin.com/faML8CN7&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/faML8CN7&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Nick
&#60;/p&#62;</description>
		</item>
		<item>
			<title>kaipyroami on "Reading Servo Input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1380#post-9875</link>
			<pubDate>Sat, 24 Mar 2012 15:38:10 +0000</pubDate>
			<dc:creator>kaipyroami</dc:creator>
			<guid isPermaLink="false">9875@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;&#60;a href=&#34;http://leaflabs.com/docs/hardware/maple-native-beta.html#maple-native-b-exti-map&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/hardware/maple-native-beta.html#maple-native-b-exti-map&#60;/a&#62;&#60;br /&#62;
or are they directly related to the EXTI lines?&#60;br /&#62;
EXTI8 = TR8?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>kaipyroami on "Reading Servo Input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1380#post-9870</link>
			<pubDate>Fri, 23 Mar 2012 23:55:45 +0000</pubDate>
			<dc:creator>kaipyroami</dc:creator>
			<guid isPermaLink="false">9870@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;So it looks like what I need to do is to be able to directly access the RTSR and FTSR for a given interrupt.&#60;br /&#62;
&#60;a href=&#34;http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/REFERENCE_MANUAL/CD00171190.pdf&#34; rel=&#34;nofollow&#34;&#62;http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/REFERENCE_MANUAL/CD00171190.pdf&#60;/a&#62;&#60;br /&#62;
page 203&#60;/p&#62;
&#60;p&#62;so by writing to this register I can manipulate the trigger criteria. Last problem, how do I know what trigger line, TR0-TR19, that the compiler used for my interrupts?&#60;br /&#62;
&#60;code&#62;&#60;br /&#62;
attachInterrupt(9, Steering, RISING);&#60;br /&#62;
attachInterrupt(10, Throttle, RISING);&#60;br /&#62;
&#60;/code&#62;&#60;br /&#62;
Are they assigned numerically? First interrupt gets TR0 then TR1 ect?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>kaipyroami on "Reading Servo Input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1380#post-9860</link>
			<pubDate>Fri, 23 Mar 2012 11:38:09 +0000</pubDate>
			<dc:creator>kaipyroami</dc:creator>
			<guid isPermaLink="false">9860@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;So I found this in exti.c&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;/* Set trigger mode */
    switch (mode) {
    case EXTI_RISING:
          bb_peri_set_bit(&#38;amp;EXTI_BASE-&#38;gt;RTSR, num, 1);
          break;
    case EXTI_FALLING:
          bb_peri_set_bit(&#38;amp;EXTI_BASE-&#38;gt;FTSR, num, 1);
          break;
    case EXTI_RISING_FALLING:
          bb_peri_set_bit(&#38;amp;EXTI_BASE-&#38;gt;RTSR, num, 1);
          bb_peri_set_bit(&#38;amp;EXTI_BASE-&#38;gt;FTSR, num, 1);
          break;
    }&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;&#60;a href=&#34;http://leaflabs.com/docs/libmaple/api/bitband.html?highlight=bb_peri_set_bit&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/libmaple/api/bitband.html?highlight=bb_peri_set_bit&#60;/a&#62;&#60;br /&#62;
And this is the explanation of bb_peri_set_bit.&#60;br /&#62;
So it looks like EXTI_BASE-&#38;gt;RTSR is the address of the bit that sets the interrupt mode? right?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>kaipyroami on "Reading Servo Input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1380#post-9859</link>
			<pubDate>Fri, 23 Mar 2012 11:02:46 +0000</pubDate>
			<dc:creator>kaipyroami</dc:creator>
			<guid isPermaLink="false">9859@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@gbulmer I am still troubleshooting. Is there a way to directly toggle register bits in the Maple IDE?&#60;/p&#62;
&#60;p&#62;Example:  attachInterrupt(9, MyFunc, RISING); &#60;/p&#62;
&#60;p&#62;MyFunc()&#60;br /&#62;
{&#60;br /&#62;
 Register_for_rise_fall ^= RISING;&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;I have narrowed my problem down to the fact that I need to sample a rising edge followed by a falling edge. So my thinking is that if I could have only one function per channel and then change the interrupt requirements in the function this would solve my problem.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Reading Servo Input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1380#post-8389</link>
			<pubDate>Sat, 25 Feb 2012 10:23:41 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">8389@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;kaipyroami - So what does your code now look like? You could use pastebin or github gist if you have several versions to post.&#60;/p&#62;
&#60;p&#62;Try simplifying everything.&#60;/p&#62;
&#60;p&#62;Use one timer&#60;br /&#62;
Make the prescaler 0xffff (i.e. 65535) which will give a tick close to 1ms.&#60;br /&#62;
Use a button to simulate the input signal.&#60;/p&#62;
&#60;p&#62;Reading the HardwareTimer and timer code, every &#60;code&#62;pause()&#60;/code&#62; must have a matching &#60;code&#62;resume()&#60;/code&#62;.&#60;br /&#62;
AFAICT &#60;code&#62;refresh()&#60;/code&#62; *must* be used to zero the timer. It isn't just the timer's counter that must be reset, but also the prescaler counter (a good reason for keeping the presecaler value small).&#60;/p&#62;
&#60;p&#62;The compare value should be 0xffff too.&#60;/p&#62;
&#60;p&#62;Also set the timer_mode to TIMER_OUTPUT_COMPARE, as PWM counts up, then counts down, so alternate values will be huge as the timer will be counting *down* from the overflow value.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;I have the prescaler to count 10 microseconds correct? (72MHz/720 = 100,000 = 0.000,010 seconds?)&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Yes, that should be fine. In that case, should &#60;code&#62;steering_input -= 1000;&#60;/code&#62; be &#60;code&#62;steering_input -= 100;&#60;/code&#62;?&#60;/p&#62;
&#60;p&#62;It looks like you are aiming to measure a servo pulse, which is typically 20ms, so you could set the prescaler to 72, to get 1us resolution. The counter will go up to 65.5ms.&#60;/p&#62;
&#60;p&#62;I should add, the timer can be used to measure the duration of a signal directly itself. The mode is called input capture, and the pin used for PWM output can also be set up to be an input, sampling an external signal. But the HardwareTimer code has no support for that beyond the functions you've already seen.&#60;br /&#62;
The RM0090 manual describes the modes, but it is quite intricate to set up. I have no code, but maybe someone does?&#60;/p&#62;
&#60;p&#62;(Full disclosure: I am not a member of LeafLabs or Olimex staff.)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>kaipyroami on "Reading Servo Input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1380#post-8385</link>
			<pubDate>Fri, 24 Feb 2012 23:58:28 +0000</pubDate>
			<dc:creator>kaipyroami</dc:creator>
			<guid isPermaLink="false">8385@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I appreciate it, sorry for the inconvenience. :)&#60;/p&#62;
&#60;p&#62;I had tried using refresh() inplace of the setCount(0)and I was only getting zero values. I as assuming that I was messing up the prescaler or configuration somehow.&#60;br /&#62;
And lastly a error on my part. I retired the code with the pause() commented out and I am still getting &#34;garbage&#34; values.&#60;br /&#62;
I have the prescaler to count 10 microseconds correct? (72MHz/720 = 100,000 = 0.000,010 seconds?)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Reading Servo Input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1380#post-8378</link>
			<pubDate>Fri, 24 Feb 2012 20:25:56 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">8378@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;kaipyroami - I took the liberty of formatting your code. Hopefully that will make it easier for people to read and help.&#60;/p&#62;
&#60;p&#62;Did you look at the examples at &#60;a href=&#34;http://leaflabs.com/docs/lang/api/hardwaretimer.html#using-timer-interrupts&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/lang/api/hardwaretimer.html#using-timer-interrupts&#60;/a&#62;&#60;br /&#62;
That advises the use of &#60;code&#62;refresh()&#60;/code&#62; to set the count to 0.&#60;br /&#62;
It also recommends using &#60;code&#62;resume()&#60;/code&#62; after a &#60;code&#62;pause()&#60;/code&#62;.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>kaipyroami on "Reading Servo Input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1380#post-8329</link>
			<pubDate>Thu, 23 Feb 2012 21:01:49 +0000</pubDate>
			<dc:creator>kaipyroami</dc:creator>
			<guid isPermaLink="false">8329@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I have a maple native, IDE 12 on windows.&#60;br /&#62;
I am attempting to read two servo signal inputs on pins 9 and 10. They are from a RC car receiver. The input is about 3.4vdc, with a pulse width of 1-2 milliseconds.&#60;br /&#62;
My method (perhaps incorrect) is to detect the rising edge of each pulse to start the timers, then detect the falling edge and read the timer value and store that in another variable.&#60;br /&#62;
I am just getting either garbage numbers or constant unchanging numbers. Am I approaching this correctly? &#60;/p&#62;
&#60;pre&#62;&#60;code&#62;HardwareTimer SteeringTimer(1);
HardwareTimer ThrottleTimer(2);
volatile uint32 time_t;
volatile uint32 time_s;
volatile uint32 steering_input;
volatile uint32 throttle_input;
void setup()
{
    Serial1.begin(9600);
    pinMode(9, INPUT);
    pinMode(10, INPUT);
    SteeringTimer.setPrescaleFactor(720);
    ThrottleTimer.setPrescaleFactor(720);
    attachInterrupt(9, S_Rise, RISING);
    attachInterrupt(9, S_Fall, FALLING);
    attachInterrupt(10, T_Rise, RISING);
    attachInterrupt(10, T_Fall, FALLING);
}
void loop()
{
    delay(1000);
    Serial1.print(&#38;quot;Throttle: &#38;quot;);
    Serial1.println(throttle_input);
    Serial1.print(&#38;quot;Steering: &#38;quot;);
    Serial1.println(steering_input);
}
/**********************Functions**and**stuff****************************************************/
void S_Rise()//restart timers on interupt
{
  SteeringTimer.setCount(0);
}
void T_Rise()
{
  ThrottleTimer.setCount(0);
}
void S_Fall()//calculate servo input from time markers, output in (% * 10) ie 1000 = 100.0%
{
  SteeringTimer.pause();
  time_s = SteeringTimer.getCount();
  steering_input = time_s;
  steering_input -= 1000;
}
void T_Fall()
{
  ThrottleTimer.pause();
  time_t = ThrottleTimer.getCount();
  throttle_input = time_t;
  throttle_input -= 1000;
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>

	</channel>
</rss>
