MORSE TRANSMITTER

Example of a simple Morse code transmitter in VHDL

Last Updated: 01-Jun-2006

 

This page describes a simple Morse code transmitter written in synthesisable VHDL. The operation is as follows, an 8 bits character (only 28 characters are used, A-Z, stop, space) is translated via a Look-Up-Table(I0) into the appropriate DITs (or dots) and DAHs (or dash, equal to 3 dots). The output of this lookup table is then shifted out at the right speed (see Clock Divider) under control of a statemachine (I2). The statemachine starts as soon as the dest signal contains the appropriate address (in the VHDL code example this is "0001110"). The statemachine then loads the LUT word into a shiftregister and asserts the busy signal until all DITs and DAHs are shifted out.

Download source files

Adding Sound

Using a bit of Tcl and Modelsim's examine command it is relative easy to add sound to the simulation. The examine command (see tb.tcl) samples the dout signal and calls sound.exe (see sound.c) to produce a short or long tone.

#-------------------------------------------------------
# Simple Tcl example to produce sounds
# Source in Modelsim before simulation.
#-------------------------------------------------------

proc call_sound {} {
    global count_s
    if {[
examine  /utta_tb/uut/morse/dout]==1} {
        incr count_s 1
        if {$count_s == 3} {
            exec sound.exe 6
            echo "---"
            set count_s 0
        }
    } else {
        if {$count_s == 1} {
            echo "."
            exec sound.exe 2
            set count_s 0
        }
    }
}

#-------------------------------------------------------
# Read from Morse Transmitter
#-------------------------------------------------------

set clken_s /utta_tb/uut/morse/clk_en
set count_s 0
when -label data_avail "$clken_s'event and $clken_s='1'" {
    call_sound  
}
 

//-------------------------------------------------
// Simple C program to call the PC speaker
// Compile to sound.exe using Watcom C/C++ 10.0
//-------------------------------------------------

#include<stdio.h>
#include<stdlib.h>
#include<dos.h>
#include <string.h>
#include <io.h>
#include <i86.h>

static unsigned freq = 440;     // In hertz (cps) 
static unsigned time_unit = 50;
// (default) In milli-seconds

int main(int argc, char **argv)
{
 
        if (argc!=2) {
             printf("\nUsage   : sound delay");
             printf("\ne.g. dit   : sound 1");
             printf("\ne.g. dah   : sound 3");
             return 1;
        }
        
        
sound(freq);
        
delay(atoi(argv[1])*time_unit);
        
nosound();
 
        return 0;
}

 

Other links