Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/24/07 03:12
Read: times


 
Msg Score: +1
 +1 Informative
#146108 - OP Update 9 of ?
Responding to: ???'s previous message
Well, today was a good day. I finished the last of the modules for the Morse code decoder, wired them all together in a top level module, loaded them into the Xilinx evaluation board, and it kinda, sorta, almost actually worked. Imagine that. Of course I had debugged the individual modules one by one in the simulator beforehand. And Andy and Jez and Richard saved me from falling more than a few times ... many thanks for that.

I'll explain later what "kinda, sorta, almost" means. But first I want to show what I did and ask the experts out there for a critique. In particular, I'm wondering about questions like these:
  • What have I done that looks goofy or stupid or naive? (BTW, I have figured out a few things like tasks and the repeat statement since I wrote some of the testbenches, so there won't be so much cut and paste repetition in future projects.)

  • Is my partitioning of the whole project into individual modules about right? It seems like a good idea to avoid big modules for the same reasons that it's a good idea to avoid big subroutines in C. But with very small modules, it seems like you'd spend all day writing module interfaces and never get anything else done. Did I come anywhere close to the sweet spot?

  • After having gone through this, it's real clear that what I've figured out is only a very small part of what a guy would need to know in order to call himself an FPGA designer. For example, at this point I don't have any feel at all for the architecture of the device. I haven't looked at all at what it takes to tune a design to make it smaller or faster. I haven't messed with any kind of timing simulations. I haven't done any gate level stuff. I don't understand 90% of the information in the reports that the software spits out. Etc., etc., etc. Can anyone suggest a good follow-on "stumble and fall" type project that might force me to dig into some of these things?
The Design

Here's a top-level block diagram of the Morse code decoder:


and here is the code that implements it:

Implementation

I made most of the diagrams here before I did very much of the implementation. As a result, they may not match the Verilog code exactly. But they are close. For the record, I've been using the word mark to mean either a dit or a dah, and space to mean the silent periods between the dits and the dahs. For lack of a better word, I've been using event to mean either a mark or a space.

The topmost block in the diagram above watches the input line for transitions in either direction. For each one, it spits out the duration of the mark or space just ending (this is just the time since the previous transition), along with a single bit to indicate whether it was a mark or a space. Here are links to details for this block:

Diagram | Implementation | Testbench

The FIFO in the middle of the diagram buffers the raw event information for use later by the decoder below it. Here are links to details for this block:

Implementation | Testbench

There's a little state machine inside the decoder that grabs events one by one from the bottom of the FIFO and assembles them into Morse code characters. The decoder then uses a simple table lookup scheme to translate sequences of dits and dahs into the corresponding ASCII codes. The state machine is in one module and the character translation table in another. Here are the details:

Decoder state machine:
Implementation | Testbench

Character translation table:
Implementation

Finally, the block at the bottom serializes the ASCII codes into an RS232 bitstream that something like Hyperterminal can display. Here are the details:

Implementation | Testbench

But wait! How does the decoder know the difference between the dits and the dahs? Well, everyone knows that dahs are longer than dits, but the decoder needs an actual threshold between the two to sort out the raw event information from the FIFO. The block on the left side of the picture watches the marks as they occur, discriminates the long ones from the short ones, and generates the threshold that the decoder needs.

The threshold detector block contains four modules. Two of them are identical averagers that keep a running average of the lengths of the dits and dahs. As it turns out, they use the very same filtering mechanism discussed here:

Diagram | Implementation | Testbench

The third module within the threshold detector works at startup to put short marks into the "dit" averager and long marks into the "dah" averager in order to get things started. Once the running averages have been established, then this tentative approach is abandoned and the output of the threshold detector is used to discriminate the incoming dits and dahs. Here are the details for this module:

Diagram | Implementation | Testbench

The last module in the threshold detector is one that simply ties the other three together:

Diagram | Implementation | Testbench

The Result

As I mentioned, the decoder as presented "kinda, sorta, almost" works. There are two problems at this point. One is a simple matter of key bounce. I need to work out some sort of filtering scheme that eliminates spurious transitions on the input signal without wiping out legitimate dits if somebody is sending really fast. A simple RC filter might be just the thing. Or maybe another averager in the FPGA.

A worse problem is that I didn't design in any way to handle the long spaces between words, or the very long space when the input simply ends. As a result,

THEWORDSRUNTOGETHERANDTHELASTCHARACTERNEVERGETSTRANSMITTE

This is something I definitely should have thought about earlier. It remains to be seen if the fix turns out to be really ugly or just the regular kind.

-- Russ



List of 147 messages in thread
TopicAuthorDate
Getting Started With FPGAs, Part II            01/01/70 00:00      
   I didn't find it too big a job ... YMMV, of course            01/01/70 00:00      
   when it doesnt work            01/01/70 00:00      
      I'd guess...            01/01/70 00:00      
         Curses            01/01/70 00:00      
   OP Update 1 of ???            01/01/70 00:00      
      On your way ...            01/01/70 00:00      
         Not windows this time?            01/01/70 00:00      
            Not Windows every time, anyway            01/01/70 00:00      
      re: OP Update            01/01/70 00:00      
         what might be helpful before you get too far along            01/01/70 00:00      
   OP Update 2 of ???            01/01/70 00:00      
      re: update            01/01/70 00:00      
         The Verilog == C trap            01/01/70 00:00      
            re: The Verilog == C trap            01/01/70 00:00      
               Thinking hardware            01/01/70 00:00      
                  I read somewhere ...            01/01/70 00:00      
                  re: Thinking Hardware            01/01/70 00:00      
               One reason why HDL isnt the same as software            01/01/70 00:00      
                  Have I got this right?            01/01/70 00:00      
                     re: Have I got this right?            01/01/70 00:00      
                        re: re: Have I got this right?            01/01/70 00:00      
                           re: OT            01/01/70 00:00      
                        Nothing\'s perfect            01/01/70 00:00      
                        The thing to watch with FPGA's            01/01/70 00:00      
   OP Update 3 of ?            01/01/70 00:00      
      have you looked at the resource utilization?            01/01/70 00:00      
         Just a little bit            01/01/70 00:00      
            On a slightly different note..            01/01/70 00:00      
               the lesson ...            01/01/70 00:00      
               HDL coding to "help" the synthesizer            01/01/70 00:00      
         Please clarify            01/01/70 00:00      
            think hardware            01/01/70 00:00      
               this sounds like...            01/01/70 00:00      
                  re: this sounds like            01/01/70 00:00      
               Please clarify again            01/01/70 00:00      
                  for purpose of understanding ... YES            01/01/70 00:00      
                  answer            01/01/70 00:00      
      double assignment            01/01/70 00:00      
         Good catch, I think            01/01/70 00:00      
            re: Good Catch            01/01/70 00:00      
      block vs nonblocking            01/01/70 00:00      
         I have unplugged my eval board            01/01/70 00:00      
            re: Unplugged            01/01/70 00:00      
   OP Update 4 of ?            01/01/70 00:00      
      Another question about the counter            01/01/70 00:00      
         what's wrong            01/01/70 00:00      
            \'initial\' block            01/01/70 00:00      
               general Verilog coding advice            01/01/70 00:00      
                  Wow            01/01/70 00:00      
            Where does "reset" come from?            01/01/70 00:00      
   OP Dumb Question 1 of ?            01/01/70 00:00      
      look at it in the other way            01/01/70 00:00      
         But isn\'t it out of spec?            01/01/70 00:00      
            If you look more closely at the spec ...            01/01/70 00:00      
         which tools?            01/01/70 00:00      
            fanout exceeded            01/01/70 00:00      
               device dependence            01/01/70 00:00      
      newer data sheet?            01/01/70 00:00      
      Metastability            01/01/70 00:00      
         ... and contact bounce            01/01/70 00:00      
            That might not be a worry ...            01/01/70 00:00      
               Thanks            01/01/70 00:00      
   OP Update 5 of ?            01/01/70 00:00      
      do you mean, adaptive threshold?            01/01/70 00:00      
         Yes            01/01/70 00:00      
            PicoBlaze            01/01/70 00:00      
               Andy ... about that PicoBlaze ...            01/01/70 00:00      
                  re: about picoblaze            01/01/70 00:00      
         the boundary is quite arbitrary            01/01/70 00:00      
            Yes            01/01/70 00:00      
   OP Update 6 of ?            01/01/70 00:00      
      a better way            01/01/70 00:00      
   OP Update 7 of ?            01/01/70 00:00      
      OP Update 7.01            01/01/70 00:00      
         excessive skew warning            01/01/70 00:00      
            Offensive code here            01/01/70 00:00      
               On a slightly different note            01/01/70 00:00      
                  whatizit?            01/01/70 00:00      
                  free vs paid-for ModelSim            01/01/70 00:00      
               reason for the skew warning            01/01/70 00:00      
                  error            01/01/70 00:00      
                  I\\\'m drinking from a fire hose!            01/01/70 00:00      
                     fIREHOSE            01/01/70 00:00      
                        Faucet            01/01/70 00:00      
                           faucet            01/01/70 00:00      
                              Slow drip            01/01/70 00:00      
                                 I have no particular interest in this - but            01/01/70 00:00      
                                    Famous last words...            01/01/70 00:00      
                                       sure, I take your point - but            01/01/70 00:00      
                                 What libraries you use in VHDL            01/01/70 00:00      
                                    std_logic_arith vs numeric_std            01/01/70 00:00      
                              I found the FM!            01/01/70 00:00      
                                 Development System Reference Guide            01/01/70 00:00      
                           Another slow drip            01/01/70 00:00      
                              doubts            01/01/70 00:00      
                              I am not surprised it doesn\'t find that            01/01/70 00:00      
                              I was surprised            01/01/70 00:00      
                              If you want to see how the logic was synthesized            01/01/70 00:00      
                                 Don't cares worked for me            01/01/70 00:00      
                                    Not quite what I meant            01/01/70 00:00      
                                       Bummer            01/01/70 00:00      
                                          I wouldn't worry about minimizing            01/01/70 00:00      
                                             Thanks            01/01/70 00:00      
                              re: drip            01/01/70 00:00      
                                 re: re: drip            01/01/70 00:00      
                                    huh?            01/01/70 00:00      
                                       re: huh?            01/01/70 00:00      
                                          defaults?            01/01/70 00:00      
                                             re: defaults?            01/01/70 00:00      
                                             ***** Interesting result! ******            01/01/70 00:00      
                                          challenge            01/01/70 00:00      
                                             unknown is not don't care            01/01/70 00:00      
                                                A noob question            01/01/70 00:00      
                                                   similar noob question            01/01/70 00:00      
                                                      re: what happens            01/01/70 00:00      
                                                   You should get a latch            01/01/70 00:00      
                                                   re: a noob question            01/01/70 00:00      
                                                      Not really answered            01/01/70 00:00      
                                                         I'd guess...            01/01/70 00:00      
                           Simulator question            01/01/70 00:00      
                              what you are seeing            01/01/70 00:00      
                                 Thanks, Jez            01/01/70 00:00      
                                    check the logic!            01/01/70 00:00      
                                       That's good news            01/01/70 00:00      
                                          this might make the key difference            01/01/70 00:00      
                                             Two flavors of \"big\"            01/01/70 00:00      
                                                drop the comments :-)            01/01/70 00:00      
                                             as has been recommended ...            01/01/70 00:00      
                                          My confidence in XILINX' simulator is low            01/01/70 00:00      
                                             Xilinx vs. ModelSim            01/01/70 00:00      
                                                It's worth using ModelSim just for the features            01/01/70 00:00      
                                          behavioral is good,kind of            01/01/70 00:00      
                                             re: behavioral is good, kind of            01/01/70 00:00      
                                       Double post. Oops.            01/01/70 00:00      
                                 not so simple            01/01/70 00:00      
                              re: Simulator Question: ANSWER            01/01/70 00:00      
                                 re: ANSWER            01/01/70 00:00      
                                 re: ANSWER, Part II            01/01/70 00:00      
                        Long time            01/01/70 00:00      
      one more comment            01/01/70 00:00      
   OP Update 8 of ?            01/01/70 00:00      
      its supposed to make things easier to debug            01/01/70 00:00      
      one way vs the other way            01/01/70 00:00      
         re: Them two ways            01/01/70 00:00      
   OP Update 9 of ?            01/01/70 00:00      
   OP Update 10 of 10            01/01/70 00:00      

Back to Subject List