Embedded Computing
  • About
  • Blog
  • Hardware
    • Which Platform?
    • Controller Platforms >
      • Adafruit Platform
      • Arduino Plaform
      • BBC micro:bit
      • Espressif Platform
      • LaunchPad Plaform
      • Microsoft Azure IoT DevKit
      • Seeeduino Platform
      • Teensy Plaform
    • Computer Platforms >
      • BeagleBone Platform
      • Mediatek Platform
      • UDOO Platform
    • Legacy Platforms >
      • chipKIT Plaform >
        • chipKIT Uno32 and uC32
        • chipKIT WF32 and WiFire
        • Compatibility
        • chipKIT PGM Programmer-Debugger
        • 4D Systems PICadillo-35T
        • Shields for chipKIT Uno32
        • 4D Systems Platform >
          • 4D Systems PICadillo-35T
          • 4D Systems gen4-IoD-28T
      • Cosa, an Alternative Framework for AVR Boards
      • DFRobot Platform >
        • DFRobot BLuno
        • DFRobot Wido
      • Digistump Platform >
        • Digispark
        • Oak
      • Intel Platform >
        • Intel Curie with Neural Network
        • Intel Edison
      • LightBlue Bean
      • Little Robot Friends
      • Maple Plaform >
        • LeafLabs Maple
      • Microduino Plaform >
        • Microduino
      • Particle Platform >
        • Particle Core
        • Particle Photon
        • Particle Tools
      • Protostack Platform >
        • Protostack Boards
      • RedBear Platform >
        • RedBearLab CC3200
        • RedBearLab WiFi Mini
        • RedBear Duo
      • Wiring Plaform >
        • Wiring S
        • Wiring Play Shield
    • Boards and Plugs
    • I²C Logic Level Converter
    • Peripherals >
      • BoosterPacks for LaunchPads
      • Shields
      • Grove System
      • Ten Years with the Grove System
      • Sensors
      • Actuators
    • Displays >
      • Pervasive Displays e-Paper Screens
      • FRAM-based E-Paper Screen Controller
      • The 2.8" HY28A LCD Screen
      • High-Definition 480x320 3.5" Screen With Touch and Fonts
      • Kentec 3.5" LCD SPI with Touch BoosterPack
      • 4D Systems Intelligent Screens
      • East Rising 5" LCD with RA8875, Touch, Fonts, Flash and SD-card
      • East Rising 5" LCD with SSD1963, Touch, Flash and SD-card
  • Software
    • The IDE Question >
      • The Battle of IDEs
      • More IDE Options
      • Looking for a Better IDE
      • Assessing the Next Generation of IDEs
    • Exploring RTOS with Galaxia >
      • Event Library
      • Semaphore Library
      • Mailbox Library
      • Timer Library
      • Clock Library
      • SWI Library
      • Task Library
    • Ultra-Low Power with EnergyTrace >
      • Ultra-Low Power with MSP430
      • Ultra-Low Power with Energia MT and Galaxia
    • Using Integers Instead of Reals
  • IoT
    • IoT Platforms: Which Hardware?
    • IoT Services: Which Solution? >
      • Recommended IoT Solutions
      • Platform-Specific IoT Solutions
      • Other IoT Solutions
      • Not tested IoT Solutions
      • Notification Solutions
    • Get Date and Time from Internet with NTP
    • Fast and Easy WiFi Connection with QR-Code
  • Tools
    • How to Start?
    • Reference >
      • Asking for Help
      • LaunchPad and BoosterPack Boards Pins Maps
      • Ruler
      • Standards for Connectors
    • Training >
      • Texas Instruments Workshops
      • Embedded Systems: Shape The World — MOOC edX UTAustinX UT.6.02x
      • Embedded Systems - Shape The World: Microcontroller Input/Output — MOOC edX UTAustinX UT.6.10x
      • Embedded Systems - Shape The World: Multi-Threaded Interfacing — MOOC edX UTAustinX UT.6.20x
      • Real-Time Bluetooth Networks: Shape the World — MOOC edX UTAustinX UT.RTBN.12.01x
      • Systems Thinking with Texas Instruments Robotics System Learning Kit
    • Books >
      • Getting Started with the MSP430 LaunchPad
      • Getting Started with Arduino
      • Arduino Cookbook
    • IDEs >
      • Texas Instruments Code Composer Studio 6
      • Texas Instruments Code Composer Studio Cloud
      • Energia
      • Tools for Documentation
    • Equipment >
      • Saleae Logic Analyser
      • Rigol DS1102E Oscilloscope
      • XDS110 Debug Probe with EnergyTrace​
      • Segger J-Link Programmer-Debugger
  • Projects
    • Libraries >
      • Master I²C Software Library
      • Date and Time Library
      • highView Library Suite
      • LCD_screen Library Suite
      • Others Libraries
    • smartDevices >
      • I²C smartColours Smart Sensor
      • I²C smartRFID Smart Sensor
      • I²C smartLED Display
      • I²C smartControls Smart Device
      • I²C smartWiFi Smart Device
      • I²C smartBLE Smart Device
      • I²C smartNode Smart Device
    • IoT Projects >
      • Remote e-Paper Messages Panel
      • Industrial IoT Project
      • Remote Contactless Temperature Monitor
      • Using Node-RED for IIoT
      • Low Power Home Network Weather Monitoring
      • Updated Low Power Home Network Weather Monitoring
      • Weather and Security Station with Blynk
      • SensorTag to Blynk Using Node-RED
      • Pervasive Reporting
    • AI Projects >
      • Colour Recognition with Neural Network
    • Other Projects >
      • Portable Particulate​ Matter Monitor
      • FRAM-based E-Paper Screen Controller
      • General Purpose 3.5" Screen
      • Colour Recognition with Neural Network
      • A Low Power Weather Station
      • Digital Volt-Amp-Watt Meter
      • Mobile Measurement with LCD Display
      • Screen with SRAM for GUI
      • Volt-Amp-Watt-Meter for Grove
      • Multi-Touch Project with CapTIvate

