Wednesday, August 29, 2012

MSP430 Morse Code in Energia

I'm cross-posting this from my Ham Radio blog: It may be of interest to anyone viewing this, my professional blog.

 Just a small project I worked on this past weekend 8/24-8/25. I have several of these cheap MSP430 Launchpad dev kits from TI. What a deal they are too, $4.30 each. I intended on configuring it to further my Kenwood TM241a project, but got sidetracked and made a program to send my callsign in Morse Code. I ended up using Energia, which is a port of the Arduino IDE but this one makes MSP430 programs. It seems most of the same commands are supported, but not all.

I really need to get setup to program in C or even try my hand at ASM. I tried ASM on the PIC microcontrollers a couple of years ago but gave up on it fairly quick. Maybe I'd do better now? I'm not sure the Wiring language would produce code fast enough to bit bang 1200 baud serial with a clock.

Code for my project is below. It would be fairly easy to modify this to make a beacon, or foxhunting cpu, or even an ID for a repeater or standalone rig. If you do something with it, I'd appreciate a link back to my radio blog, and maybe drop me a line to let me know. I'd probably write an entry about it and link to your site.

It's not technically hard to add other characters and I think it's fairly self-explanatory. I'm not 100% happy with using the IF statements to cycle through the letters. I'd be happier with an array and a For loop with an index number but this works. I tried to set up a constant type like an UIntTable to store the characters, but I only received error messages when I tried to use that. It may not be fully supported in Energia yet, or probably I didn't fully understand it.

I know I'm not the first person to do this by a long shot, but it was a fun challenge and it did help me familiarize myself somewhat in Energia, maybe next time I'll rewrite this in C? I see there are videos of others who have written Morse Code projects for the MSP430 on Youtube with a little more pizzazz than mine, such as audio out and a serial terminal for input.
James Hall - N9XLC
Small program to push out my callsign via the red LED on a MSP430 board.
Developed 8/24/2012-8/25/2012

Started off modifying, then totally replacing the code in the 'Blink' example project.
This could probably be wrapped up in a function to send out arbitrary sentences.
Only enough morse code is implemented to get my callsign out, but it would be trivial to add the rest.
Could be used to blink out current temp or maybe short status info in morse code in other projects.
 #define output 2 // pin 2 has the red led on a msp430 board, pin 14 is the green led.
unsigned int mask = 1;
int dot = 1;
int dash = 3; //dash is equal to 3 dots
int lspace = 1; //spacing in same letter is 1 dot
int llspace = 3; //spacing between two letters in same word is 3 dots
int wspace = 7; //spacing between two words is 7 dots.

int didot = 2;
int didash = 3;
int spacems = 100; //100ms is a little slower than 20wpm (60ms) so maybe 13-15wpm?
// 10 dot, 11 dash, 00 end
// unsigned int is 16 bits
unsigned int cwN = 11; //0000 0000 0000 1011 <-read right-to-left
unsigned int cw9 = 767; //0000 0010 1111 1111
unsigned int cwX = 235; //0000 0000 1110 1011
unsigned int cwL = 174; //0000 0000 1010 1110
unsigned int cwC = 187; //0000 0000 1011 1011
byte testbyte;
void setup() {                
  // initialize the digital pin as an output.
  // Pin 14 has an LED connected on most Arduino boards:
  pinMode(output, OUTPUT);     
  pinMode(14, OUTPUT);
 // pinMode(5, INPUT);

void loop() {
  digitalWrite(14, LOW);
  digitalWrite(output, LOW);
  unsigned int cwout;
  unsigned int mask = 3;
  int callsign = 1;
while(callsign) {
 if (callsign == 1) {cwout = cwN;}
 if (callsign == 2) {cwout = cw9;}
 if (callsign == 3) {cwout = cwX;}
 if (callsign == 4) {cwout = cwL;}
 if (callsign == 5) {cwout = cwC; callsign = 0;}

    while (cwout) {
     testbyte = cwout & mask;
       if (testbyte == 2 ) {
          digitalWrite(output, HIGH);
          delay(dot * spacems);
          digitalWrite(output, LOW);
           if (testbyte == 3 ) {
            digitalWrite(output, HIGH);
            delay(dash * spacems);
            digitalWrite(output, LOW);
       delay(spacems * dot); //inner letter spacing 
     cwout >>= 2; 
 delay (spacems * dash); //outer letter spacing


delay (spacems * wspace); //word spacing

No comments:

Post a Comment