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

		<item>
			<title>9xer on "Maple frequency measurement"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1038&amp;page=2#post-10676</link>
			<pubDate>Tue, 15 May 2012 18:10:26 +0000</pubDate>
			<dc:creator>9xer</dc:creator>
			<guid isPermaLink="false">10676@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Links for 32bit resolution. &#60;/p&#62;
&#60;p&#62;Application Note: &#60;a href=&#34;http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/APPLICATION_NOTE/CD00165509.pdf&#34; rel=&#34;nofollow&#34;&#62;http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/APPLICATION_NOTE/CD00165509.pdf&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Example code: &#60;a href=&#34;http://www.st.com/internet/com/SOFTWARE_RESOURCES/SW_COMPONENT/FIRMWARE/an2592.zip&#34; rel=&#34;nofollow&#34;&#62;http://www.st.com/internet/com/SOFTWARE_RESOURCES/SW_COMPONENT/FIRMWARE/an2592.zip&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>9xer on "Maple frequency measurement"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1038&amp;page=2#post-10671</link>
			<pubDate>Tue, 15 May 2012 15:42:37 +0000</pubDate>
			<dc:creator>9xer</dc:creator>
			<guid isPermaLink="false">10671@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;First thank you to chris.troutner for uploading his code, it has saved me a good deal of time getting started with my first Maple project.&#60;/p&#62;
&#60;p&#62;WRT to this code &#60;a href=&#34;http://pastebin.com/53rmN4rF&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/53rmN4rF&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;I can give a little back by telling you why you are having the overflow problem. It's because you set value=0; only inside the input capture ISR. If you have no input pulse to capture, and therefore an overflow, the input capture ISR will never trigger and therefore you never set value=0. Move the overflow_flag check to the serial output loop.&#60;/p&#62;
&#60;p&#62;Also when capturing input durations you should never stop or reset the counter (pretty sure the STM32 is no exception). Leave it alone, just let it run. Currently the input capture ISR zeros the counter. This means your counter reset is offset from the actual transition event by the interrupt latency, and the code inside the ISR. At 100Hz this makes little to no difference on this 72Mhz CPU, but as speeds increase it will become more apparent.&#60;/p&#62;
&#60;p&#62;The best thing to do is something like this inside your ISR:&#60;/p&#62;
&#60;p&#62;current = TIMER4_BASE-&#38;gt;CCR1;		//read the captured value&#60;br /&#62;
value = current - previous;&#60;br /&#62;
previous = current;&#60;/p&#62;
&#60;p&#62;Make sure current and previous are unsigned 16 bit datatypes and everything will take care of itself.&#60;/p&#62;
&#60;p&#62;Only problem with this approach is you can't use timer overflow events in quite the same way to spot an overflow.&#60;/p&#62;
&#60;p&#62;And finally you can chain or cascade timers together to give you 32-bit input capture resolution see AN2592 (CD00165509.pdf). Another thought to save this complexity is to use the prescaler like an autoranger, take a quick measurement at an arbitrary prescaler, then adjust the prescaler to better suit the frequency. I dare say you could confuse it with a fast enough moving frequency, but with a thought.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Maple frequency measurement"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1038#post-7402</link>
			<pubDate>Mon, 19 Dec 2011 14:45:31 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">7402@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;chris.troutner - you might move forward faster by trying to get the pieces working in the easiest configuration first. Specifically using two timers, and then trying to merge both functions onto one timer. Then you could have two easier problems to solve, and when everything works, a working reference case to compare to when you try the merge of timer functionality.&#60;/p&#62;
&#60;p&#62;Think of it like a program optimisation problem, and take Michael Jacksons advice:&#60;br /&#62;
&#34;The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.&#34;&#60;br /&#62;
(&#60;a href=&#34;http://en.wikipedia.org/wiki/Program_optimization#Quotes&#34; rel=&#34;nofollow&#34;&#62;http://en.wikipedia.org/wiki/Program_optimization#Quotes&#60;/a&#62;)&#60;/p&#62;
&#60;p&#62;Having said that, my reading of RM0008&#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;
e.g &#34;15.3.2 Counter modes&#34; is &#34;In upcounting mode, the counter counts from 0 to the auto-reload value (content of the&#60;br /&#62;
TIMx_ARR register), then restarts from 0 and generates a counter overflow event.&#34;&#60;br /&#62;
So there is no need for an extra channel, there is an event generated when the timer counter reaches the value in the reload register. Set the reload value to 65535 (or less if you need it), and the overflow event will signal that there was no input.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>chris.troutner on "Maple frequency measurement"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1038#post-7401</link>
			<pubDate>Mon, 19 Dec 2011 14:20:25 +0000</pubDate>
			<dc:creator>chris.troutner</dc:creator>
			<guid isPermaLink="false">7401@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Good points! And thank you for reviewing my code!&#60;/p&#62;
