LVTTL HW Trigger with control via virtual Serial over USB. Works well with NUCLEO boards.

Dependencies:   mbed

Committer:
Neolker
Date:
Fri Jan 22 10:33:36 2016 +0000
Revision:
0:46a9ecc2d2b8
Child:
1:26ff6101d6d5
final release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Neolker 0:46a9ecc2d2b8 1 /*
Neolker 0:46a9ecc2d2b8 2 * ---------------
Neolker 0:46a9ecc2d2b8 3 * TriggerNiNo 1.0
Neolker 0:46a9ecc2d2b8 4 * ---------------
Neolker 0:46a9ecc2d2b8 5 *
Neolker 0:46a9ecc2d2b8 6 * LVTTL HW Trigger with control via virtual Serial over USB.
Neolker 0:46a9ecc2d2b8 7 * Works well with NUCLEO-F031K6 and NUCLEO-F411RE.
Neolker 0:46a9ecc2d2b8 8 *
Neolker 0:46a9ecc2d2b8 9 * Copyright (C) <2015> Martin Wolker <neolker@gmail.com>
Neolker 0:46a9ecc2d2b8 10 *
Neolker 0:46a9ecc2d2b8 11 * TriggerNiNo is free software: you can redistribute it and/or modify
Neolker 0:46a9ecc2d2b8 12 * it under the terms of the GNU General Public License as published by
Neolker 0:46a9ecc2d2b8 13 * the Free Software Foundation, either version 3 of the License, or
Neolker 0:46a9ecc2d2b8 14 * (at your option) any later version.
Neolker 0:46a9ecc2d2b8 15 *
Neolker 0:46a9ecc2d2b8 16 * You should have received a copy of the GNU General Public License
Neolker 0:46a9ecc2d2b8 17 * If not, see <http://www.gnu.org/licenses/>.
Neolker 0:46a9ecc2d2b8 18 */
Neolker 0:46a9ecc2d2b8 19
Neolker 0:46a9ecc2d2b8 20 #include "mbed.h" //mbed official library.
Neolker 0:46a9ecc2d2b8 21 #define TRIGGER_PULSE_LENGTH_MS 500 //Length of the trigger pulse in ms.
Neolker 0:46a9ecc2d2b8 22
Neolker 0:46a9ecc2d2b8 23 Serial pc(USBTX, USBRX); //Virtual Serial over USB with 9600 baud.
Neolker 0:46a9ecc2d2b8 24 DigitalOut trigger_output_positive(D2); //Declaration of positive trigger output.
Neolker 0:46a9ecc2d2b8 25 DigitalOut trigger_output_negative(D3); //Declaration of negative trigger output.
Neolker 0:46a9ecc2d2b8 26 DigitalOut trigger_indication(LED1); //Declaration of indication LED.
Neolker 0:46a9ecc2d2b8 27
Neolker 0:46a9ecc2d2b8 28 void trigger(void)
Neolker 0:46a9ecc2d2b8 29 {
Neolker 0:46a9ecc2d2b8 30 trigger_output_positive =! trigger_output_positive; //Change the state of the positive output.
Neolker 0:46a9ecc2d2b8 31 trigger_output_negative =! trigger_output_negative; //Change the state of the negative output.
Neolker 0:46a9ecc2d2b8 32 trigger_indication =! trigger_indication; //Change the state of the indication LED.
Neolker 0:46a9ecc2d2b8 33 }
Neolker 0:46a9ecc2d2b8 34
Neolker 0:46a9ecc2d2b8 35 void interrupt(void)
Neolker 0:46a9ecc2d2b8 36 {
Neolker 0:46a9ecc2d2b8 37 pc.getc(); //Get the character from the buffer and clear.
Neolker 0:46a9ecc2d2b8 38 trigger(); //Trigger ON.
Neolker 0:46a9ecc2d2b8 39 wait_ms(TRIGGER_PULSE_LENGTH_MS); //Waiting when the trigger pulse is ON.
Neolker 0:46a9ecc2d2b8 40 trigger(); //Trigger OFF.
Neolker 0:46a9ecc2d2b8 41 }
Neolker 0:46a9ecc2d2b8 42
Neolker 0:46a9ecc2d2b8 43 int main(void)
Neolker 0:46a9ecc2d2b8 44 {
Neolker 0:46a9ecc2d2b8 45 pc.attach(&interrupt); //Call the interrupt, when any data are received from PC.
Neolker 0:46a9ecc2d2b8 46 trigger_output_positive = 0; //Initial state of positive output in idle state.
Neolker 0:46a9ecc2d2b8 47 trigger_output_negative = 1; //Initial state of negative output in idle state.
Neolker 0:46a9ecc2d2b8 48 trigger_indication = 0; //Initial state of LED in idle state is OFF.
Neolker 0:46a9ecc2d2b8 49 while(1) {} //Infinity loop.
Neolker 0:46a9ecc2d2b8 50 }