Ryo Od
/
Nucleo-F767_DCO_Test01
Nucleo-F767 DCO Test 01
Diff: main.cpp
- Revision:
- 0:000c6506ff90
- Child:
- 1:4fc93890f58e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Jul 23 17:05:39 2018 +0000 @@ -0,0 +1,79 @@ +/* + Nucleo F767 DCO + 2018.07.22 + +*/ +#include "mbed.h" + +#include "wavetable_12bit_16k.h" +#define COUNT_OF_ENTRIES (16384) + +#define PIN_CHECK (1) +#define UART_TRACE (0) +#define TITLE_STR1 ("Nucleo F767 DCO") +#define TITLE_STR2 ("20180724") + +// Pin Assign +AnalogOut Dac1(PA_4); +AnalogOut Dac2(PA_5); + +#if (PIN_CHECK) +DigitalOut CheckPin(D4); +#endif + +// Parameter +double drate = 1000.0; // initial output rate (Hz) +const double refclk = 418000.0; // Hz + +// Interruput +Ticker ticker; + +// DDS +volatile uint32_t phaccu; +volatile uint32_t tword_m; + +//------------------------------------------------------------------------------------------------- +// Interrupt Service Routine +// + +// param +// val: 0 .. 4095 +void InternalDacWrite(uint16_t val) +{ + // avoid distortion of built-in DAC + uint16_t v = ((val + 1024) << 3); + + Dac2.write_u16(v); +} + +void update() +{ +#if (PIN_CHECK) + CheckPin.write(1); +#endif + + phaccu = phaccu + tword_m; + uint16_t idx = phaccu >> 18; // use upper 14 bits + + InternalDacWrite(sin_12bit_16k[idx]); + +#if (PIN_CHECK) + CheckPin.write(0); +#endif +} + +//------------------------------------------------------------------------------------------------- +// Main routine +// + +int main() +{ + tword_m = pow(2.0, 32) * drate / refclk; // calculate DDS tuning word; + + float interruptPeriodUs = 1000000.0 / refclk; + ticker.attach_us(&update, interruptPeriodUs); + + while (1) { + } +} +