&#60;p&#62;I only reset the time value &#60;strong&#62;on&#60;/strong&#62; an input capture. If the input is never captured, the timer should over-flow, which is when I want to generate the overflow/compare interrupt.&#60;/p&#62;
&#60;p&#62;You may be right that the code is messing up the overflow/compare since I configure it &#60;strong&#62;before&#60;/strong&#62; the capture configuration. This was intentional, and I was wondering the same thing. &#60;/p&#62;
&#60;p&#62;That bit bang code is from airthimble's code. I didn't want to mess it up, so I didn't change it. I think I just need to go through each bit in the reference manual and figure out if it's messing up my overflow/compare. I was hoping someone might be able to see the problem. Oh well.&#60;/p&#62;
&#60;p&#62;Otherwise, I think you're right that I'll just have to use another timer. I was hoping to use the same timer, and in theory it should work. Hmm...&#60;/p&#62;
&#60;p&#62;Cheers!&#60;/p&#62;
&#60;p&#62;Chris Troutner&#60;br /&#62;
&#60;a href=&#34;http://thesolarpowerexpert.com&#34;&#62;thesolarpowerexpert.com&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "Maple frequency measurement"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1038#post-7376</link>
			<pubDate>Fri, 16 Dec 2011 17:53:47 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">7376@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I know you want to run the input capture and output compare on the same timer, but I wonder if that isnt the issue. I am savvy enough with the timers to say one way or the other or if you need to be clever to do it. &#60;/p&#62;
&#60;p&#62;I noticed in your code that you reset the timer value on the input capture, perhaps you are never overflowing? &#60;/p&#62;
&#60;p&#62;I also noticed that you configured the input capture after the output compare via bit-banding. Make sure you arnt smashing the output compare configuration accidentally when writing to the timer registers to setup input compare. Since you are bit-banding you probably dont need to do read-modify writes, but its possible you got one of the vals wrong.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Dweller on "Maple frequency measurement"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1038#post-7364</link>
			<pubDate>Fri, 16 Dec 2011 15:42:08 +0000</pubDate>
			<dc:creator>Dweller</dc:creator>
			<guid isPermaLink="false">7364@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I did some timer capture stuff over in the thread at &#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=1170&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=1170&#60;/a&#62; where I had DMA moving the data across to an array, where I could process it outside of an interrupt handler..
&#60;/p&#62;</description>
		</item>
		<item>
			<title>chris.troutner on "Maple frequency measurement"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1038#post-7351</link>
			<pubDate>Wed, 14 Dec 2011 15:21:43 +0000</pubDate>
			<dc:creator>chris.troutner</dc:creator>
			<guid isPermaLink="false">7351@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hey all,&#60;/p&#62;
&#60;p&#62;I was able to mash the code in this thread together to get my own frequency measurement going on my Maple (Rev 5). Here is a pastebin of the code for those who would like to use it:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://pastebin.com/53rmN4rF&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/53rmN4rF&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Just use a wire to short pins 5 and 7 together. Pin 7 generates the square wave, pin 5 measures it.&#60;/p&#62;
&#60;p&#62;-----&#60;/p&#62;
&#60;p&#62;I need a little help refining this example. The code uses Timer4, channel 1 in Capture mode to measure the time between pulses. However, if I'd like the variable 'value' to get set to zero if Timer4 overflows without measuring a pulse. Without this feature, the old value continues getting displayed when you disconnect the wire because the capture interrupt never fires.&#60;/p&#62;
&#60;p&#62;I (tried to) set up Timer4, channel 2 in Compare mode with the compare value set to the overflow value. The intention is that I want a second interrupt to fire when Timer4 overflows which sets the variable 'overflow_flag'. &#60;/p&#62;
&#60;p&#62;I'd really appreciated it if people could review my code and let me know why I can't get the overflow interrupt to fire. In particular, check out this section in setup_timer() where I set up the overflow channel and interrupt:&#60;/p&#62;
&#60;p&#62;  //New code to set overflow timer&#60;br /&#62;
  timer4.setMode(2, TIMER_OUTPUT_COMPARE); //Set this channel to compare&#60;br /&#62;
  timer4.setCompare(2, 65534); //Set the compare for the channel to the overflow vale&#60;br /&#62;
  timer4.attachInterrupt(2, handle_overflow); //Assign the interrupt handler&#60;/p&#62;
