I'm trying to play a note through the speaker of my board. Currently, I have an interrupt as follows:
void sampleISR(void) {
static uint32_t phaseAcc = 0;
phaseAcc += a; //this `a` is modified outside
analogWrite(OUTR_PIN, phaseAcc);
}
It is attached in the setup()
function as follows:
TIM_TypeDef *Instance = TIM1;
HardwareTimer *sampleTimer = new HardwareTimer(Instance);
sampleTimer->setOverflow(22000, HERTZ_FORMAT);
sampleTimer->attachInterrupt(sampleISR);
sampleTimer->resume();
I am trying to use a DMA to reduce the strain on my CPU and also increase the sampling rate (making the 22000 bigger). I am trying to use this as my board supports it, however, I am conceptually confused as to what the transformation entails. Currently, I have an interrupt which modifies the analogWrite
value to pin OUTR_PIN
every 22000 samples. My current understanding is that a DMA is a tool that connects memory to peripherals or memory to memory, in such a way that data can be transferred without the need for the CPU to do it. However, I am uncertain as to what that means in the current context. Would I need to create a memory-to-periphery DMA where the source is memory (my phaseAcc
variable and the output is a periphery (my OUTR_PIN
?). I am not sure how I would go around doing this, or if what I described above is correct. I am trying to directly mimic the functionality described above.
I am using a board from the stm32 family.