element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
RoadTests & Reviews
  • Products
  • More
RoadTests & Reviews
Blog LED Road Test - Timing software - Blog 9 - Jan 18
  • Blog
  • RoadTest Forum
  • Documents
  • RoadTests
  • Reviews
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join RoadTests & Reviews to participate - click to join for free!
  • Share
  • More
  • Cancel
  • Author Author: gpolder
  • Date Created: 18 Jan 2016 8:20 PM Date Created
  • Views 381 views
  • Likes 2 likes
  • Comments 0 comments
Related
Recommended
  • interrupt
  • trigger
  • ledroadtestplus
  • flash
  • timing
  • msp430
  • software

LED Road Test - Timing software - Blog 9 - Jan 18

gpolder
gpolder
18 Jan 2016

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

LED Road Test - Launchpad user interface - Blog 5 - Dec 19

LED Road Test - Solder the LEDs - Blog 6 - Dec 28

LED Road Test - Deadline approaching - Blog 7 - Jan 15

LED Road Test - Making a ring light - Blog 8 - Jan 16

 

Related links:

search for a PCB for Würth power leds

LED_RoadTest_Unboxing

LED_RoadTest_Soldering

LED testing

flashcontroller screen-recording

 

 

Timing software

In my forth blog I explained the timing diagram and in the fifth blog I described the MSP430 user interface, but the timing wasn't implemented by then.

So today I will explain how I programmed the timing. Luckily due to the existence of the delayMicroseconds() function in Energia, this is not a big issue.

Remember all the timing values I have:

List of parameters:

  1. flash duration
  2. flash delay
  3. trigger duration
  4. trigger delay
  5. interval
  6. internal/external trigger

 

In the software we first declare the led output pin and trigger input pin:

int ledPin = 12;
int triggerInPin = 11;

 

Set the appropriate INPUT and OUTPUT in the setup function:

void setup() {
        // start serial port at 9600 bps:
        Serial.begin(9600);
        establishContact();  // send the initialization data OUT
        pinMode(ledPin, OUTPUT);
        pinMode(triggerInPin, INPUT);
}

 

We put the flash including delay and duration in a function:

void led_flash() {
    delayMicroseconds(flash_delay);
    digitalWrite(ledPin, HIGH);
    delayMicroseconds(flash_duration);
    digitalWrite(ledPin, LOW);
}

 

This function will be called from the main loop:

    while (Serial.available() == 0){ //Loop until some serial data is recieved.
        if (!external_trigger) {
                delayMicroseconds(interval);
                led_flash();
        }
    }

 

In the case of an external trigger I use an interrupt, which fires the led_flash function on a rising edge of the optocoupler which is connected to the triggerInPin:

 

void set_external_trigger(String Par) {
    if (Par.equals("on")) {
        external_trigger = true;
        attachInterrupt(triggerInPin, led_flash, RISING); // Interrupt is fired whenever input give rising edge
    } else if (Par.equals("off")) {
        external_trigger = false;
        detachInterrupt(triggerInPin);
    }
}

 

 

The complete program now is:

// Flash Controler using MSP430FR4133 LaunchPad
// (c) Gerrit Polder, 2015, 2016


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;
int ledPin = 12;
int triggerInPin = 11;


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;
        attachInterrupt(triggerInPin, led_flash, RISING); // Interrupt is fired whenever input give rising edge
    } else if (Par.equals("off")) {
        external_trigger = false;
        detachInterrupt(triggerInPin);
    }
}


void led_flash() {
    delayMicroseconds(flash_delay);
    digitalWrite(ledPin, HIGH);
    delayMicroseconds(flash_duration);
    digitalWrite(ledPin, LOW);
}

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 initialization data OUT
        pinMode(ledPin, OUTPUT);
        pinMode(triggerInPin, INPUT);
}


void loop() {
    Command = "";
    Parameter = "";


    Serial.print("\n> ");
    while (Serial.available() == 0){ //Loop until some serial data is recieved.
        if (!external_trigger) {
                delayMicroseconds(interval);
                led_flash();
        }
    }
    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();
    }
   
}

 

 

Thats it for now, be aware that the camera trigger out yet isn't implemented, but that will be very easy to add given the example code above. Later today I will publish the wrap-up of the whole project for the tenth blog post.

stay tuned.


  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube