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

Dependencies:   mbed

Committer:
Neolker
Date:
Tue Sep 27 12:17:50 2016 +0000
Revision:
1:26ff6101d6d5
Parent:
0:46a9ecc2d2b8
Updated licence and unnecessary comments has been deleted

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Neolker 0:46a9ecc2d2b8 1 /*
Neolker 1:26ff6101d6d5 2 * ----------------------------
Neolker 1:26ff6101d6d5 3 * TriggerNiNo 1.0 (2016-09-26)
Neolker 1:26ff6101d6d5 4 * ----------------------------
Neolker 0:46a9ecc2d2b8 5 * LVTTL HW Trigger with control via virtual Serial over USB.
Neolker 0:46a9ecc2d2b8 6 * Works well with NUCLEO-F031K6 and NUCLEO-F411RE.
Neolker 0:46a9ecc2d2b8 7 *
Neolker 1:26ff6101d6d5 8 * Copyright (c) 2016, Martin Wolker (neolker@gmail.com)
Neolker 1:26ff6101d6d5 9 * All rights reserved.
Neolker 0:46a9ecc2d2b8 10 *
Neolker 1:26ff6101d6d5 11 * Redistribution and use in source and binary forms, with or without
Neolker 1:26ff6101d6d5 12 * modification, are permitted provided that the following conditions are met:
Neolker 1:26ff6101d6d5 13 * - Redistributions of source code must retain the above copyright
Neolker 1:26ff6101d6d5 14 * notice, this list of conditions and the following disclaimer.
Neolker 1:26ff6101d6d5 15 * - Redistributions in binary form must reproduce the above copyright
Neolker 1:26ff6101d6d5 16 * notice, this list of conditions and the following disclaimer in the
Neolker 1:26ff6101d6d5 17 * documentation and/or other materials provided with the distribution.
Neolker 1:26ff6101d6d5 18 * - Neither the name of Martin Wolker nor the
Neolker 1:26ff6101d6d5 19 * names of its contributors may be used to endorse or promote products
Neolker 1:26ff6101d6d5 20 * derived from this software without specific prior written permission.
Neolker 0:46a9ecc2d2b8 21 *
Neolker 1:26ff6101d6d5 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Neolker 1:26ff6101d6d5 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Neolker 1:26ff6101d6d5 24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Neolker 1:26ff6101d6d5 25 * DISCLAIMED. IN NO EVENT SHALL MARTIN WOLKER BE LIABLE FOR ANY
Neolker 1:26ff6101d6d5 26 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Neolker 1:26ff6101d6d5 27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Neolker 1:26ff6101d6d5 28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Neolker 1:26ff6101d6d5 29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Neolker 1:26ff6101d6d5 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Neolker 1:26ff6101d6d5 31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Neolker 0:46a9ecc2d2b8 32 */
Neolker 0:46a9ecc2d2b8 33
Neolker 1:26ff6101d6d5 34 #include "mbed.h"
Neolker 1:26ff6101d6d5 35 #define TRIGGER_PULSE_LENGTH_MS 500
Neolker 0:46a9ecc2d2b8 36
Neolker 1:26ff6101d6d5 37 Serial pc(USBTX, USBRX);
Neolker 1:26ff6101d6d5 38 DigitalOut trigger_output_positive(D2);
Neolker 1:26ff6101d6d5 39 DigitalOut trigger_output_negative(D3);
Neolker 1:26ff6101d6d5 40 DigitalOut trigger_indication(LED1);
Neolker 0:46a9ecc2d2b8 41
Neolker 0:46a9ecc2d2b8 42 void trigger(void)
Neolker 0:46a9ecc2d2b8 43 {
Neolker 1:26ff6101d6d5 44 trigger_output_positive =! trigger_output_positive;
Neolker 1:26ff6101d6d5 45 trigger_output_negative =! trigger_output_negative;
Neolker 1:26ff6101d6d5 46 trigger_indication =! trigger_indication;
Neolker 0:46a9ecc2d2b8 47 }
Neolker 0:46a9ecc2d2b8 48
Neolker 0:46a9ecc2d2b8 49 void interrupt(void)
Neolker 0:46a9ecc2d2b8 50 {
Neolker 1:26ff6101d6d5 51 pc.getc();
Neolker 1:26ff6101d6d5 52 trigger();
Neolker 1:26ff6101d6d5 53 wait_ms(TRIGGER_PULSE_LENGTH_MS);
Neolker 1:26ff6101d6d5 54 trigger();
Neolker 0:46a9ecc2d2b8 55 }
Neolker 0:46a9ecc2d2b8 56
Neolker 0:46a9ecc2d2b8 57 int main(void)
Neolker 0:46a9ecc2d2b8 58 {
Neolker 1:26ff6101d6d5 59 pc.attach(&interrupt);
Neolker 1:26ff6101d6d5 60 trigger_output_positive = 0;
Neolker 1:26ff6101d6d5 61 trigger_output_negative = 1;
Neolker 1:26ff6101d6d5 62 trigger_indication = 0;
Neolker 1:26ff6101d6d5 63 while(1) {}
Neolker 0:46a9ecc2d2b8 64 }