<?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: Timer Register Counter is uint32 but timer_get_count(timer_dev *dev) is a uint16</title>
		<link>http://forums.leaflabs.com/topic.php?id=2196</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:07:38 +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=2196" rel="self" type="application/rss+xml" />

		<item>
			<title>LarryP on "Timer Register Counter is uint32 but timer_get_count(timer_dev *dev) is a uint16"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2196#post-12453</link>
			<pubDate>Wed, 15 Aug 2012 15:03:31 +0000</pubDate>
			<dc:creator>LarryP</dc:creator>
			<guid isPermaLink="false">12453@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@siy,&#60;/p&#62;
&#60;p&#62;Thank you for posting those two bits of code.  As soon as I get my hands on a quadrature encoder, I'll see if I can get encoder counting to behave for me.&#60;/p&#62;
&#60;p&#62;----&#60;/p&#62;
&#60;p&#62;@all,&#60;/p&#62;
&#60;p&#62;Does anybody reading know whether the quadrature-encoder enabled timers can handle undebounced (namely raw) mechanical encoder inputs?  &#60;/p&#62;
&#60;p&#62;For work, I've always used optical encoders, which have no mechanical bounce.  However, the lowest cost quadrature encoders I've found are mechanical, so I expect they'll produce transitions with contact bounce.&#60;br /&#62;
The STMicro documentation I've read to date does not seem to say anything about contact bounce when in quadrature mode.  Dedicated quadrature-encoder interface chips usually incorporate some sort of debouncing on chip, but if there's a software only way to handle contact bounce in quadrature mode (without using up a significant slice of the CPU bandwidth), that would be much preferred.&#60;/p&#62;
&#60;p&#62;Thanks in advance,&#60;/p&#62;
&#60;p&#62;Larry
&#60;/p&#62;</description>
		</item>
		<item>
			<title>siy on "Timer Register Counter is uint32 but timer_get_count(timer_dev *dev) is a uint16"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2196#post-12128</link>
			<pubDate>Tue, 31 Jul 2012 14:10:46 +0000</pubDate>
			<dc:creator>siy</dc:creator>
			<guid isPermaLink="false">12128@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;libmaple-friendly version:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;static inline timer_gen_reg_map* timer_get_reg_map(timer_dev* dev) {
	return (dev-&#38;gt;regs).gen;
}
...
    timer_init(TIMER2);
    timer_cc_set_pol(TIMER2, 1, 1);
    timer_cc_set_pol(TIMER2, 2, 1);
    timer_get_reg_map(TIMER2)-&#38;gt;CCMR1 &#124;= TIMER_CCMR1_CC1S; //set both channels
    timer_get_reg_map(TIMER2)-&#38;gt;SMCR &#124;= TIMER_SMCR_SMS_ENCODER1 &#124; TIMER_SMCR_SMS_ENCODER2;
    timer_set_reload(TIMER2, 100); // Counter upper limit
    timer_resume(TIMER2);
...&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>siy on "Timer Register Counter is uint32 but timer_get_count(timer_dev *dev) is a uint16"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2196#post-12119</link>
			<pubDate>Tue, 31 Jul 2012 04:54:00 +0000</pubDate>
			<dc:creator>siy</dc:creator>
			<guid isPermaLink="false">12119@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@LarryP, following sequence enables the encoder counter connected to GPIOA0 and GPIOA1 pins:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;RCC-&#38;gt;APB1ENR = RCC_APB1ENR_TIM2EN;

TIM2-&#38;gt;CCMR1 = TIM_CCMR1_CC1S_0 &#124; TIM_CCMR1_CC2S_0;
TIM2-&#38;gt;CCER = TIM_CCER_CC1P &#124; TIM_CCER_CC2P;
TIM2-&#38;gt;SMCR = TIM_SMCR_SMS_0 &#124; TIM_SMCR_SMS_1;
TIM2-&#38;gt;ARR = 100; //Counter upper limit
TIM2-&#38;gt;CR1 = TIM_CR1_CEN;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;(both pins should be configured as INPUT_PULL_UP)&#60;br /&#62;
The code above is not libmaple friendly, I'll post version of the code adapted to libmaple a bit later, once I'll reach home.&#60;/p&#62;
&#60;p&#62;By the way, I've found that use of hardware encoder support is not always convenient and for encoder-based UI switched to use of external interrupts (basically idea is the same as described here &#60;a href=&#34;http://www.circuitsathome.com/mcu/reading-rotary-encoder-on-arduino)&#34; rel=&#34;nofollow&#34;&#62;http://www.circuitsathome.com/mcu/reading-rotary-encoder-on-arduino)&#60;/a&#62;.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>LarryP on "Timer Register Counter is uint32 but timer_get_count(timer_dev *dev) is a uint16"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2196#post-12096</link>
			<pubDate>Sat, 28 Jul 2012 19:19:17 +0000</pubDate>
			<dc:creator>LarryP</dc:creator>
			<guid isPermaLink="false">12096@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@Carlos,&#60;/p&#62;
&#60;p&#62;You wrote:&#60;br /&#62;
&#38;gt; I have set the prescaler to 2000 and get the precision I wanted, but I fear that during&#60;br /&#62;
&#38;gt; use, will have a variable speed of the vehicle out, what will generate a change in the&#60;br /&#62;
&#38;gt; clock speed of the encoder.&#60;/p&#62;
&#60;p&#62;Variations in the edge-to-edge timing of encoder pulses is normal and to be expected.  The maximum frequency (namely what you expect from your encoder with the vehicle going at its fastest speed), has to be within the specs of the counter/timer on the the CPU chip.  You can also use this max. frequency to figure out how often you must sample the counter, in order to tell the difference between overflow and underflow.  (For example, by sampling fast enough that the counter can only change by 1/4th of the counter's full range.)&#60;/p&#62;
&#60;p&#62;If you would, could you please post the code you're using to set up the timer/counter for accepting your encoder input?  There are several registers involved, several fields in each, so having an example that worked for somebody else would be quite helpful as a starting point.&#60;/p&#62;
&#60;p&#62;Thanks,&#60;/p&#62;
&#60;p&#62;Larry
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "Timer Register Counter is uint32 but timer_get_count(timer_dev *dev) is a uint16"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2196#post-11899</link>
			<pubDate>Sat, 21 Jul 2012 20:31:02 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">11899@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;
where I find this manual?
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;By the way, datasheets and reference manuals for each board are always in the recommended reading in the board's hardware documentation. Example for Maple:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://leaflabs.com/docs/hardware/maple.html#recommended-reading&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/hardware/maple.html#recommended-reading&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "Timer Register Counter is uint32 but timer_get_count(timer_dev *dev) is a uint16"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2196#post-11895</link>
			<pubDate>Sat, 21 Jul 2012 10:08:52 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">11895@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The reference manual can be found here: &#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;/p&#62;
&#60;p&#62;Just a warning, it is a large download.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "Timer Register Counter is uint32 but timer_get_count(timer_dev *dev) is a uint16"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2196#post-11893</link>
			<pubDate>Sat, 21 Jul 2012 09:13:50 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">11893@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;where I find this manual?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bubulindo on "Timer Register Counter is uint32 but timer_get_count(timer_dev *dev) is a uint16"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2196#post-11873</link>
			<pubDate>Fri, 20 Jul 2012 15:07:36 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">11873@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello, &#60;/p&#62;
&#60;p&#62;I don't use messenger.&#60;br /&#62;
I'll have a look at the manual as soon as possible and send you an email about it. &#60;/p&#62;
&#60;p&#62;Maple is probably as new to you as it is to me. ;)&#60;/p&#62;
&#60;p&#62;Best regards, Carlos.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "Timer Register Counter is uint32 but timer_get_count(timer_dev *dev) is a uint16"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2196#post-11866</link>
			<pubDate>Fri, 20 Jul 2012 08:33:50 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">11866@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@ bubulindo&#60;br /&#62;
I'll leave my contact to talk via msn: &#60;a href=&#34;mailto:consultoria@carlosdelfino.eti.br&#34;&#62;consultoria@carlosdelfino.eti.br&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;I'd like to write a short tutorial about my learning, if we succeed, we can work this together, but remember: everything about Maple is very new.&#60;/p&#62;
&#60;p&#62;The Arduino simulates the quatrature from Encoder, Maple reads and counting.&#60;/p&#62;
&#60;p&#62;As soon as possible to put a picture of how to put together all the tests and code on my site.&#60;/p&#62;
&#60;p&#62;-------&#60;br /&#62;
@bubulindo&#60;br /&#62;
Vou deixar meu contato para conversarmos via msn: &#60;a href=&#34;mailto:consultoria@carlosdelfino.eti.br&#34;&#62;consultoria@carlosdelfino.eti.br&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Eu gostaria de escrever um pequeno tutorial sobre meu aprendizado, caso tenhamos sucesso, podemos trabalhar nisto juntos, mas lembre-se: tudo relativo ao Maple é muito novo.&#60;/p&#62;
&#60;p&#62;O Arduino simula a quadratura do Encoder, o Maple le e contabiliza.&#60;/p&#62;
&#60;p&#62;Assim que possível eu coloco as fotos de como montei e o código no meu site.&#60;/p&#62;
&#60;p&#62;Abraços.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bubulindo on "Timer Register Counter is uint32 but timer_get_count(timer_dev *dev) is a uint16"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2196#post-11860</link>
			<pubDate>Fri, 20 Jul 2012 04:50:02 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">11860@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;With encoder counts i meant, do you see the maple counting pulses from your arduino? That is the most important part as it means that you have the hardware ready. Now it's just programming. :) &#60;/p&#62;
&#60;p&#62;I got left there as I didn't have an encoder to test on, and when I got one, work took over my time. But I'll have a look again at the manual and see if I can give you some more help. &#60;/p&#62;
&#60;p&#62;Abraço, um outro Carlos. :)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "Timer Register Counter is uint32 but timer_get_count(timer_dev *dev) is a uint16"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2196#post-11840</link>
			<pubDate>Thu, 19 Jul 2012 21:45:37 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">11840@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi! bubulindo and Larry.&#60;br /&#62;
I have set the prescaler to 2000 and get the precision I wanted, but I fear that during use, will have a variable speed of the vehicle out, what will generate a change in the clock speed of the encoder.&#60;/p&#62;
&#60;p&#62;I did my tests with an Arduino in a simulated encoder clock 33khz.&#60;/p&#62;
&#60;p&#62;I do not understand the question of the encoder count, and have not seen much to configure the hardware. In the case of my &#34;Encoder&#34;, 2000 pulses are emitted every turn.&#60;/p&#62;
&#60;p&#62;Larry, I thought, after reading their comments, if he could use another timer to do the reading, reading and send it to another counter, which also keep a flag indicating the direction, then you know if I should increase or decrease.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>LarryP on "Timer Register Counter is uint32 but timer_get_count(timer_dev *dev) is a uint16"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2196#post-11839</link>
			<pubDate>Thu, 19 Jul 2012 17:45:04 +0000</pubDate>
			<dc:creator>LarryP</dc:creator>
			<guid isPermaLink="false">11839@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@Carlos, &#60;/p&#62;
&#60;p&#62;I agree with the poster above that the first thing is to get the encoder to cause counting.  &#60;/p&#62;
&#60;p&#62;One approach to &#34;widening&#34; an encoder variable is to start by setting a wider int to the initial count (or start both counter and wide int variable at zero.)  On each reading of the counter, you add  the *change* in the counter from the last time you read it to the current wide-integer value; note that this change can be either positive or negative, depending of the direction the encoder is rotating (assuming a quadrature encoder.)  &#60;/p&#62;
&#60;p&#62;In order for this to work, you have to read the counter often enough that you can tell the difference between a counter underflow from a counter overflow.  My rule of thumb has been to read the counter often enough (via ISR or polling) that the encoder can't have caused more than a quarter of the max val the counter can hold.  If you can ensure you read the counter that often, you can disambiguate the sign of the change, and then use the delta to update your wider integer.  HTH.&#60;/p&#62;
&#60;p&#62;If you would, can you describe which pins you're using for your encoder, and whether you're going to encounter both clockwise and counterclockwise rotation?&#60;/p&#62;
&#60;p&#62;Thanks,&#60;/p&#62;
&#60;p&#62;Larry
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bubulindo on "Timer Register Counter is uint32 but timer_get_count(timer_dev *dev) is a uint16"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2196#post-11838</link>
			<pubDate>Thu, 19 Jul 2012 17:12:52 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">11838@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello, &#60;/p&#62;
&#60;p&#62;I ended up not having a chance to follow through on this. &#60;/p&#62;
&#60;p&#62;Have you looked at the prescaler? That can give you quite some accuracy. &#60;/p&#62;
&#60;p&#62;Have you seen the encoder count already? One of my biggest doubts in the beginning was the hardware setup (port configuration mostly).
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "Timer Register Counter is uint32 but timer_get_count(timer_dev *dev) is a uint16"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2196#post-11834</link>
			<pubDate>Thu, 19 Jul 2012 08:06:09 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">11834@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi peoples!!!&#60;/p&#62;
&#60;p&#62;I using a Timer for create a Odometer with a Encoder, but I need a big counter, like a uint32 or more, like a uint64, i need test on field for get the limit.&#60;/p&#62;
&#60;p&#62;How I can grow the limit of Timer count, for get more.&#60;/p&#62;
&#60;p&#62;And more, I need count 1 each 2000 clock from Encoder, someone could help me?&#60;/p&#62;
&#60;p&#62;I use this code:&#60;/p&#62;
&#60;p&#62;const uint8 enconder_prescaler = 2000;&#60;/p&#62;
&#60;p&#62;void configEncoder(){&#60;br /&#62;
timer_init(TIMER2);&#60;br /&#62;
timer_cc_set_pol(TIMER2, 1, 1);&#60;br /&#62;
timer_cc_set_pol(TIMER2, 2, 1);&#60;br /&#62;
timer_get_reg_map(TIMER2)-&#38;gt;CCMR1 &#124;= TIMER_CCMR1_CC1S; //set both channels&#60;br /&#62;
timer_get_reg_map(TIMER2)-&#38;gt;SMCR &#124;= TIMER_SMCR_SMS_ENCODER1 &#124; TIMER_SMCR_SMS_ENCODER2;&#60;br /&#62;
timer_set_prescaler(TIMER2, encoder_prescaler);&#60;br /&#62;
timer_resume(TIMER2);&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;char* readEncoder(){&#60;br /&#62;
newPosition = timer_get_count(TIMER2) &#38;gt;&#38;gt; 2;&#60;/p&#62;
&#60;p&#62;// abs() avita que a direção tenha mudado&#60;br /&#62;
// e o valor esteja negativo devido a contagem invertida e atrasos&#60;br /&#62;
if(newPosition != oldPosition &#124;&#124; isForceRead()){&#60;br /&#62;
direction = (newPosition &#38;gt; oldPosition &#38;amp;&#38;amp; abs(newPosition-oldPosition) &#38;lt;30);&#60;br /&#62;
concat(bufE, bufESize, oldPosition, newPosition, direction);&#60;br /&#62;
oldPosition = newPosition;&#60;/p&#62;
&#60;p&#62;}&#60;br /&#62;
else{&#60;br /&#62;
return &#34;&#34;;&#60;br /&#62;
}&#60;br /&#62;
return bufE;&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;Based in this post: &#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=1566#post-10229&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=1566#post-10229&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Thanks.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
