Transistor Gijutsu, October 2014, Special Features Chapter 9, Software of the Function Generator トランジスタ技術2014年10月号 特集第9章のソフトウェア わがまま波形発生器のソフトウェア

Dependencies:   USBDevice mbed

Information

tg_201410s8_AD7714 トランジスタ技術 2014年 10月号 第9章のソフトウェア

Program for Section 9 in October. 2014 issue of the Transistor Gijutsu
(Japanese electronics magazine)

概要

このプログラムは、ソフトウエアDDSにより、任意の波形を出力(2ch)します。 特徴は次のとおりです。

  • PWM出力をDAコンバータとして利用します。
  • 周波数や波形、バースト条件などを個別に設定できる独立した出力を2チャネル持っています。
  • 周波数分解能0.023mHz
  • 周波数範囲0.023mHz~10kHz
  • 各チャネルにそれぞれ、波形の先頭で出力されるトリガ出力があります。
  • 出力波形を関数で定義できます。
  • 休止波数、出力波数、を設定することでバースト波形が出力できます。

ファイル

このソフトウエアは、次のファイルから構成されています。

  • DDS.cpp - DDSによる波形発生
  • main.cpp - main()関数

詳細については、10月号の記事および上記ファイル中のコメントを参照してください。

Committer:
Dance
Date:
Fri Aug 29 08:33:17 2014 +0000
Revision:
0:f1ecca559ec3
Transistor Gijutsu, October 2014, Special Features Chapter 9; ????????2014?10??????9????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Dance 0:f1ecca559ec3 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
Dance 0:f1ecca559ec3 2 *
Dance 0:f1ecca559ec3 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Dance 0:f1ecca559ec3 4 * and associated documentation files (the "Software"), to deal in the Software without
Dance 0:f1ecca559ec3 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
Dance 0:f1ecca559ec3 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Dance 0:f1ecca559ec3 7 * Software is furnished to do so, subject to the following conditions:
Dance 0:f1ecca559ec3 8 *
Dance 0:f1ecca559ec3 9 * The above copyright notice and this permission notice shall be included in all copies or
Dance 0:f1ecca559ec3 10 * substantial portions of the Software.
Dance 0:f1ecca559ec3 11 *
Dance 0:f1ecca559ec3 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Dance 0:f1ecca559ec3 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Dance 0:f1ecca559ec3 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Dance 0:f1ecca559ec3 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Dance 0:f1ecca559ec3 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Dance 0:f1ecca559ec3 17 */
Dance 0:f1ecca559ec3 18
Dance 0:f1ecca559ec3 19 #ifndef USBKEYBOARD_H
Dance 0:f1ecca559ec3 20 #define USBKEYBOARD_H
Dance 0:f1ecca559ec3 21
Dance 0:f1ecca559ec3 22 #include "USBHID.h"
Dance 0:f1ecca559ec3 23 #include "Stream.h"
Dance 0:f1ecca559ec3 24
Dance 0:f1ecca559ec3 25 /* Modifiers */
Dance 0:f1ecca559ec3 26 enum MODIFIER_KEY {
Dance 0:f1ecca559ec3 27 KEY_CTRL = 1,
Dance 0:f1ecca559ec3 28 KEY_SHIFT = 2,
Dance 0:f1ecca559ec3 29 KEY_ALT = 4,
Dance 0:f1ecca559ec3 30 };
Dance 0:f1ecca559ec3 31
Dance 0:f1ecca559ec3 32
Dance 0:f1ecca559ec3 33 enum MEDIA_KEY {
Dance 0:f1ecca559ec3 34 KEY_NEXT_TRACK, /*!< next Track Button */
Dance 0:f1ecca559ec3 35 KEY_PREVIOUS_TRACK, /*!< Previous track Button */
Dance 0:f1ecca559ec3 36 KEY_STOP, /*!< Stop Button */
Dance 0:f1ecca559ec3 37 KEY_PLAY_PAUSE, /*!< Play/Pause Button */
Dance 0:f1ecca559ec3 38 KEY_MUTE, /*!< Mute Button */
Dance 0:f1ecca559ec3 39 KEY_VOLUME_UP, /*!< Volume Up Button */
Dance 0:f1ecca559ec3 40 KEY_VOLUME_DOWN, /*!< Volume Down Button */
Dance 0:f1ecca559ec3 41 };
Dance 0:f1ecca559ec3 42
Dance 0:f1ecca559ec3 43 enum FUNCTION_KEY {
Dance 0:f1ecca559ec3 44 KEY_F1 = 128, /* F1 key */
Dance 0:f1ecca559ec3 45 KEY_F2, /* F2 key */
Dance 0:f1ecca559ec3 46 KEY_F3, /* F3 key */
Dance 0:f1ecca559ec3 47 KEY_F4, /* F4 key */
Dance 0:f1ecca559ec3 48 KEY_F5, /* F5 key */
Dance 0:f1ecca559ec3 49 KEY_F6, /* F6 key */
Dance 0:f1ecca559ec3 50 KEY_F7, /* F7 key */
Dance 0:f1ecca559ec3 51 KEY_F8, /* F8 key */
Dance 0:f1ecca559ec3 52 KEY_F9, /* F9 key */
Dance 0:f1ecca559ec3 53 KEY_F10, /* F10 key */
Dance 0:f1ecca559ec3 54 KEY_F11, /* F11 key */
Dance 0:f1ecca559ec3 55 KEY_F12, /* F12 key */
Dance 0:f1ecca559ec3 56
Dance 0:f1ecca559ec3 57 KEY_PRINT_SCREEN, /* Print Screen key */
Dance 0:f1ecca559ec3 58 KEY_SCROLL_LOCK, /* Scroll lock */
Dance 0:f1ecca559ec3 59 KEY_CAPS_LOCK, /* caps lock */
Dance 0:f1ecca559ec3 60 KEY_NUM_LOCK, /* num lock */
Dance 0:f1ecca559ec3 61 KEY_INSERT, /* Insert key */
Dance 0:f1ecca559ec3 62 KEY_HOME, /* Home key */
Dance 0:f1ecca559ec3 63 KEY_PAGE_UP, /* Page Up key */
Dance 0:f1ecca559ec3 64 KEY_PAGE_DOWN, /* Page Down key */
Dance 0:f1ecca559ec3 65
Dance 0:f1ecca559ec3 66 RIGHT_ARROW, /* Right arrow */
Dance 0:f1ecca559ec3 67 LEFT_ARROW, /* Left arrow */
Dance 0:f1ecca559ec3 68 DOWN_ARROW, /* Down arrow */
Dance 0:f1ecca559ec3 69 UP_ARROW, /* Up arrow */
Dance 0:f1ecca559ec3 70 };
Dance 0:f1ecca559ec3 71
Dance 0:f1ecca559ec3 72 /**
Dance 0:f1ecca559ec3 73 * USBKeyboard example
Dance 0:f1ecca559ec3 74 * @code
Dance 0:f1ecca559ec3 75 *
Dance 0:f1ecca559ec3 76 * #include "mbed.h"
Dance 0:f1ecca559ec3 77 * #include "USBKeyboard.h"
Dance 0:f1ecca559ec3 78 *
Dance 0:f1ecca559ec3 79 * USBKeyboard key;
Dance 0:f1ecca559ec3 80 *
Dance 0:f1ecca559ec3 81 * int main(void)
Dance 0:f1ecca559ec3 82 * {
Dance 0:f1ecca559ec3 83 * while (1)
Dance 0:f1ecca559ec3 84 * {
Dance 0:f1ecca559ec3 85 * key.printf("Hello World\r\n");
Dance 0:f1ecca559ec3 86 * wait(1);
Dance 0:f1ecca559ec3 87 * }
Dance 0:f1ecca559ec3 88 * }
Dance 0:f1ecca559ec3 89 *
Dance 0:f1ecca559ec3 90 * @endcode
Dance 0:f1ecca559ec3 91 */
Dance 0:f1ecca559ec3 92 class USBKeyboard: public USBHID, public Stream {
Dance 0:f1ecca559ec3 93 public:
Dance 0:f1ecca559ec3 94
Dance 0:f1ecca559ec3 95 /**
Dance 0:f1ecca559ec3 96 * Constructor
Dance 0:f1ecca559ec3 97 *
Dance 0:f1ecca559ec3 98 *
Dance 0:f1ecca559ec3 99 * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK
Dance 0:f1ecca559ec3 100 * @param vendor_id Your vendor_id (default: 0x1235)
Dance 0:f1ecca559ec3 101 * @param product_id Your product_id (default: 0x0050)
Dance 0:f1ecca559ec3 102 * @param product_release Your preoduct_release (default: 0x0001)
Dance 0:f1ecca559ec3 103 *
Dance 0:f1ecca559ec3 104 */
Dance 0:f1ecca559ec3 105 USBKeyboard(uint16_t vendor_id = 0x1235, uint16_t product_id = 0x0050, uint16_t product_release = 0x0001):
Dance 0:f1ecca559ec3 106 USBHID(0, 0, vendor_id, product_id, product_release, false) {
Dance 0:f1ecca559ec3 107 lock_status = 0;
Dance 0:f1ecca559ec3 108 connect();
Dance 0:f1ecca559ec3 109 };
Dance 0:f1ecca559ec3 110
Dance 0:f1ecca559ec3 111 /**
Dance 0:f1ecca559ec3 112 * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key
Dance 0:f1ecca559ec3 113 *
Dance 0:f1ecca559ec3 114 * @code
Dance 0:f1ecca559ec3 115 * //To send CTRL + s (save)
Dance 0:f1ecca559ec3 116 * keyboard.keyCode('s', KEY_CTRL);
Dance 0:f1ecca559ec3 117 * @endcode
Dance 0:f1ecca559ec3 118 *
Dance 0:f1ecca559ec3 119 * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0)
Dance 0:f1ecca559ec3 120 * @param key character to send
Dance 0:f1ecca559ec3 121 * @returns true if there is no error, false otherwise
Dance 0:f1ecca559ec3 122 */
Dance 0:f1ecca559ec3 123 bool keyCode(uint8_t key, uint8_t modifier = 0);
Dance 0:f1ecca559ec3 124
Dance 0:f1ecca559ec3 125 /**
Dance 0:f1ecca559ec3 126 * Send a character
Dance 0:f1ecca559ec3 127 *
Dance 0:f1ecca559ec3 128 * @param c character to be sent
Dance 0:f1ecca559ec3 129 * @returns true if there is no error, false otherwise
Dance 0:f1ecca559ec3 130 */
Dance 0:f1ecca559ec3 131 virtual int _putc(int c);
Dance 0:f1ecca559ec3 132
Dance 0:f1ecca559ec3 133 /**
Dance 0:f1ecca559ec3 134 * Control media keys
Dance 0:f1ecca559ec3 135 *
Dance 0:f1ecca559ec3 136 * @param key media key pressed (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN)
Dance 0:f1ecca559ec3 137 * @returns true if there is no error, false otherwise
Dance 0:f1ecca559ec3 138 */
Dance 0:f1ecca559ec3 139 bool mediaControl(MEDIA_KEY key);
Dance 0:f1ecca559ec3 140
Dance 0:f1ecca559ec3 141 /*
Dance 0:f1ecca559ec3 142 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
Dance 0:f1ecca559ec3 143 *
Dance 0:f1ecca559ec3 144 * @returns pointer to the report descriptor
Dance 0:f1ecca559ec3 145 */
Dance 0:f1ecca559ec3 146 virtual uint8_t * reportDesc();
Dance 0:f1ecca559ec3 147
Dance 0:f1ecca559ec3 148 /*
Dance 0:f1ecca559ec3 149 * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys
Dance 0:f1ecca559ec3 150 *
Dance 0:f1ecca559ec3 151 * @returns if handle by subclass, return true
Dance 0:f1ecca559ec3 152 */
Dance 0:f1ecca559ec3 153 virtual bool EP1_OUT_callback();
Dance 0:f1ecca559ec3 154
Dance 0:f1ecca559ec3 155 /**
Dance 0:f1ecca559ec3 156 * Read status of lock keys. Useful to switch-on/off leds according to key pressed. Only the first three bits of the result is important:
Dance 0:f1ecca559ec3 157 * - First bit: NUM_LOCK
Dance 0:f1ecca559ec3 158 * - Second bit: CAPS_LOCK
Dance 0:f1ecca559ec3 159 * - Third bit: SCROLL_LOCK
Dance 0:f1ecca559ec3 160 *
Dance 0:f1ecca559ec3 161 * @returns status of lock keys
Dance 0:f1ecca559ec3 162 */
Dance 0:f1ecca559ec3 163 uint8_t lockStatus();
Dance 0:f1ecca559ec3 164
Dance 0:f1ecca559ec3 165 protected:
Dance 0:f1ecca559ec3 166 /*
Dance 0:f1ecca559ec3 167 * Get configuration descriptor
Dance 0:f1ecca559ec3 168 *
Dance 0:f1ecca559ec3 169 * @returns pointer to the configuration descriptor
Dance 0:f1ecca559ec3 170 */
Dance 0:f1ecca559ec3 171 virtual uint8_t * configurationDesc();
Dance 0:f1ecca559ec3 172
Dance 0:f1ecca559ec3 173 private:
Dance 0:f1ecca559ec3 174 //dummy otherwise it doesn,t compile (we must define all methods of an abstract class)
Dance 0:f1ecca559ec3 175 virtual int _getc() {
Dance 0:f1ecca559ec3 176 return -1;
Dance 0:f1ecca559ec3 177 };
Dance 0:f1ecca559ec3 178
Dance 0:f1ecca559ec3 179 uint8_t lock_status;
Dance 0:f1ecca559ec3 180
Dance 0:f1ecca559ec3 181 };
Dance 0:f1ecca559ec3 182
Dance 0:f1ecca559ec3 183 #endif