Clock Library

This example uses clocks and illustrates a radically different approach from the example provided on the MSP432 review. Both examples do exactly the same: they blink each colour of the RGB LED at different speeds. 

The preliminary part of the sketch is very standard, with includes, a structure for the LED, variables for each colour of the RGB LED, and functions for each colour of the RGB LED.

///

/// @author Rei Vilo

/// @author http://embeddedcomputing.weebly.com

///

/// @copyright (c) Rei Vilo, 2015

/// @copyright CC = BY SA NC

///


// Core library for code-sense - IDE-based

#   include "Energia.h"


// Include application, user and local libraries

#include "rtosGlobals.h"

#include "Clock.h"


// Prototypes


// Define variables and constants

struct LED_t {

    uint8_t status;

    uint8_t pin;

};


LED_t ledR = { 0, RED_LED };

LED_t ledG = { 0, GREEN_LED };

LED_t ledB = { 0, BLUE_LED };


// Functions

void clockFunctionR()

{

    ledR.status = 1 - ledR.status;

    digitalWrite(ledR.pin, ledR.status);

}


void clockFunctionG()

{

    ledG.status = 1 - ledG.status;

    digitalWrite(ledG.pin, ledG.status);

}


void clockFunctionB()

{

    ledB.status = 1 - ledB.status;

    digitalWrite(ledB.pin, ledB.status);

}


Instead of having 3 tasks, the main part of the sketch contains three clocks. Each clock calls a dedicated function to manage one colour of the RGB LED.

The function called by the Clock needs to be void clockFunction().

Two periods are defined:
  • the first one is the initial start delay,
  • and the second is the repetitive period.

​Both are stated in ms. If the initial start delay is equal to 0, the clock starts immediately. If the repetitive period is equal to 0, the clock runs only once (one-shot timer).

In this example, the clocks start running after 1 second, and call the respective functions every 100, 333 or 500 ms.

Note the function loop() is empty. Everything is managed by SYS/BIOS, the OS of TI-RTOS used by Energia MT.

// Define variables and constants

Clock myClockR;

Clock myClockG;

Clock myClockB;


// Setup

void setup()

{

    myClockR.begin(clockFunctionR, 1000, 100); // 1000 ms = 1 s

    myClockG.begin(clockFunctionG, 1000, 333); // 1000 ms = 1 s

    myClockB.begin(clockFunctionB, 1000, 500); // 1000 ms = 1 s

    

    myClockR.start();

    myClockG.start();

    myClockB.start();

}



// Loop

void loop()

{

    

}

Now, compare this implementation with the sketch commented on the MSP432 review. Both do the same. Which one do you prefer?
Powered by Create your own unique website with customizable templates.