&#60;p&#62;Thanks!&#60;/p&#62;
&#60;p&#62;Chris Troutner&#60;br /&#62;
&#60;a href=&#34;http://thesolarpowerexpert.com&#34;&#62;thesolarpowerexpert.com&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>airthimble on "Maple frequency measurement"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1038#post-6722</link>
			<pubDate>Sat, 01 Oct 2011 14:39:05 +0000</pubDate>
			<dc:creator>airthimble</dc:creator>
			<guid isPermaLink="false">6722@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;mbolivar, thanks for the quick reply! I should have enough stuff to keep me busy for awhile now :D
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "Maple frequency measurement"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1038#post-6721</link>
			<pubDate>Sat, 01 Oct 2011 13:09:08 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">6721@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;
On another note does anyone know if libmaple supports using I2C with DMA?&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;I see no reason why dma.h won't support I2C with DMA.  The relevant channels are DMA1 channels 6 and 7.  See this thread for a nice discussion on using I2C with SPI, including example code:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=1075&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=1075&#60;/a&#62;&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
I also have a question with interrupts, how are interrupts &#34;attached&#34;? Does it use one of the External Interrupts?&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Sometimes, but not always.  The enum &#60;code&#62;nvic_irq_num&#60;/code&#62; in nvic.h gives all of the possible interrupt vectors on the MCU:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://leaflabs.com/docs/libmaple/api/nvic.html#project0nvic_8h_1a89e3d57340a69fbdef83f12661543d83&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/libmaple/api/nvic.html#project0nvic_8h_1a89e3d57340a69fbdef83f12661543d83&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Some of these have to do with external interrupts; these begin with NVIC_EXTI (so &#60;code&#62;NVIC_EXTI0&#60;/code&#62;, &#60;code&#62;NVIC_EXTI_15_10&#60;/code&#62;).&#60;/p&#62;
&#60;p&#62;Interrupt &#34;attaching&#34; is jargon derived from the Wiring project.  If you want to attach to a timer interrupt, use &#60;a href=&#34;http://leaflabs.com/docs/libmaple/api/timer.html#project0timer_8c_1a022e444b1be2b3a47f598d16b0386f95&#34;&#62;timer_attach_interrupt()&#60;/a&#62; (or the more restrictive but more user-friendly &#60;a href=&#34;http://leaflabs.com/docs/lang/api/hardwaretimer.html#project0class_hardware_timer_1ae1965408f7b2ed72eaf37f35590a1e36&#34;&#62;HardwareTimer::attachInterrupt()&#60;/a&#62;).&#60;/p&#62;
&#60;p&#62;To attach to an external interrupt (EXTI), just use &#60;a href=&#34;http://leaflabs.com/docs/lang/api/attachinterrupt.html&#34;&#62;attachInterrupt()&#60;/a&#62;.&#60;/p&#62;
&#60;p&#62;&#60;code&#62;--------------------------------------------------&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;I've been meaning to write more about this for the documentation, so here's a sketch of how this all works (note: this omits certain details, but hopefully gets the important points across). Definitely optional reading, but you may find it interesting.&#60;/p&#62;
&#60;p&#62;On the Cortex M3, there's a table of pointers to the functions you want to use as interrupt handlers.  This is called the vector table; its address in memory is the value of the register SCB_VTOR (accessible in libmaple as &#60;code&#62;SCB_BASE-&#38;gt;VTOR&#60;/code&#62;).&#60;/p&#62;
&#60;p&#62;When an interrupt occurs, the MCU looks up the corresponding handler function from the vector table.  It then proceeds to save the current context by stacking registers and doing some other stuff, then jumps to the handler.  When the interrupt is done, this context saving gets undone and you go back to user code. (The truth is a little bit more complicated because interrupts can nest, but that's the basic idea).&#60;/p&#62;
&#60;p&#62;Part of what the libmaple startup sequence does is set up the vector table so that the addresses of our handler functions (whose names all begin with &#34;__irq&#34;; see libmaple's support/ld/names.inc for a list of all the names) get stored in the appropriate places in the vector table.&#60;/p&#62;
&#60;p&#62;When you call one of the various &#60;code&#62;attachInterrupt()&#60;/code&#62; or &#60;code&#62;foo_attach_interrupt()&#60;/code&#62; functions, it doesn't replace the vector table entry. Instead, what happens is that a pointer to &#60;em&#62;your&#60;/em&#62; function is stored in a secondary table of functions (this secondary table being part of libmaple), and when the interrupt occurs, the corresponding &#60;code&#62;&#60;/code&#62;__irq_foo()&#60;code&#62;&#60;/code&#62; calls your function after looking it up in libmaple's table.&#60;/p&#62;
&#60;p&#62;An example of such a secondary table is the array &#60;code&#62;exti_channels&#60;/code&#62; in exti.c, libmaple v0.0.12:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/v0.0.12/libmaple/exti.c#L49&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/blob/v0.0.12/libmaple/exti.c#L49&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;The &#60;code&#62;handler&#60;/code&#62; fields in the elements of &#60;code&#62;exti_channels&#60;/code&#62; are what hold the functions you pass to &#60;code&#62;attachInterrupt()&#60;/code&#62;.  To see this in action, you can connect the dots between the source code for &#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/v0.0.12/libmaple/exti.c#L142&#34;&#62;__irq_exti0()&#60;/a&#62; and &#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/v0.0.12/wirish/ext_interrupts.cpp#L47&#34;&#62;attachInterrupt()&#60;/a&#62;.&#60;/p&#62;
&#60;p&#62;This may seem complicated, and it does add some overhead, but the result is more user friendly.&#60;/p&#62;
&#60;p&#62;For instance, a lot of interrupts get multiplexed into a single interrupt vector.  E.g., there's a single &#60;code&#62;__irq_tim1_cc()&#60;/code&#62; that has to handle all 4 channel capture/compare interrupts for timer 1.  &#60;code&#62;timer_attach_interrupt()&#60;/code&#62; hides this complexity from you, so that you can pretend like there's a single interrupt for each of those channels.&#60;/p&#62;
&#60;p&#62;Further, serving an interrupt is usually more complicated than just providing a function that serves your application's purpose when the interrupt occurs. Often, there are peripheral registers which you have to massage each time the interrupt happens in order to keep things working. External interrupt handlers need to clear pending masks in EXTI_PR. DMA interrupt handlers need to clear DMA_ISR bits. Timer interrupts need to clear TIMx_SR bits, etc. etc. In each case, the libmaple &#60;code&#62;__irq_foo()&#60;/code&#62; function handles this for you behind the scenes.&#60;/p&#62;
&#60;p&#62;We think this increase in usability is worth the performance penalty. You may disagree. If so, you can use &#60;a href=&#34;http://leaflabs.com/docs/libmaple/api/nvic.html#project0nvic_8c_1ab78786ff3387dfaf3d9aeb017a111197&#34;&#62;nvic_set_vector_table()&#60;/a&#62; to set up your own vector table. If you do, you're on your own ;).&#60;/p&#62;
&#60;p&#62;HTH!&#60;/p&#62;
&#60;p&#62;edits: examples, clarifications
&#60;/p&#62;</description>
		</item>
		<item>
			<title>airthimble on "Maple frequency measurement"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1038#post-6720</link>
			<pubDate>Sat, 01 Oct 2011 11:30:14 +0000</pubDate>
			<dc:creator>airthimble</dc:creator>
			<guid isPermaLink="false">6720@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Here is the solution I came up with last night, it has a function to set things up and then the interrupt routine. I am not sure what all is implemented in libmaple, I noticed that there were some &#34;TODO&#34; in the comments of timer.h so I set some registers myself and used a few timer convenience functions, the comments should explain what is going on:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;void testSetup()
{
        pinMode(5, INPUT_PULLDOWN);

	TIMER4_BASE-&#38;gt;CCMR1 = 0x00F1;		//channel 1 configure as input, IC1 mapped on TI1
	TIMER4_BASE-&#38;gt;CCMR2 = 0x0000;		//channels 3&#38;amp;4 disabled
	TIMER4_BASE-&#38;gt;CCER = 0x0001;		//configure channel 1 as an input
	TIMER4_BASE-&#38;gt;SMCR = 0x0000;		//all slave modes disabled, CC transitions on clock
	TIMER4_BASE-&#38;gt;CR1 = 0x0001;		//enable the counter
	TIMER4_BASE-&#38;gt;CR2 = 0x0000;		//connect TIM4_CH1 pin to TI1 input
	TIMER4_BASE-&#38;gt;PSC = 0x00FF;		//set a random large prescalar just for testing

	timer_attach_interrupt(TIMER4, TIMER_CC1_INTERRUPT, __measurePulse_irq);

	timer_resume(TIMER4);
}

