<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Helvetica;
panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
{font-family:Helvetica;
panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
pre
{mso-style-priority:99;
mso-style-link:"Préformaté HTML Car";
margin:0cm;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Texte de bulles Car";
margin:0cm;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.apple-converted-space
{mso-style-name:apple-converted-space;}
span.EmailStyle19
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.PrformatHTMLCar
{mso-style-name:"Préformaté HTML Car";
mso-style-priority:99;
mso-style-link:"Préformaté HTML";
font-family:Consolas;}
span.EmailStyle22
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.TextedebullesCar
{mso-style-name:"Texte de bulles Car";
mso-style-priority:99;
mso-style-link:"Texte de bulles";
font-family:"Tahoma","sans-serif";}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=FR-CA link=blue vlink=purple><div class=WordSection1><p><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>></span><span lang=EN-CA> Typically I'd use a 1 ms timer to poll the switch and run a state machine. State machine would look for the encoder changing, start a count down timer for<br>> debouncing, when timer is 0 read encoder and compare it to last stable value to see if it has changed.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>That’s exactly what I had coded before the hardware ‘solution’.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Polling the 3 encoder pins. <u>Everything was working fine</u> until I added some<br>code to process the encoder changes. Then BOOM..<br>Many missed counts everywhere (increments/decrements).<br>The interrupt style was even harder to implement since there were<br>4 different states to read before any final counts.<br>A $2 bucks chips solution makes me spend my time<br>elsewhere in my project releasing.<br>Again..<o:p></o:p></span></p><p class=MsoNormal><u><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Any simple</span></u><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>, fast and reliable interrupt driven code to suggest ??<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Managing all the encoder 4 steps with debouncing too ?<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=FR style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>De :</span></b><span lang=FR style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Synth-diy [mailto:synth-diy-bounces@synth-diy.org] <b>De la part de</b> Jay Schwichtenberg via Synth-diy<br><b>Envoyé :</b> 11 août 2021 20:14<br><b>À :</b> synth-diy@synth-diy.org<br><b>Objet :</b> Re: [sdiy] Rotary encoder reading.. hardware solution (fast & accurate)<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p>I agree with Tom, this is a trivial uC problem that can be solved with about a page of firmware.<o:p></o:p></p><p>Don't know where there is any code out there for this. Might check out in Arduino land or MicroChip.<o:p></o:p></p><p>I can think of 4-6 ways of doing this, depends on what else the uC needs to do.<o:p></o:p></p><p>Typically I'd use a 1 ms timer to poll the switch and run a state machine. State machine would look for the encoder changing, start a count down timer for debouncing, when timer is 0 read encoder and compare it to last stable value to see if it has changed.<o:p></o:p></p><p>Jay S.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>On 8/11/2021 3:53 PM, Jean-Pierre Desrochers wrote:<o:p></o:p></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><p class=MsoNormal><u><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Any simple</span></u><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>, fast and reliable interrupt driven code to suggest ??</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Managing all the encoder 4 steps with debouncing too ?</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=FR style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>De :</span></b><span lang=FR style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Tom Wiltshire [<a href="mailto:tom@electricdruid.net">mailto:tom@electricdruid.net</a>] <br><b>Envoyé :</b> 11 août 2021 18:38<br><b>À :</b> Jean-Pierre Desrochers<br><b>Cc :</b> SDIY<br><b>Objet :</b> Re: [sdiy] Rotary encoder reading.. hardware solution (fast & accurate)</span><o:p></o:p></p></div></div><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal>Gagh! Two whole chips to save writing a few lines of code! Heresy! ;)<o:p></o:p></p><div><p class=MsoNormal> <o:p></o:p></p></div><div><p class=MsoNormal>Tom<o:p></o:p></p><div><div><p class=MsoNormal> <o:p></o:p></p></div></div><div><p class=MsoNormal><br><br><br><o:p></o:p></p><div><p class=MsoNormal>On 11 Aug 2021, at 21:27, Jean-Pierre Desrochers <<a href="mailto:jpdesroc@oricom.ca">jpdesroc@oricom.ca</a>> wrote:<o:p></o:p></p></div><p class=MsoNormal> <o:p></o:p></p><div><div><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>For anybody who could be interested..</span><o:p></o:p></p></div><div><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Just found this video yesterday and tried the circuit..</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><a href="https://www.youtube.com/watch?v=UlehqasO-fo&t=1471s"><span style='color:purple'>https://www.youtube.com/watch?v=UlehqasO-fo&t=1471s</span></a></span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p></div><div><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Outputs A and B (CD4013) connected to PORTB of a PIC16F1783</span><o:p></o:p></p></div><div><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>(RB0 and RB1) using interrupts on change (rising edges).</span><o:p></o:p></p></div><div><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Now I only have to check one incoming pulse on each RB0 & RB1</span><o:p></o:p></p></div><div><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>to increment or decrement a counter.<br>Much faster than computing all the 4 possible states in each encoder step<br>to finally get a result.</span><o:p></o:p></p></div><div><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>My interrupt uses TIMER1 (1msec steps), RB0 & RB1 on change.</span><o:p></o:p></p></div><div><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>No missing counts anymore even rotating fast, on both direction.</span><o:p></o:p></p></div><div><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p></div><div><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><image001.jpg></span><o:p></o:p></p></div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Helvetica","sans-serif"'>_______________________________________________<br>Synth-diy mailing list<br></span><a href="mailto:Synth-diy@synth-diy.org"><span style='font-size:9.0pt;font-family:"Helvetica","sans-serif";color:purple'>Synth-diy@synth-diy.org</span></a><span style='font-size:9.0pt;font-family:"Helvetica","sans-serif"'><br></span><a href="http://synth-diy.org/mailman/listinfo/synth-diy"><span style='font-size:9.0pt;font-family:"Helvetica","sans-serif";color:purple'>http://synth-diy.org/mailman/listinfo/synth-diy</span></a><span style='font-size:9.0pt;font-family:"Helvetica","sans-serif"'><br>Selling or trading? Use<span class=apple-converted-space> </span></span><a href="mailto:marketplace@synth-diy.org"><span style='font-size:9.0pt;font-family:"Helvetica","sans-serif";color:purple'>marketplace@synth-diy.org</span></a><o:p></o:p></p></div></div><p class=MsoNormal> <o:p></o:p></p></div><p class=MsoNormal><br><br><o:p></o:p></p><pre>_______________________________________________<o:p></o:p></pre><pre>Synth-diy mailing list<o:p></o:p></pre><pre><a href="mailto:Synth-diy@synth-diy.org">Synth-diy@synth-diy.org</a><o:p></o:p></pre><pre><a href="http://synth-diy.org/mailman/listinfo/synth-diy">http://synth-diy.org/mailman/listinfo/synth-diy</a><o:p></o:p></pre><pre>Selling or trading? Use <a href="mailto:marketplace@synth-diy.org">marketplace@synth-diy.org</a><o:p></o:p></pre></blockquote></div></body></html>