send in the address and value via SPI: takes the Slave Select (SS or CS) pin low to select the DAC format/split sample for SPI port (4 config bits, followed by 12 audio bits) using formula below, calculate correct oscillator frequency valueįrequency = (frequencyInHertz * 65536.0) / sampleRate //here sampleRate is 44100 (or 44.1kHz) but it is convinient here to show freqency calculation normally we wouldn't use floats, and just use integers, Oscil = waveTable // get sample from wave tableĭACtimer->setOverflow(sampleRate, HERTZ_FORMAT) // 44.1kHzĭACtimer->attachInterrupt(std::bind(DACinterrupt)) // bind argument to callback: When Update_IT_callback is called MyData will be given as argumentįloat frequencyInHertz = Freq // use this to hold a frequency in hertz WaveIndex = phaseAcc > 8 // use top 8 bits as wavetable waveIndex PhaseAcc = phaseAcc + frequency // add in pith, the higher the number, the faster it rolls over, the more cycles per second Every 44.1kHz, calculate the oscillation frequency, map to the wavetable and output it via SPI. used for selecting the wavefrom from the wavetable. frequency = (FrequencyInHertz * 65536) / SampleRate, here sample rate is 44100 this is an integer proportial to Hertz in the following way: holds frequency value used for oscillator in phase steps Int waveIndex = 0 // Index for wave lookup (the upper 8 bits of the accumulator) Uint16_t phaseAcc = 0 // large number holds phase the two bytes that go to the DAC over SPI #define sampleRate 44100 // 44.1kHz sampling rate Other SPI 'default' SPI1 pins are :- MOSI1 = PA7 / SCLK1 = PA5 Test script for DAC output (12bit and 44.1kHz). If someone could talk me through/point me in the right direction, I'd appreciate it! (I was super close on the Arduino, but it was just too tight on power). I'm not really looking to maintain portability, as my aim is to just develop this as is. I'm not sure this will really give me much more overhead, but it feels like the correct way to do this. My main focus right now is to have the DMA handle the DAC/SPI interaction. I've used a couple of low-level commands to reduce the overhead of the SPI sending in the interrupt, and I'm pretty certain I need to doing my oscillator calculations outside of the interrupt, but, it works (even with up to 8 separate oscillators). This handles my oscillator calculations, and then sending my 12-bit sample to my DAC over SPI. I've currently got an interrupt that fires off at 44.1kHz. I think I understand that I need to maybe disable/alter the way the Arduino API uses the HAL functions, but I'm not sure how (or if I even need to for a DAC). It works pretty well, but I'd love to get the DMA working for outputting to my DAC (12-bit MCP4921)! I've had a read around at some older posts, but I can only really find one that refers to a DAC and DMA (linked below), as opposed to quite a few ADC and DMA. I'm building a little synth on the Blue Pill/STM32F103 (HID2.2 boot loader) with using Arduino IDE 1.8.13, on MacOS Mojave (10.14.6) and the stm32duino (STM Cores 1.9.0). The help I got last time has got me up and running!
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |