Ryo Od
/
Nucleo-F767_DCO_Test01
Nucleo-F767 DCO Test 01
Diff: main.cpp
- Revision:
- 4:b242f4206894
- Parent:
- 3:19bb7c30c354
--- a/main.cpp Mon Jul 23 17:47:22 2018 +0000 +++ b/main.cpp Sun Aug 19 01:07:58 2018 +0000 @@ -1,5 +1,5 @@ /* - Nucleo F767 DCO + Nucleo F767 DCO Test01 2018.07.22 */ @@ -10,20 +10,22 @@ #define PIN_CHECK (1) #define UART_TRACE (0) -#define TITLE_STR1 ("Nucleo F767 DCO") -#define TITLE_STR2 ("20180724") +#define TITLE_STR1 ("Nucleo F767 DCO Test01") +#define TITLE_STR2 ("20180819") + // Pin Assign AnalogOut Dac1(PA_4); AnalogOut Dac2(PA_5); #if (PIN_CHECK) -DigitalOut CheckPin(D4); +DigitalOut CheckPin1(D4); +DigitalOut CheckPin2(D5); #endif // Parameter -double drate = 440.0; // initial output rate (Hz) -const double refclk = 200000; // Hz +double drate = 1000.0; // initial output rate (Hz) +const double refclk = 100000; // 100kHz // Interruput Ticker ticker; @@ -41,8 +43,9 @@ // val: 0 .. 4095 void InternalDacWrite(int ch, uint16_t val) { - // avoid distortion of built-in DAC - uint16_t v = ((val + 1024) << 3); + //uint16_t v = val << 4; + // avoid distortion of the built-in DAC + uint16_t v = (val + 256) * 14; switch(ch) { case 1: @@ -57,17 +60,17 @@ void update() { #if (PIN_CHECK) - CheckPin.write(1); + CheckPin1.write(1); #endif phaccu = phaccu + tword_m; uint16_t idx = phaccu >> 17; // use upper 15 bits InternalDacWrite(1, sin_12bit_32k[idx]); - InternalDacWrite(2, sin_12bit_32k[idx]); + //InternalDacWrite(2, sin_12bit_32k[idx]); #if (PIN_CHECK) - CheckPin.write(0); + CheckPin1.write(0); #endif } @@ -79,10 +82,17 @@ { tword_m = pow(2.0, 32) * drate / refclk; // calculate DDS tuning word; + // 1.0s / 1.0us = 1000000.0 float interruptPeriodUs = 1000000.0 / refclk; ticker.attach_us(&update, interruptPeriodUs); while (1) { +#if (PIN_CHECK) + CheckPin2.write(1); + wait_us(1); + CheckPin2.write(0); + wait_us(1); +#endif } }