KIK01 Release

Dependencies:   mcp3008 mbed mbed-rtos AverageMCP3008 VoltageMonitor

Committer:
ryood
Date:
Sat Feb 23 08:46:10 2019 +0000
Revision:
40:2e252971aa08
Parent:
39:3c73531d13a2
Child:
41:ac576c48eace
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ryood 3:f89b400cfe57 1 /*
ryood 3:f89b400cfe57 2 * KIK01
ryood 3:f89b400cfe57 3 * Kick Machine
ryood 3:f89b400cfe57 4 *
ryood 40:2e252971aa08 5 * 2019.02.23 Ver.1.01 Dual SyncIns / SyncOuts
ryood 39:3c73531d13a2 6 * 2018.01.17 Release
ryood 35:05798de92fb5 7 * 2017.12.15 Proto08: LEDs
ryood 33:eac518ea0f34 8 * 2017.12.03 Proto07: SyncIn
ryood 32:41cda5ad45e4 9 * 2017.11.29 Proto06: Add Power Monitor
ryood 27:b07a55935230 10 * 2017.10.19 Proto05: Add NOS01 Controller
ryood 17:a5d9908bd456 11 * 2017.09.16 Proto04: SPI1 for AD8402 Wein Bridge DCO & Internal DAC for Dual-OTA-VCA
ryood 15:8f674acdac03 12 * 2017.07.04 Proto03: MCP4922 DCA
ryood 13:43a43da257e3 13 * 2017.06.19 Proto02
ryood 3:f89b400cfe57 14 * 2017.06.04 created.
ryood 3:f89b400cfe57 15 *
ryood 3:f89b400cfe57 16 */
ryood 3:f89b400cfe57 17
ryood 0:2dcec10e9199 18 #include "mbed.h"
ryood 0:2dcec10e9199 19 #include "rtos.h"
ryood 13:43a43da257e3 20 #include "mcp3008.h"
ryood 28:387c5a6d5206 21 #include "AverageMCP3008.h"
ryood 22:a3bb7594f9bb 22 #include "EnvelopeAR.h"
ryood 0:2dcec10e9199 23
ryood 38:90dde01f8255 24 #define UART_TRACE (0)
ryood 32:41cda5ad45e4 25 #include "VoltageMonitor.h"
ryood 32:41cda5ad45e4 26
ryood 38:90dde01f8255 27 #define PIN_CHECK (0)
ryood 36:3543a352b9d4 28 #define LED_SYNCOUT_BLINK (1)
ryood 36:3543a352b9d4 29
ryood 40:2e252971aa08 30 #define TITLE_STR1 ("KIK01 Kick Machine Ver.1.0.1")
ryood 40:2e252971aa08 31 #define TITLE_STR2 ("20190223")
ryood 40:2e252971aa08 32 #define TITLE_STR3 (__TIME__)
ryood 0:2dcec10e9199 33
ryood 0:2dcec10e9199 34 #define PI_F (3.1415926f)
ryood 15:8f674acdac03 35
ryood 35:05798de92fb5 36 #define MCP3008_SPI_SPEED (1406250)
ryood 21:a527f51381d6 37 #define AD8402_SPI_SPEED (10000000)
ryood 31:3c7e1cd0d947 38 #define ENVELOPE_UPDATE_RATE (32000) // Hz
ryood 17:a5d9908bd456 39
ryood 20:70a05941db8c 40 #define AD8402_RMAX (10000.0f)
ryood 20:70a05941db8c 41 #define AD8402_RMIN (50.0f)
ryood 20:70a05941db8c 42
ryood 31:3c7e1cd0d947 43 #define AVERAGE_BUFFER_SIZE (4)
ryood 31:3c7e1cd0d947 44
ryood 32:41cda5ad45e4 45 #define PM_VDD (3.32f)
ryood 35:05798de92fb5 46 #define PM_LoThreshold (2.3f)
ryood 35:05798de92fb5 47 #define PM_HiThreshold (2.7f)
ryood 32:41cda5ad45e4 48
ryood 40:2e252971aa08 49 #define LED_BEAT_KIK_BLINK_CYCLE (0.15f)
ryood 40:2e252971aa08 50 #define LED_BEAT_NOS_BLINK_CYCLE (0.15f)
ryood 40:2e252971aa08 51 #define LED_SYNCIN_KIK_BLINK_CYCLE (0.04f)
ryood 40:2e252971aa08 52 #define LED_SYNCIN_NOS_BLINK_CYCLE (0.04f)
ryood 40:2e252971aa08 53 #define LED_SYNCOUT_KIK_BLINK_CYCLE (0.04f)
ryood 40:2e252971aa08 54 #define LED_SYNCOUT_NOS_BLINK_CYCLE (0.04f)
ryood 36:3543a352b9d4 55
ryood 35:05798de92fb5 56 // LEDs
ryood 36:3543a352b9d4 57 DigitalOut LedPower(PB_2);
ryood 40:2e252971aa08 58
ryood 40:2e252971aa08 59 DigitalOut LedBeatKik(PA_12);
ryood 40:2e252971aa08 60 DigitalOut LedSyncInKik(PA_11);
ryood 40:2e252971aa08 61 DigitalOut LedSyncOutKik(PB_12);
ryood 40:2e252971aa08 62
ryood 40:2e252971aa08 63 DigitalOut LedBeatNos(PC_8);
ryood 40:2e252971aa08 64 DigitalOut LedSyncInNos(PC_6);
ryood 40:2e252971aa08 65 DigitalOut LedSyncOutNos(PC_5);
ryood 35:05798de92fb5 66
ryood 35:05798de92fb5 67 // Envelope Output
ryood 40:2e252971aa08 68 AnalogOut Dac1(PA_4); // Kik
ryood 40:2e252971aa08 69 AnalogOut Dac2(PA_5); // Nos
ryood 3:f89b400cfe57 70
ryood 26:866d672ba446 71 // AD8402 SPI (SPI2)
ryood 26:866d672ba446 72 // SPI (PinName mosi, PinName miso, PinName sclk, PinName ssel=NC)
ryood 26:866d672ba446 73 SPI SpiMAD8402(PB_15, PB_14, PB_13);
ryood 35:05798de92fb5 74 DigitalOut AD8402Cs(PC_4, 1); // Initaially Inactive
ryood 15:8f674acdac03 75
ryood 18:1bf4abf6895b 76 // MCP3008 SPI
ryood 26:866d672ba446 77 // SPI (PinName mosi, PinName miso, PinName sclk, PinName ssel=NC)
ryood 26:866d672ba446 78 SPI SpiMAdc(PB_5, PB_4, PB_3);
ryood 32:41cda5ad45e4 79 MCP3008 Adc1(&SpiMAdc, PA_9);
ryood 26:866d672ba446 80 MCP3008 Adc2(&SpiMAdc, PA_8);
ryood 32:41cda5ad45e4 81 MCP3008 Adc3(&SpiMAdc, PB_10);
ryood 31:3c7e1cd0d947 82 AverageMCP3008 AvgAdc1(&Adc1, AVERAGE_BUFFER_SIZE);
ryood 31:3c7e1cd0d947 83 AverageMCP3008 AvgAdc2(&Adc2, AVERAGE_BUFFER_SIZE);
ryood 32:41cda5ad45e4 84 AverageMCP3008 AvgAdc3(&Adc3, AVERAGE_BUFFER_SIZE);
ryood 32:41cda5ad45e4 85
ryood 32:41cda5ad45e4 86 // Power Monitor
ryood 32:41cda5ad45e4 87 AnalogIn PowerMonitorIn(PA_0);
ryood 35:05798de92fb5 88 VoltageMonitor PWMon(&PowerMonitorIn, PM_VDD, PM_LoThreshold, PM_HiThreshold, &LedPower);
ryood 8:bb34a4894337 89
ryood 18:1bf4abf6895b 90 // Sync
ryood 40:2e252971aa08 91 DigitalOut SyncOutKik(PC_12);
ryood 40:2e252971aa08 92 DigitalOut SyncOutNos(PD_2);
ryood 40:2e252971aa08 93
ryood 40:2e252971aa08 94 InterruptIn SyncInKik(PC_10);
ryood 40:2e252971aa08 95 InterruptIn SyncInNos(PC_11);
ryood 40:2e252971aa08 96
ryood 37:85eb8e38cac8 97 DigitalIn AutoRunSw(PB_1);
ryood 18:1bf4abf6895b 98
ryood 14:8e96f97e261b 99 // Check pins
ryood 36:3543a352b9d4 100 DigitalOut Dout1(D14);
ryood 36:3543a352b9d4 101 DigitalOut Dout2(D15);
ryood 36:3543a352b9d4 102 DigitalOut Dout3(D2);
ryood 14:8e96f97e261b 103
ryood 40:2e252971aa08 104 EnvelopeAR envelopeFrequencyKik(5, 300, 880.0f, 120.0f, 40.0f, 0.36f, 0.1f);
ryood 40:2e252971aa08 105 EnvelopeAR envelopeAmplitudeKik(50, 200, 0.99f, 1.0f, 0.0f);
ryood 40:2e252971aa08 106 EnvelopeAR envelopeAmplitudeNos(50, 200, 0.99f, 1.0f, 0.0f);
ryood 40:2e252971aa08 107
ryood 40:2e252971aa08 108 EnvelopeParam frequencyParamKik;
ryood 40:2e252971aa08 109 EnvelopeParam amplitudeParamKik;
ryood 40:2e252971aa08 110 EnvelopeParam amplitudeParamNos;
ryood 5:846772a77d33 111
ryood 40:2e252971aa08 112 Timeout timeoutLedBeatKik;
ryood 40:2e252971aa08 113 Timeout timeoutLedBeatNos;
ryood 40:2e252971aa08 114 Timeout timeoutLedSyncInKik;
ryood 40:2e252971aa08 115 Timeout timeoutLedSyncInNos;
ryood 36:3543a352b9d4 116 #if (LED_SYNCOUT_BLINK)
ryood 40:2e252971aa08 117 Timeout timeoutLedSyncOutKik;
ryood 40:2e252971aa08 118 Timeout timeoutLedSyncOutNos;
ryood 36:3543a352b9d4 119 #endif
ryood 36:3543a352b9d4 120
ryood 40:2e252971aa08 121 volatile int ticksKik;
ryood 40:2e252971aa08 122 volatile int ticksNos;
ryood 40:2e252971aa08 123 volatile float frequencyKik;
ryood 40:2e252971aa08 124 volatile float amplitudeKik;
ryood 40:2e252971aa08 125 volatile float amplitudeNos;
ryood 3:f89b400cfe57 126
ryood 5:846772a77d33 127 volatile int envelopeLength;
ryood 14:8e96f97e261b 128 volatile int stepLength;
ryood 0:2dcec10e9199 129
ryood 38:90dde01f8255 130 float bpm;
ryood 38:90dde01f8255 131
ryood 36:3543a352b9d4 132 //-----------------------------------------------------------------------------
ryood 38:90dde01f8255 133 // Interrupt Service Routine
ryood 36:3543a352b9d4 134 //-----------------------------------------------------------------------------
ryood 36:3543a352b9d4 135
ryood 40:2e252971aa08 136 void ledBeatAtTimeoutKik()
ryood 36:3543a352b9d4 137 {
ryood 40:2e252971aa08 138 LedBeatKik = 0;
ryood 36:3543a352b9d4 139 }
ryood 36:3543a352b9d4 140
ryood 40:2e252971aa08 141 void ledBeatAtTimeoutNos()
ryood 40:2e252971aa08 142 {
ryood 40:2e252971aa08 143 LedBeatNos = 0;
ryood 40:2e252971aa08 144 }
ryood 40:2e252971aa08 145
ryood 40:2e252971aa08 146 void ledSyncInAtTimeoutKik()
ryood 36:3543a352b9d4 147 {
ryood 40:2e252971aa08 148 LedSyncInKik = 0;
ryood 40:2e252971aa08 149 }
ryood 40:2e252971aa08 150
ryood 40:2e252971aa08 151 void ledSyncInAtTimeoutNos()
ryood 40:2e252971aa08 152 {
ryood 40:2e252971aa08 153 LedSyncInNos = 0;
ryood 36:3543a352b9d4 154 }
ryood 36:3543a352b9d4 155
ryood 36:3543a352b9d4 156 #if (LED_SYNCOUT_BLINK)
ryood 40:2e252971aa08 157 void ledSyncOutAtTimeoutKik()
ryood 36:3543a352b9d4 158 {
ryood 40:2e252971aa08 159 LedSyncOutKik = 0;
ryood 40:2e252971aa08 160 }
ryood 40:2e252971aa08 161
ryood 40:2e252971aa08 162 void ledSyncOutAtTimeoutNos()
ryood 40:2e252971aa08 163 {
ryood 40:2e252971aa08 164 LedSyncOutNos = 0;
ryood 36:3543a352b9d4 165 }
ryood 36:3543a352b9d4 166 #endif
ryood 36:3543a352b9d4 167
ryood 40:2e252971aa08 168 void syncInFunctionKik()
ryood 38:90dde01f8255 169 {
ryood 40:2e252971aa08 170 ticksKik = 0;
ryood 40:2e252971aa08 171 LedSyncInKik = 1;
ryood 40:2e252971aa08 172 timeoutLedSyncInKik.attach(&ledSyncInAtTimeoutKik, LED_SYNCIN_KIK_BLINK_CYCLE);
ryood 40:2e252971aa08 173 }
ryood 40:2e252971aa08 174
ryood 40:2e252971aa08 175 void syncInFunctionNos()
ryood 40:2e252971aa08 176 {
ryood 40:2e252971aa08 177 ticksNos = 0;
ryood 40:2e252971aa08 178 LedSyncInNos = 1;
ryood 40:2e252971aa08 179 timeoutLedSyncInNos.attach(&ledSyncInAtTimeoutNos, LED_SYNCIN_NOS_BLINK_CYCLE);
ryood 38:90dde01f8255 180 }
ryood 36:3543a352b9d4 181
ryood 17:a5d9908bd456 182 void AD8402Write(uint8_t address, uint8_t value)
ryood 17:a5d9908bd456 183 {
ryood 21:a527f51381d6 184 #if (PIN_CHECK)
ryood 26:866d672ba446 185 Dout2 = 1;
ryood 21:a527f51381d6 186 #endif
ryood 21:a527f51381d6 187
ryood 18:1bf4abf6895b 188 AD8402Cs = 0;
ryood 21:a527f51381d6 189 SpiMAD8402.write(address);
ryood 21:a527f51381d6 190 SpiMAD8402.write(value);
ryood 18:1bf4abf6895b 191 AD8402Cs = 1;
ryood 39:3c73531d13a2 192 //wait_us(1);
ryood 21:a527f51381d6 193
ryood 21:a527f51381d6 194 #if (PIN_CHECK)
ryood 26:866d672ba446 195 Dout2 = 0;
ryood 21:a527f51381d6 196 #endif
ryood 17:a5d9908bd456 197 }
ryood 17:a5d9908bd456 198
ryood 23:da7c5f7feff1 199 void DcoSetFrequency(float freq)
ryood 17:a5d9908bd456 200 {
ryood 17:a5d9908bd456 201 const float c = 0.00000047;
ryood 40:2e252971aa08 202 float r = 1.0f / (2.0f * PI_F * frequencyKik * c);
ryood 20:70a05941db8c 203 if (r < AD8402_RMIN) r = AD8402_RMIN;
ryood 20:70a05941db8c 204 if (r > AD8402_RMAX) r = AD8402_RMAX;
ryood 20:70a05941db8c 205
ryood 20:70a05941db8c 206 uint8_t v = 256.0f * (r - AD8402_RMIN) / AD8402_RMAX;
ryood 21:a527f51381d6 207
ryood 17:a5d9908bd456 208 AD8402Write(0, v);
ryood 17:a5d9908bd456 209 AD8402Write(1, v);
ryood 23:da7c5f7feff1 210 }
ryood 17:a5d9908bd456 211
ryood 27:b07a55935230 212 void DcaSetAmplitude(int channel, float amp)
ryood 23:da7c5f7feff1 213 {
ryood 27:b07a55935230 214 switch (channel) {
ryood 27:b07a55935230 215 case 1:
ryood 27:b07a55935230 216 Dac1.write(amp);
ryood 27:b07a55935230 217 break;
ryood 27:b07a55935230 218 case 2:
ryood 33:eac518ea0f34 219 //Dac2.write(amp);
ryood 27:b07a55935230 220 Dac2.write(amp * 0.8f); // Avoid LED,s Non-Linearity
ryood 27:b07a55935230 221 break;
ryood 27:b07a55935230 222 default:
ryood 27:b07a55935230 223 error("DcaSetAmplitude(): invalid channel");
ryood 27:b07a55935230 224 }
ryood 17:a5d9908bd456 225 }
ryood 15:8f674acdac03 226
ryood 2:8dff77a1ee4d 227 void update()
ryood 2:8dff77a1ee4d 228 {
ryood 12:5b498285d121 229 #if (PIN_CHECK)
ryood 26:866d672ba446 230 Dout1 = 1;
ryood 12:5b498285d121 231 #endif
ryood 15:8f674acdac03 232
ryood 14:8e96f97e261b 233 // Output Sync Signal per steps
ryood 40:2e252971aa08 234 if (ticksKik % stepLength == 0) {
ryood 40:2e252971aa08 235 SyncOutKik = 1;
ryood 36:3543a352b9d4 236 #if (LED_SYNCOUT_BLINK)
ryood 40:2e252971aa08 237 LedSyncOutKik = 1;
ryood 40:2e252971aa08 238 timeoutLedSyncOutKik.attach(&ledSyncOutAtTimeoutKik, LED_SYNCOUT_KIK_BLINK_CYCLE);
ryood 40:2e252971aa08 239 #endif
ryood 40:2e252971aa08 240 }
ryood 40:2e252971aa08 241
ryood 40:2e252971aa08 242 if (ticksNos % stepLength == 0) {
ryood 40:2e252971aa08 243 SyncOutNos = 1;
ryood 40:2e252971aa08 244 #if (LED_SYNCOUT_BLINK)
ryood 40:2e252971aa08 245 LedSyncOutNos = 1;
ryood 40:2e252971aa08 246 timeoutLedSyncOutNos.attach(&ledSyncOutAtTimeoutNos, LED_SYNCOUT_NOS_BLINK_CYCLE);
ryood 36:3543a352b9d4 247 #endif
ryood 14:8e96f97e261b 248 }
ryood 15:8f674acdac03 249
ryood 17:a5d9908bd456 250 // set envelope parameters
ryood 40:2e252971aa08 251 envelopeAmplitudeKik.setParam(amplitudeParamKik);
ryood 40:2e252971aa08 252 envelopeFrequencyKik.setParam(frequencyParamKik);
ryood 40:2e252971aa08 253 envelopeAmplitudeNos.setParam(amplitudeParamNos);
ryood 11:7e11404adca0 254
ryood 40:2e252971aa08 255 frequencyKik = envelopeFrequencyKik.getAmplitude(ticksKik);
ryood 40:2e252971aa08 256 amplitudeKik = envelopeAmplitudeKik.getAmplitude(ticksKik);
ryood 40:2e252971aa08 257 amplitudeNos = envelopeAmplitudeNos.getAmplitude(ticksNos);
ryood 23:da7c5f7feff1 258
ryood 40:2e252971aa08 259 DcoSetFrequency(frequencyKik);
ryood 40:2e252971aa08 260 DcaSetAmplitude(1, amplitudeKik);
ryood 40:2e252971aa08 261 DcaSetAmplitude(2, amplitudeNos);
ryood 11:7e11404adca0 262
ryood 40:2e252971aa08 263 ticksKik++;
ryood 40:2e252971aa08 264 ticksNos++;
ryood 40:2e252971aa08 265 if (AutoRunSw && ticksKik >= envelopeLength) {
ryood 40:2e252971aa08 266 ticksKik = 0;
ryood 40:2e252971aa08 267 LedBeatKik = 1;
ryood 40:2e252971aa08 268 timeoutLedBeatKik.attach(&ledBeatAtTimeoutKik, LED_BEAT_KIK_BLINK_CYCLE);
ryood 40:2e252971aa08 269 }
ryood 40:2e252971aa08 270 if (AutoRunSw && ticksNos >= envelopeLength) {
ryood 40:2e252971aa08 271 ticksNos = 0;
ryood 40:2e252971aa08 272 LedBeatNos = 1;
ryood 40:2e252971aa08 273 timeoutLedBeatNos.attach(&ledBeatAtTimeoutNos, LED_BEAT_NOS_BLINK_CYCLE);
ryood 2:8dff77a1ee4d 274 }
ryood 15:8f674acdac03 275
ryood 14:8e96f97e261b 276 // Output SyncSignal
ryood 40:2e252971aa08 277 SyncOutKik = 0;
ryood 40:2e252971aa08 278 SyncOutNos = 0;
ryood 15:8f674acdac03 279
ryood 12:5b498285d121 280 #if (PIN_CHECK)
ryood 26:866d672ba446 281 Dout1 = 0;
ryood 12:5b498285d121 282 #endif
ryood 2:8dff77a1ee4d 283 }
ryood 2:8dff77a1ee4d 284
ryood 38:90dde01f8255 285 //-----------------------------------------------------------------------------
ryood 38:90dde01f8255 286 // Functions
ryood 38:90dde01f8255 287 //-----------------------------------------------------------------------------
ryood 38:90dde01f8255 288
ryood 25:b4977c7e0db7 289 void readParams()
ryood 5:846772a77d33 290 {
ryood 28:387c5a6d5206 291 bpm = AvgAdc1.read_input(7) * 180.0f + 60.0f;
ryood 12:5b498285d121 292 envelopeLength = 60 * ENVELOPE_UPDATE_RATE / bpm;
ryood 14:8e96f97e261b 293 stepLength = envelopeLength / 4;
ryood 11:7e11404adca0 294
ryood 40:2e252971aa08 295 amplitudeParamKik.attack = AvgAdc1.read_input(0) * envelopeLength + 1;
ryood 40:2e252971aa08 296 amplitudeParamKik.release = AvgAdc1.read_input(1) * envelopeLength;
ryood 40:2e252971aa08 297 amplitudeParamKik.v0 = AvgAdc1.read_input(4);
ryood 40:2e252971aa08 298 amplitudeParamKik.v1 = AvgAdc1.read_input(5);
ryood 40:2e252971aa08 299 amplitudeParamKik.v2 = AvgAdc1.read_input(6);
ryood 40:2e252971aa08 300 amplitudeParamKik.attackTauRatio = AvgAdc1.read_input(2) + 0.01f;
ryood 40:2e252971aa08 301 amplitudeParamKik.releaseTauRatio = AvgAdc1.read_input(3) + 0.01f;
ryood 11:7e11404adca0 302
ryood 40:2e252971aa08 303 frequencyParamKik.attack = AvgAdc2.read_input(0) * envelopeLength * 0.1f;
ryood 40:2e252971aa08 304 frequencyParamKik.release = AvgAdc2.read_input(1) * envelopeLength + 1;
ryood 40:2e252971aa08 305 frequencyParamKik.v0 = AvgAdc2.read_input(4) * 4000.0f;
ryood 40:2e252971aa08 306 frequencyParamKik.v1 = AvgAdc2.read_input(5) * 400.0f;
ryood 40:2e252971aa08 307 frequencyParamKik.v2 = AvgAdc2.read_input(6) * 400.0f;
ryood 40:2e252971aa08 308 frequencyParamKik.attackTauRatio = AvgAdc2.read_input(2) + 0.01f;
ryood 40:2e252971aa08 309 frequencyParamKik.releaseTauRatio = AvgAdc2.read_input(3) + 0.01f;
ryood 29:947992b9904f 310
ryood 40:2e252971aa08 311 amplitudeParamNos.attack = AvgAdc3.read_input(0) * envelopeLength + 1;
ryood 40:2e252971aa08 312 amplitudeParamNos.release = AvgAdc3.read_input(1) * envelopeLength;
ryood 40:2e252971aa08 313 amplitudeParamNos.v0 = AvgAdc3.read_input(4);
ryood 40:2e252971aa08 314 amplitudeParamNos.v1 = AvgAdc3.read_input(5);
ryood 40:2e252971aa08 315 amplitudeParamNos.v2 = AvgAdc3.read_input(6);
ryood 40:2e252971aa08 316 amplitudeParamNos.attackTauRatio = AvgAdc3.read_input(2) + 0.01f;
ryood 40:2e252971aa08 317 amplitudeParamNos.releaseTauRatio = AvgAdc3.read_input(3) + 0.01f;
ryood 5:846772a77d33 318 }
ryood 5:846772a77d33 319
ryood 35:05798de92fb5 320 void LedsCheck(int n, int wait)
ryood 35:05798de92fb5 321 {
ryood 35:05798de92fb5 322 for (int i = 0; i < n; i++) {
ryood 40:2e252971aa08 323 LedBeatKik = 1;
ryood 38:90dde01f8255 324 Thread::wait(wait);
ryood 40:2e252971aa08 325 LedBeatKik = 0;
ryood 38:90dde01f8255 326
ryood 40:2e252971aa08 327 LedSyncInKik = 1;
ryood 38:90dde01f8255 328 Thread::wait(wait);
ryood 40:2e252971aa08 329 LedSyncInKik = 0;
ryood 38:90dde01f8255 330
ryood 40:2e252971aa08 331 LedSyncOutKik = 1;
ryood 35:05798de92fb5 332 Thread::wait(wait);
ryood 40:2e252971aa08 333 LedSyncOutKik = 0;
ryood 35:05798de92fb5 334 }
ryood 33:eac518ea0f34 335 }
ryood 33:eac518ea0f34 336
ryood 0:2dcec10e9199 337 int main()
ryood 0:2dcec10e9199 338 {
ryood 40:2e252971aa08 339 printf("\r\n\n%s %s %s\r\n", TITLE_STR1, TITLE_STR2, TITLE_STR3);
ryood 15:8f674acdac03 340
ryood 35:05798de92fb5 341 // LEDs Check
ryood 35:05798de92fb5 342 LedsCheck(4, 100); // 4 counts, 100ms cycle
ryood 35:05798de92fb5 343
ryood 21:a527f51381d6 344 SpiMAD8402.format(8, 0);
ryood 21:a527f51381d6 345 SpiMAD8402.frequency(AD8402_SPI_SPEED);
ryood 17:a5d9908bd456 346
ryood 26:866d672ba446 347 SpiMAdc.format(8, 0);
ryood 26:866d672ba446 348 SpiMAdc.frequency(MCP3008_SPI_SPEED);
ryood 36:3543a352b9d4 349
ryood 40:2e252971aa08 350 SyncInKik.mode(PullDown);
ryood 40:2e252971aa08 351 SyncInNos.mode(PullDown);
ryood 37:85eb8e38cac8 352 AutoRunSw.mode(PullUp);
ryood 15:8f674acdac03 353
ryood 40:2e252971aa08 354 frequencyKik = 100.0f;
ryood 40:2e252971aa08 355 amplitudeKik = 1.0f;
ryood 40:2e252971aa08 356 amplitudeNos = 1.0f;
ryood 17:a5d9908bd456 357 bpm = 120.0f;
ryood 17:a5d9908bd456 358
ryood 25:b4977c7e0db7 359 readParams();
ryood 11:7e11404adca0 360
ryood 40:2e252971aa08 361 ticksKik = 0;
ryood 40:2e252971aa08 362 ticksNos = 0;
ryood 2:8dff77a1ee4d 363 Ticker samplingTicker;
ryood 17:a5d9908bd456 364 samplingTicker.attach(&update, (1.0f/ENVELOPE_UPDATE_RATE));
ryood 33:eac518ea0f34 365
ryood 33:eac518ea0f34 366 // Sync Interrupt
ryood 40:2e252971aa08 367 SyncInKik.rise(&syncInFunctionKik);
ryood 40:2e252971aa08 368 SyncInNos.rise(&syncInFunctionNos);
ryood 11:7e11404adca0 369
ryood 3:f89b400cfe57 370 for (;;) {
ryood 13:43a43da257e3 371 #if (PIN_CHECK)
ryood 26:866d672ba446 372 Dout3 = 1;
ryood 15:8f674acdac03 373 #endif
ryood 25:b4977c7e0db7 374
ryood 25:b4977c7e0db7 375 readParams();
ryood 25:b4977c7e0db7 376
ryood 13:43a43da257e3 377 #if (PIN_CHECK)
ryood 26:866d672ba446 378 Dout3 = 0;
ryood 15:8f674acdac03 379 #endif
ryood 11:7e11404adca0 380
ryood 32:41cda5ad45e4 381
ryood 11:7e11404adca0 382 #if UART_TRACE
ryood 6:897d6392b408 383 printf("%.1f\t%d\t", bpm, envelopeLength);
ryood 11:7e11404adca0 384
ryood 40:2e252971aa08 385 printf("| %d\t%d\t", amplitudeParamKik.attack, amplitudeParamKik.release);
ryood 40:2e252971aa08 386 printf("%.2f\t%.2f\t%.2f\t", amplitudeParamKik.v0, amplitudeParamKik.v1, amplitudeParamKik.v2);
ryood 40:2e252971aa08 387 printf("%.2f\t%.2f\t", amplitudeParamKik.attackTauRatio, amplitudeParamKik.releaseTauRatio);
ryood 6:897d6392b408 388
ryood 40:2e252971aa08 389 printf("| %d\t%d\t", frequencyParamKik.attack, frequencyParamKik.release);
ryood 40:2e252971aa08 390 printf("%.2f\t%.2f\t%.2f\t", frequencyParamKik.v0, frequencyParamKik.v1, frequencyParamKik.v2);
ryood 40:2e252971aa08 391 printf("%.2f\t%.2f\t", frequencyParamKik.attackTauRatio, frequencyParamKik.releaseTauRatio);
ryood 29:947992b9904f 392
ryood 40:2e252971aa08 393 printf("| %d\t%d\t", amplitudeParamNos.attack, amplitudeParamNos.release);
ryood 40:2e252971aa08 394 printf("%.2f\t%.2f\t%.2f\t", amplitudeParamNos.v0, amplitudeParamNos.v1, amplitudeParamNos.v2);
ryood 40:2e252971aa08 395 printf("%.2f\t%.2f\t", amplitudeParamNos.attackTauRatio, amplitudeParamNos.releaseTauRatio);
ryood 37:85eb8e38cac8 396
ryood 37:85eb8e38cac8 397 printf("| AutoRun:%d\t", int(AutoRunSw));
ryood 11:7e11404adca0 398 #endif
ryood 11:7e11404adca0 399
ryood 32:41cda5ad45e4 400 PWMon.check();
ryood 32:41cda5ad45e4 401
ryood 40:2e252971aa08 402 //Thread::wait(1);
ryood 3:f89b400cfe57 403 }
ryood 0:2dcec10e9199 404 }