Ryo Od
/
Nucleo-F767_DCO_Test01
Nucleo-F767 DCO Test 01
main.cpp
- Committer:
- ryood
- Date:
- 2018-07-23
- Revision:
- 3:19bb7c30c354
- Parent:
- 2:4834d4483ea6
- Child:
- 4:b242f4206894
File content as of revision 3:19bb7c30c354:
/* Nucleo F767 DCO 2018.07.22 */ #include "mbed.h" #include "wavetable_12bit_32k.h" #define COUNT_OF_ENTRIES (32768) #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 = 440.0; // initial output rate (Hz) const double refclk = 200000; // Hz // Interruput Ticker ticker; // DDS volatile uint32_t phaccu; volatile uint32_t tword_m; //------------------------------------------------------------------------------------------------- // Interrupt Service Routine // // param // channel: 1 or 2 // val: 0 .. 4095 void InternalDacWrite(int ch, uint16_t val) { // avoid distortion of built-in DAC uint16_t v = ((val + 1024) << 3); switch(ch) { case 1: Dac1.write_u16(v); break; case 2: Dac2.write_u16(v); break; } } void update() { #if (PIN_CHECK) CheckPin.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]); #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) { } }