Ryo Od
/
Nucleo-F767_DCO_Test01
Nucleo-F767 DCO Test 01
main.cpp
- Committer:
- ryood
- Date:
- 2018-07-23
- Revision:
- 2:4834d4483ea6
- Parent:
- 1:4fc93890f58e
- Child:
- 3:19bb7c30c354
File content as of revision 2:4834d4483ea6:
/* 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 = 1000.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 // 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 >> 17; // use upper 15 bits InternalDacWrite(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) { } }