<?xml version="1.0" encoding="UTF-8"?><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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Vigorius stirring redefined. Part 2 &#8211; electronics</title>
	<atom:link href="http://www.circuitsathome.com/mcu/programming/vigorius-stirring-redefined-part-2-electronics/feed" rel="self" type="application/rss+xml" />
	<link>http://www.circuitsathome.com/mcu/vigorius-stirring-redefined-part-2-electronics</link>
	<description>A Solder Joint</description>
	<lastBuildDate>Thu, 17 May 2012 05:09:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Reading rotary encoder on Arduino &#171; Circuits@Home</title>
		<link>http://www.circuitsathome.com/mcu/vigorius-stirring-redefined-part-2-electronics/comment-page-1#comment-280</link>
		<dc:creator>Reading rotary encoder on Arduino &#171; Circuits@Home</dc:creator>
		<pubDate>Mon, 12 Apr 2010 21:44:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.circuitsathome.com/?p=1484#comment-280</guid>
		<description>[...] cheap low-quality encoders, but is somewhat cryptic and difficult to understand. Soon after posting one of my projects where I used rotary encoder to set motor speed i started receiving e-mails asking to explain the [...]</description>
		<content:encoded><![CDATA[<p>[...] cheap low-quality encoders, but is somewhat cryptic and difficult to understand. Soon after posting one of my projects where I used rotary encoder to set motor speed i started receiving e-mails asking to explain the [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cory</title>
		<link>http://www.circuitsathome.com/mcu/vigorius-stirring-redefined-part-2-electronics/comment-page-1#comment-279</link>
		<dc:creator>Cory</dc:creator>
		<pubDate>Sat, 13 Mar 2010 20:23:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.circuitsathome.com/?p=1484#comment-279</guid>
		<description>Duh!  I should have known that lol

Thanks again,
Cory</description>
		<content:encoded><![CDATA[<p>Duh!  I should have known that lol</p>
<p>Thanks again,<br />
Cory</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: oleg</title>
		<link>http://www.circuitsathome.com/mcu/vigorius-stirring-redefined-part-2-electronics/comment-page-1#comment-278</link>
		<dc:creator>oleg</dc:creator>
		<pubDate>Thu, 11 Mar 2010 05:14:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.circuitsathome.com/?p=1484#comment-278</guid>
		<description>If you want your enc_value to be larger than 255, it needs to be declared as unsigned int. It&#039;s currently declared as byte AKA unsigned char which is 8 bits.</description>
		<content:encoded><![CDATA[<p>If you want your enc_value to be larger than 255, it needs to be declared as unsigned int. It&#8217;s currently declared as byte AKA unsigned char which is 8 bits.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cory</title>
		<link>http://www.circuitsathome.com/mcu/vigorius-stirring-redefined-part-2-electronics/comment-page-1#comment-277</link>
		<dc:creator>Cory</dc:creator>
		<pubDate>Thu, 11 Mar 2010 05:00:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.circuitsathome.com/?p=1484#comment-277</guid>
		<description>I really like the simplicity of this code and I want to use it in my project, but I&#039;m running into a problem.  My encoders are 624 counts per revolution but the code seems to max out at 255 even if I change the :
if( enc_value == 255 ) to if( enc_value == 624 ) .

I even tried changing from PINC to PINB thinking that the analog pins were maxed at 255.

Thanks,
Cory</description>
		<content:encoded><![CDATA[<p>I really like the simplicity of this code and I want to use it in my project, but I&#8217;m running into a problem.  My encoders are 624 counts per revolution but the code seems to max out at 255 even if I change the :<br />
if( enc_value == 255 ) to if( enc_value == 624 ) .</p>
<p>I even tried changing from PINC to PINB thinking that the analog pins were maxed at 255.</p>
<p>Thanks,<br />
Cory</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: oleg</title>
		<link>http://www.circuitsathome.com/mcu/vigorius-stirring-redefined-part-2-electronics/comment-page-1#comment-276</link>
		<dc:creator>oleg</dc:creator>
		<pubDate>Thu, 31 Dec 2009 19:05:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.circuitsathome.com/?p=1484#comment-276</guid>
		<description>Somehow your previous post with code ended up in spam folder and I haven&#039;t noticed it until today. Anyway, It&#039;s nice that you had encoder control sorted out!</description>
		<content:encoded><![CDATA[<p>Somehow your previous post with code ended up in spam folder and I haven&#8217;t noticed it until today. Anyway, It&#8217;s nice that you had encoder control sorted out!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brad</title>
		<link>http://www.circuitsathome.com/mcu/vigorius-stirring-redefined-part-2-electronics/comment-page-1#comment-275</link>
		<dc:creator>Brad</dc:creator>
		<pubDate>Thu, 31 Dec 2009 03:37:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.circuitsathome.com/?p=1484#comment-275</guid>
		<description>After a bit of twiddling I got it working - Oleg, I have to say that this is THE most elegant rotary encoder solution I have seen. I have spent the past week or so working with different routines for quadrature encoders and this is just absolutely awesome.

Thanks very much!

Brad</description>
		<content:encoded><![CDATA[<p>After a bit of twiddling I got it working &#8211; Oleg, I have to say that this is THE most elegant rotary encoder solution I have seen. I have spent the past week or so working with different routines for quadrature encoders and this is just absolutely awesome.</p>
<p>Thanks very much!</p>
<p>Brad</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brad</title>
		<link>http://www.circuitsathome.com/mcu/vigorius-stirring-redefined-part-2-electronics/comment-page-1#comment-274</link>
		<dc:creator>Brad</dc:creator>
		<pubDate>Thu, 31 Dec 2009 03:21:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.circuitsathome.com/?p=1484#comment-274</guid>
		<description>Oleg, yours is the most elegant and simple code for reading an encoder I have seen... only it doesn&#039;t work for me! Would you mind looking over what I have here and possibly giving me a suggestion?

&lt;code&gt;
#include
#fuses HS,NOWDT,NOPROTECT,NOLVP,BROWNOUT,PUT,NOPBADEN,DEBUG
#use delay(clock=20M)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#include

signed char enc_states[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
byte old_AB = 0;
byte enc_value = 127;
byte old_enc_value = 0;

void encoder0Loop(void) {     // int8 enc_value
   old_AB &lt;&lt;= 2;    //remember previous state by shifting the lower bits up 2
   old_AB &#124;= ( portb &amp; 0x03 );      // AND the lower 2 bits of port b, then OR them with var old_AB to set new value
   enc_value += enc_states[( old_AB &amp; 0x0f )];     // the lower 4 bits of old_AB &amp; 16 are then the index for enc_states
      if ( enc_value == old_enc_value ) {
     return;
   }
   if( enc_value == 255 ) {       // Original line
     enc_value = 0;
   }
   printf(&quot;enc_value = %3d, old_AB = %3d, old_enc_value = %3d\n\r&quot;,enc_value,old_AB,old_enc_value);  // debugging...
   printf(lcd_putc,&quot;\fEncoder 0 = %d\n&quot;,enc_value);
   old_enc_value = enc_value;
   // set whatever variable you need to increment to enc_value here...
   }
//////////////////////////////////////////////////////////////////#int_TIMER0
void timer0_isr()
   {
      output_toggle(PIN_A2);     // let me know it&#039;s alive...
   }
//////////////////////////////////////////////////////////////////

void main(void) {

   port_b_pullups(true);
   setup_adc_ports(NO_ANALOGS);
   set_tris_b(255);
   input_b();
   ENABLE_INTERRUPTS(global);
   ENABLE_INTERRUPTS(INT_TIMER0);
   SETUP_TIMER_0(RTCC_INTERNAL &#124; RTCC_DIV_32);

   printf(&quot;\n\r\rRotary Encoder Test 2\n\n\r&quot;);
   printf(lcd_putc,&quot;\fRotary Encoder\nTest 2&quot;);
   delay_ms(1000);

   while (true)
   {
      encoder0Loop();
   }     // end of while loop

}        // end of main
&lt;/code&gt;

I have scoped the encoder and it is working properly; currently this runs through the loop endlessly, with no response to the encoder at all! Any help would be greatly appreciated, but no problem if you don&#039;t want to!

Thanks,
Brad</description>
		<content:encoded><![CDATA[<p>Oleg, yours is the most elegant and simple code for reading an encoder I have seen&#8230; only it doesn&#8217;t work for me! Would you mind looking over what I have here and possibly giving me a suggestion?</p>
<p><code><br />
#include<br />
#fuses HS,NOWDT,NOPROTECT,NOLVP,BROWNOUT,PUT,NOPBADEN,DEBUG<br />
#use delay(clock=20M)<br />
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)<br />
#include</p>
<p>signed char enc_states[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};<br />
byte old_AB = 0;<br />
byte enc_value = 127;<br />
byte old_enc_value = 0;</p>
<p>void encoder0Loop(void) {     // int8 enc_value<br />
   old_AB &lt;&lt;= 2;    //remember previous state by shifting the lower bits up 2<br />
   old_AB |= ( portb &amp; 0x03 );      // AND the lower 2 bits of port b, then OR them with var old_AB to set new value<br />
   enc_value += enc_states[( old_AB &amp; 0x0f )];     // the lower 4 bits of old_AB &amp; 16 are then the index for enc_states<br />
      if ( enc_value == old_enc_value ) {<br />
     return;<br />
   }<br />
   if( enc_value == 255 ) {       // Original line<br />
     enc_value = 0;<br />
   }<br />
   printf(&quot;enc_value = %3d, old_AB = %3d, old_enc_value = %3d\n\r&quot;,enc_value,old_AB,old_enc_value);  // debugging...<br />
   printf(lcd_putc,&quot;\fEncoder 0 = %d\n&quot;,enc_value);<br />
   old_enc_value = enc_value;<br />
   // set whatever variable you need to increment to enc_value here...<br />
   }<br />
//////////////////////////////////////////////////////////////////#int_TIMER0<br />
void timer0_isr()<br />
   {<br />
      output_toggle(PIN_A2);     // let me know it&#039;s alive...<br />
   }<br />
//////////////////////////////////////////////////////////////////</p>
<p>void main(void) {</p>
<p>   port_b_pullups(true);<br />
   setup_adc_ports(NO_ANALOGS);<br />
   set_tris_b(255);<br />
   input_b();<br />
   ENABLE_INTERRUPTS(global);<br />
   ENABLE_INTERRUPTS(INT_TIMER0);<br />
   SETUP_TIMER_0(RTCC_INTERNAL | RTCC_DIV_32);</p>
<p>   printf(&quot;\n\r\rRotary Encoder Test 2\n\n\r&quot;);<br />
   printf(lcd_putc,&quot;\fRotary Encoder\nTest 2&quot;);<br />
   delay_ms(1000);</p>
<p>   while (true)<br />
   {<br />
      encoder0Loop();<br />
   }     // end of while loop</p>
<p>}        // end of main<br />
</code></p>
<p>I have scoped the encoder and it is working properly; currently this runs through the loop endlessly, with no response to the encoder at all! Any help would be greatly appreciated, but no problem if you don&#8217;t want to!</p>
<p>Thanks,<br />
Brad</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: oleg</title>
		<link>http://www.circuitsathome.com/mcu/vigorius-stirring-redefined-part-2-electronics/comment-page-1#comment-273</link>
		<dc:creator>oleg</dc:creator>
		<pubDate>Wed, 30 Dec 2009 23:32:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.circuitsathome.com/?p=1484#comment-273</guid>
		<description>Encoder&#039;s A and B pins are connected to Atmega&#039;s PORTC pins 0 and 1. The name for the whole port byte is PINC. The magic happens on line 33 :-). &#039;PINC &amp; 0x03&#039; clears upper 6 bits of whatever was read from PORTC leaving bits 0 and 1 intact. &#039;old_AB &#124;= ( PINC &amp; 0x03 )&#039; generates an index for enc_states. This code would work on a PIC with almost no changes, the port name being the only one. You would need to have your encoder connected to 2 lower bits of a port, otherwise the code would become more complex.</description>
		<content:encoded><![CDATA[<p>Encoder&#8217;s A and B pins are connected to Atmega&#8217;s PORTC pins 0 and 1. The name for the whole port byte is PINC. The magic happens on line 33 <img src='http://www.circuitsathome.com/wp/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . &#8216;PINC &amp; 0&#215;03&#8242; clears upper 6 bits of whatever was read from PORTC leaving bits 0 and 1 intact. &#8216;old_AB |= ( PINC &amp; 0&#215;03 )&#8217; generates an index for enc_states. This code would work on a PIC with almost no changes, the port name being the only one. You would need to have your encoder connected to 2 lower bits of a port, otherwise the code would become more complex.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brad</title>
		<link>http://www.circuitsathome.com/mcu/vigorius-stirring-redefined-part-2-electronics/comment-page-1#comment-272</link>
		<dc:creator>Brad</dc:creator>
		<pubDate>Wed, 30 Dec 2009 22:56:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.circuitsathome.com/?p=1484#comment-272</guid>
		<description>I guess what I&#039;m asking is, how do you read your encoder?? (Like you said, outputting the question clariefies it in your mind!)</description>
		<content:encoded><![CDATA[<p>I guess what I&#8217;m asking is, how do you read your encoder?? (Like you said, outputting the question clariefies it in your mind!)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brad</title>
		<link>http://www.circuitsathome.com/mcu/vigorius-stirring-redefined-part-2-electronics/comment-page-1#comment-271</link>
		<dc:creator>Brad</dc:creator>
		<pubDate>Wed, 30 Dec 2009 22:44:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.circuitsathome.com/?p=1484#comment-271</guid>
		<description>Neat stuff, Oleg!

I&#039;m trying to borrow your encoder routine to use in my PIC 18F4620... I&#039;ve got a couple of questions, though.

In line 33, you AND PINC &amp; 0x03, and then OR it with old_AB... what is PINC connected to? How to you get your encoder0PinA &amp; B input values into enc_value? (I&#039;m guessing here...)

Thanks for a great website and projects!</description>
		<content:encoded><![CDATA[<p>Neat stuff, Oleg!</p>
<p>I&#8217;m trying to borrow your encoder routine to use in my PIC 18F4620&#8230; I&#8217;ve got a couple of questions, though.</p>
<p>In line 33, you AND PINC &amp; 0&#215;03, and then OR it with old_AB&#8230; what is PINC connected to? How to you get your encoder0PinA &amp; B input values into enc_value? (I&#8217;m guessing here&#8230;)</p>
<p>Thanks for a great website and projects!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

