<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html><body>
<p>Hi Volker,</p>
<p><span style="font-size: 12px;">I couldn't be bothererd to learn the math so the tap positions (the constant of 0x30) was found trail and error - it isn't that hard as knowing that a 5-bit two-tap design is possible <span>the are only 4 options (0x30, 0x28, 0x24, 0x22 and 0x21)</span>. </span><span style="font-size: 12px;">Once I had a maximal LFSR (it goes through all 63 possible states), it was just a case of running it forward a few states to get the 0x22 constant for the start/reset value.</span></p>
<p>As to what application? Well, I've been getting a bit pain for putting up FPGA designs that that people are handing in as answers to their coursework, and I am going to put my digital clock up on my wiki. As a digital clock is a common course assignment, so I am including a few Easter Eggs to upset the lazy student .</p>
<p>To divide the 32MHz XTAL signal to get a pulse per second signal (pps) rather than a simple counter that goes from 0-31999999 I'm doing this:</p>
<pre>      if rising_edge(clk) then
         if lfsr  = "1111111111111111111111111" then
            lfsr <= "0111110111010111001000000";
            pps  <= '1';
         else
            lfsr <= (lfsr(0) xor lfsr(3)) & lfsr(lfsr'high downto 1);
            pps  <= '0';
         end if;
      end if;<br /><br />Likewise, to count minutes and seconds I'm using 6-bit  LFSRs rather than regular counters, and for the minute set and clock set buttons.<br /><br />The high level structure is just the same, the output is just the same, but good luck explaining that one to your teacher if you hand it in as homework.<br /><br />Mike</pre>
<p><span style="font-size: 12px;">On 20.11.2014 07:41, Volker Kuhlmann wrote:</span></p>
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%"><!-- html ignored --><!-- head ignored --><!-- meta ignored -->
<pre>On Wed 19 Nov 2014 22:07:12 NZDT +1300, Michael Field wrote:</pre>
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">static int chocolate_fish_challenge(void) { static unsigned char reg = 0x22; if(reg) { reg = (reg >> 1) ^ ((reg & 1) ? 0 : 0x30); return 0; } reg = 0x22; return 1; }</blockquote>
<pre>Interesting!
How did you find the start value, early exit condition and tap positions?

What application do you have requiring this? Incrementing a counter to
60 gives shorter code, faster execution, and a lot less maintenance
headache for the same memory requirements.

Thanks,

Volker
</pre>
</blockquote>
<p> </p>
<div> </div>
</body></html>