void __measurePulse_irq()
{
	//get the bit to see if this is an up or down pulse
	polarity = TIMER4_BASE-&#38;gt;CCER &#38;amp; 0x0002;

	if(polarity == 0)	//this is a rising edge capture
	{
		timer_set_count(TIMER4, 0x000);		//zero the counter
		temp = TIMER4_BASE-&#38;gt;CCR1;		//clear the interrupt by reading CCR1 value
		TIMER4_BASE-&#38;gt;CCER &#124;= 0x0002;		//change polarity to capture falling edge
	}
	else	//this is a falling edge capture
	{
		value = TIMER4_BASE-&#38;gt;CCR1;		//read the captured value
		TIMER4_BASE-&#38;gt;CCER &#38;amp;= ~0x0002;		//change polarity to capture rising edge
		timer_set_count(TIMER4, 0x0000);	//zero the counter
	}
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;To test this code I created this test loop in main, then wired pin7 to pin5:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;int main()
{
	pinMode(7, OUTPUT);

	newTest();

	while(1)
	{
		delay(500);
		SerialUSB.println(value);
		count++;

		digitalWrite(7, HIGH);
		delay(count);
		digitalWrite(7, LOW);
	}
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Hopefully someone may find this code useful, I will post a second version when I get it cleaned up and adjusted later today. On another note does anyone know if libmaple supports using I2C with DMA? &#60;/p&#62;
&#60;p&#62;I also have a question with interrupts, how are interrupts &#34;attached&#34;? Does it use one of the External Interrupts?&#60;/p&#62;
&#60;p&#62;I noticed there seems to be interrupt vectors defined in nvic.c/h, timer.c/h and exti.c/h, I would like to take advantage of some of these. Would someone be willing to type up a quick explanation of what I need to do to use some of these?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Maple frequency measurement"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1038#post-6714</link>
			<pubDate>Fri, 30 Sep 2011 20:42:51 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6714@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Okay, 5us to 20ms is a dynamic range of 4,000, and the timer is only 16 bits, so only about 4000/65,536= 1/16th, or 4 bits precision&#60;br /&#62;
If that is enough precision it should be straightforward&#60;br /&#62;
If it isn't, it is possible to 'chain' timers to construct a 32bit count, in which case, you might get to 72MHz clock frequency, or about 1/280th, better than 1% :-)&#60;/p&#62;
&#60;p&#62;I've done this on Arduino and the fundamental mechanism looks the same, though the registers are different. &#60;/p&#62;
&#60;p&#62;you could work up to this in a few steps:&#60;br /&#62;
1. Poll the pin with digitalRead() and use micros() to measure time&#60;br /&#62;
2. set a timer to the right frequency (about 4MHz, a &#34;prescaler&#34; of 8) to get to the right count frequency (for a 16 bit count), use that count as the time base, and read it at edges. See &#60;a href=&#34;http://leaflabs.com/docs/libmaple/api/timer.html#count-and-prescaler&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/libmaple/api/timer.html#count-and-prescaler&#60;/a&#62;&#60;br /&#62;
3. reset the counter to zero when you poll the start edgeand read the count when you see the finish edge&#60;br /&#62;
4. poll the pin directly &#38;amp; read the timer&#60;br /&#62;
 - use the pin map to convert from the pin number to the actual 16-bit port and pin within port,&#60;br /&#62;
    read the input data register (RM0008 section 9.2.3 &#34;Port input data register (GPIOx_IDR) (x=A..G)&#34;) to poll the pin&#60;br /&#62;
    e.g. &#60;code&#62;while (GPIOB_IDR&#38;amp;(BIT(6))) {} // wait for port B pin 6 to clear&#60;/code&#62;&#60;br /&#62;
    This is only more precise in that there is a smaller window for an interrupt to hit (as digitalRead should be deterministic)&#60;br /&#62;
5. Set the timer to capture signal change itself see &#60;a href=&#34;http://leaflabs.com/docs/libmaple/api/timer.html#capture-compare&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/libmaple/api/timer.html#capture-compare&#60;/a&#62;&#60;br /&#62;
     initially poll the timer to see if it has 'captured' i,e, timed a change&#60;br /&#62;
6. Get the captured count it with interrupts!-)&#60;/p&#62;
&#60;p&#62;HTH
&#60;/p&#62;</description>
		</item>
		<item>
			<title>airthimble on "Maple frequency measurement"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1038#post-6713</link>
			<pubDate>Fri, 30 Sep 2011 17:11:16 +0000</pubDate>
			<dc:creator>airthimble</dc:creator>
			<guid isPermaLink="false">6713@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I wasn't able to find anything besides this post on the forum regarding input capture. I was planning on doing an input capture to measure a digital signal of 5us to 20ms in length. If have time to get it working this weekend I will post my code.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Maple frequency measurement"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1038#post-6388</link>
			<pubDate>Sun, 18 Sep 2011 19:20:11 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6388@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;house91320 - most of the timers have 'input capture' pins.&#60;br /&#62;
The timer can be configured to count, then when an input capture pin is triggered by a signal edge, the timer count is copied into a 'capture register', and an interrupt triggered. The interrupt service routine can pick up the value stored in the capture register, and that is a measure of duration.&#60;/p&#62;
&#60;p&#62;The resolution of a single timer is 16 bits, which is far from the range needed for 100Hz to 8MHz. If you can have several attempts at the same signal, you could try to adjust the frequency the timer counts (the prescaler) so that it can be captured in 16 bits. That might not be an option.&#60;br /&#62;
It is possible to 'chain' timers together, if you want to think of one timer's counter reaching the maximum value, and the 'carry' from that timerdriving a second timer counter, effectively giving you a 32-bit counter.&#60;/p&#62;
&#60;p&#62;The timer can only count at the 72MHz clock frequency, and the sampling of the input signal will effectively be rounded to the nearest clock edge. So an 8MHz signal is only going to register as, roughly a count of 12 (depending on exactly when the edge happens), with an error of almost 10%.&#60;/p&#62;
&#60;p&#62;If the signal is fast, but repetitive, the signal from the input capture trigger can be divided, say by 16, so the counter value captured in the time for 16 cycles of the input signal, averaging the duration, and hence giving a bit more resolution (though the same absolute error).&#60;/p&#62;
&#60;p&#62;Have a look at the RM0008 manual, for example section 15.3.5 &#34;Input capture mode&#34; and see if it makes sense.&#60;br /&#62;
Some of the existing library can be used to set the timer up for counting, but I think you will have to get down to the hardware level, to set up some of the modes, and to get at the capture register.&#60;/p&#62;
&#60;p&#62;I haven't written code to do this, but it looks quite doable.&#60;/p&#62;
&#60;p&#62;(full disclosure: I am not a member of LeafLabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>house91320 on "Maple frequency measurement"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1038#post-6376</link>
			<pubDate>Sat, 17 Sep 2011 00:24:42 +0000</pubDate>
			<dc:creator>house91320</dc:creator>
			<guid isPermaLink="false">6376@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Any code ideas?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>house91320 on "Maple frequency measurement"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1038#post-6365</link>
			<pubDate>Thu, 15 Sep 2011 21:29:52 +0000</pubDate>
			<dc:creator>house91320</dc:creator>
			<guid isPermaLink="false">6365@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Its digital at 100hz to 8mhz, ideally it would be as accurate as possible.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
