Morse Code?

Brandon_K

Member
Join Date
Mar 2016
Location
Pittsburgh, PA
Posts
150
Possibly a bit of an odd one for a PLC, but why not.

I need to display morse code messages on a indicator lamp, but I also need to be able to change them easily, so that rules out hard coded timers.

My initial thought was to have a drum instruction for each letter. I tried this in a limited test and it works, but I'm not sure what the best way to trigger a sequence of drum instructions would be. Ideally I'd be able to put the message in a string and then convert that in a way to run the drums. But I'm not sure how to best go about that.

Dots and spaces are ~92ms, dashes are ~276ms. I'm using Productivity, so I have a fair number of instructions available.

Thoughts?
 
I like having distinctive beeps for my machines and use a fb to generate the signal.

I pass :
a integer where the bits represent the tempo
the number of bits used
and the duration of each bit

so S = 10101
O = 11011011

You can build a structure with the lookup for each letter
 
Wouldn't you just require a hard coded timer of 92ms?

276/92 = 3
So a dash will be 3 spaces. If you know this, you can create an array where the bit signals the logical state during that space.
Taking the letter A for example a dot, space and dash would be
101110000

The trailing zeros would have to be enough for the longest chain you would need which seems to be the 0 clocking in at 21 bits if you decide to put a trailing space there.

I'm not sure how well this translates into the PLC side, but on a microcontroller you'd create an array of 127 positions and follow the ASCII standard. This would then allow you to use text messages in strings to be transmitted by your Morse Code interface.

Looking back it seems Geoff had the same idea apart from the timing.
 
Last edited:
https://en.wikipedia.org/wiki/Morse_code
Looking at Morse code the longest number is 0. This is five long dashes. The shortest is E. This is one short dash.
In the PLC, I would try to represent each character by one word. (16 Bits)
A short dash is 10 = E
A long dash is 11011011011011 = number 0
The space between the numbers and character should be set for 0000 = space
Each character is now one word in length.
You can use the FIFO instruction or indirect addressing to point to the location for the next character to show.
The character to show will use a shift instruction to shift the bits for the character into the output every 92 ms. Compare for the end of the word (16 bits) or four bits (0000) to determine when to go to the next character.

This is a combination of what Geoff and cardosocea have explained.

Getting the ASCII characters to the FIFO stack can be done by using compares and move statements.

Hope this helps to get you going.
Regards,
 
A short dash is 10 = E
A long dash is 11011011011011 = number 0
The space between the numbers and character should be set for 0000 = space
Each character is now one word in length.

There isn't any benefit in fitting the pattern in 16 bits apart from saving memory, which shouldn't be an issue nowadays. It will, however, make it a bit more complicated as you need to keep track of two timers.

If however, you have a routine that runs at each 92ms and does the following:

Are there bits to send?
If no then Exit.
If yes then shift next bit into morse output.
Decrement bit counter.
Exit.

The "smart" bit of the logic would be to move the right number of bits into a memory section all in a row. So to send SOS you would have to put in the following bit pattern.
101010111011101110101010

Now we also don't know if the OP is looking for something that is dynamic like someone typing a message to be sent across or if the messages are static in which case this will be the simplest way of doing it.

If the platform accepts indirect addressing down to bit level it would be even better.
 
There is a body of knowledge on this topic in the ham radio community. Specifically memory and keyboard keyers.

A look-up table stores the code for each letter, character, and number. You can save some bits by encoding each element as:

00=end of character
01=dit
10=dah
11=continued in next byte (needed for numerals and punctuation and "packed" messages. ) This last is not needed for a lookup table, but is useful when storing messages as pre-encoded morse.

By dedicating two bits per element, the spacing between elements is inferred, and need not take up a bit. Also dits take the same storage as dahs, rather than dahs needing twice as much, so this conserves 25% memory on average.

This also allows all letters (four elements maximum) to be encoded into a single byte. If the letter has 4 elements, the end of character is inferred. Shorter characters use the 00 code to end early, so proper letter spacing is maintained. The zero-zero code also allows packing messages to achieve better than 1 letter per byte, since morse is intentionally designed so that the most common letters are shorter than than the rare letters. The 11 code allows letters to bridge between bytes when packing, as well as accommodating numerals and punctuation which require 10 or 12 bits to encode.

You can also observe that letters are shorter than numerals and punctuation, so you can split your look up table into two sections with the letter section only needing one byte per character, and the numeral/punctuation having two bytes per character, so your look-up table needs less memory.

Finally, silence is used for spacing between letters and words. In the scheme above, silence between elements and letters can be inferred, but there is no allowance for encoding between words. We can address this by making the first two bits of each byte have special meaning: 11=inter-word space, 00=inter-letter space. Note that this use of 00 is consistent with the end-of-character meaning, as that also infers a between-letters silence.

Edit: I posted this info to tell how hams have worked out a minimum storage space solution, which is useful when implementing a morse device in a low cost microcontroller such as an HC05 or PIC. While the concepts may be handy for PLC implementations, other ways may prove more efficient for programming time, since PLCs typically have significant memory available. At any rate, I find it interesting seeing how something can be optimized.
 
Last edited:
I'm using Productivity said:
Fitting the characters into the 16 bits is not to save space. This is to simply use the data instructions available in the Productivity Series PLC that the OP is using.

There are multiple Data Types available for configuring parameters and tags within a project.

The Data Types are:
Boolean
Integer, 8 Bit Unsigned
Integer, 16 Bit
Integer, 16 Bit Unsigned
Integer, 16 Bit BCD
Integer, 32 Bit
Integer, 32 Bit BCD
Float, 32 Bit
String
*Constant

* With the exception of a constant data type, each of the above data types are also available as Array data types, one dimensional (1D) Arrays & two dimensional (2D) Arrays.

The arrays is how the information can be obtained.

Regards,
Garry
 
For when you are under a machine with a spanner and your hand up inside holding an M5 nut, and would like to know wether to get your butt up now and go attend the most important machine in the factory, or wether you can tighten your nut first, pack your tools and go attend the cute little machine in the corner that runs 4hrs a day.
Or if you're just closing your eyes to meditate.

Extra challenge: program that Morse code code with your eyes closed.
 

Similar Topics

Hi all, may I ask anybody for help to write a program which translates text to morse code. I understand I have to divide text string to individual...
Replies
34
Views
7,158
Hi all, thank you for reading this post. it's been a while since I posted a thread. I hope you are well. I have this new project requirement for...
Replies
51
Views
18,290
Hi All, Can anyone advise me on how to determine the AN of a genie instance I writing to. I have created a genie to display a valve and some text...
Replies
0
Views
81
Hi I have been knocking my head against the wall trying to figure out why these two plcs won't talk with Produced and Consumed Tags data. The...
Replies
14
Views
417
Hello Everyone. Looking to see if any of you have encountered an issue with these drives. We have a major installation with around 30 of these...
Replies
0
Views
59
Back
Top Bottom