Previous Posts:
TI and Würth Elektronik LED RoadTest+ application and un-boxing - Blog 1 - Nov 10
LED Road Test - Software issues - Blog 2 - Nov 26
LED Road Test - LED PCB issues - Blog 3 - Dec 5
LED Road Test - Some words on timing - Blog 4 - Dec 15
Related links:
search for a PCB for Würth power leds
Introduction
In my previous post I explained that I need six parameters for the flash controller. I decided to make a simple trial protocol so that the flash controller can be operated over a USB serial link. In the future the LaunchPad can eventually be extended with a WiFi boosterpack and IoT interface, but since that is nit the initial goal of this project, for the time being I will stick to a simple serial connection.
List of parameters:
- flash duration
- flash delay
- trigger duration
- trigger delay
- interval
- internal/external trigger
The delay and duration as well as the interval values are given in microseconds [us]. Since a large range is needed for these values they are declared as long integer, which is 32 bit on the MSP430. The trigger is just on or off, so we use a bool here.
Code
Below you find the code for the user interface. Be aware that it currently only is the user interface, no further functionality is implemented. Only the values mentioned above can be set from a command line. Also some functions for help an showing the status are implemented.
// Flash Controler using MSP430FR4133 LaunchPad // (c) Gerrit Polder, 2015 String Command; String Parameter; long flash_duration = 0; long flash_delay = 0; long trigger_duration = 0; long trigger_delay = 0; long interval = 0; bool external_trigger = false; void establishContact() { Serial.println(); Serial.println(" _____ _ _ "); Serial.println(" | ___| | __ _ ___| |__ "); Serial.println(" | |_ | |/ _` / __| '_ \\ "); Serial.println(" | _| | | (_| \\__ \\ | | | "); Serial.println(" |_|___|_|\\__,_|___/_| |_| _ _ "); Serial.println(" / ___|___ _ __ | |_ _ __ ___ | | | ___ _ __ "); Serial.println(" | | / _ \\| '_ \\| __| '__/ _ \\| | |/ _ \\ '__|"); Serial.println(" | |__| (_) | | | | |_| | | (_) | | | __/ | "); Serial.println(" \\____\\___/|_| |_|\\__|_| \\___/|_|_|\\___|_| "); Serial.println("\nSerial command shell v1.0"); Serial.println("Copyright (c) 2015 Gerrit Polder"); Serial.println("__________________________________________\n\n"); } void help(){ Serial.println(); Serial.println("Serial command shell v1.0"); Serial.println("Copyright (c) 2015 Gerrit Polder"); Serial.println("help - This help info"); Serial.println("reboot - Resets variables to their initial values"); Serial.println("status - Displays status information"); Serial.println("flashduration val - set flash duration val [us]"); Serial.println("flashdelay val - set flash delay val [us]"); Serial.println("triggerduration val - set trigger duration val [us]"); Serial.println("triggerdelay val - set trigger delay val [us]"); Serial.println("flashdelay val - set flash delay val [us]"); Serial.println("externaltrigger [on/off] - set external trigger"); Serial.println("interval val - set interval val [us]"); } void reboot(){ setup(); } void status(){ Serial.println(); Serial.println("Flash: duration: " + String(flash_duration) + " [us] delay: " + String(flash_delay) + " [us]"); Serial.println("Trigger: duration: " + String(trigger_duration) + " [us] delay: " + String(trigger_delay) + " [us]"); if (external_trigger) { Serial.println("External trigger"); } else { Serial.println("Interval: " + String(interval) + " [us]"); } } void set_external_trigger(String Par) { if (Par.equals("on")) { external_trigger = true; } else if (Par.equals("off")) { external_trigger = false; } } void invalid_input(){ Serial.println("Error in input command. Type ""help"" for available commands."); } void setup() { // start serial port at 9600 bps: Serial.begin(9600); establishContact(); // send the fun initialization data OUT; and wait for a keypress } void loop() { Command = ""; Parameter = ""; Serial.print("\n> "); while (Serial.available() == 0){} //Loop until some serial data is recieved. char command_temp = 0; bool read_parameter = false; while (command_temp != '\r' && command_temp != '\n'){ while (Serial.available() < 1){} command_temp = Serial.read(); Serial.print(command_temp); // echo if (command_temp <= 32){ //This is the end of the base command, and the start of arguments read_parameter = true; } else if (read_parameter){ Parameter = Parameter + command_temp; } else { Command = Command + command_temp; } } if (Command.equals("status")){ status(); } else if (Command.equals("help")){ help(); } else if (Command.equals("reboot")){ reboot(); } else if (Command.equals("flashdelay")){ flash_delay = Parameter.toInt(); } else if (Command.equals("flashduration")){ flash_duration = Parameter.toInt(); } else if (Command.equals("triggerdelay")){ trigger_delay = Parameter.toInt(); } else if (Command.equals("triggerduration")){ trigger_duration = Parameter.toInt(); } else if (Command.equals("externaltrigger")){ set_external_trigger(Parameter); } else if (Command.equals("interval")){ interval = Parameter.toInt(); } else if (Command.equals("")) { //no command, do nothing } else { invalid_input(); } }
Screen recording
Here is how this looks like when you connect to the LaunchPad using a serial console. In this case the Mac OS X screen function is used from a terminal window. Similar software on other platforms, such as hyperterm on windows will also do the job.
My LED PCBs are arrived, I'm planning to describe my experiences with them in the next blog.
stay tuned.