Report
5 days, 22 hours ago.

DMA using

How can I implement DMA for generating 100kHz sine via DAC?

My board is nucleo STM32 L476RG

Comment on this question

1 Answer

16 hours, 27 minutes ago.

Hello Igor,

You can't implement a DMA on the nucleo STM32 L476RG because the board does not support DMA. You still, however, able to generate a 100kHz sine via the DAC.

Here is an example code

100Khz sine output

#include "mbed.h"

// DAC 100khz
#define DAC_Frequency 100000

AnalogOut dac(PA_4);

DigitalIn btn(USER_BUTTON);

Timer tim;
Ticker tic;

//sine table for a 12bit day
static volatile uint16_t sinetable[] = {
   2047,    2147,    2248,    2348,    2447,    2545,    2642,    2737,
   2831,    2923,    3012,    3100,    3185,    3267,    3346,    3422,
   3495,    3564,    3630,    3692,    3750,    3804,    3853,    3898,
   3939,    3975,    4007,    4034,    4056,    4073,    4085,    4093,
   4095,    4093,    4085,    4073,    4056,    4034,    4007,    3975,
   3939,    3898,    3853,    3804,    3750,    3692,    3630,    3564,
   3495,    3422,    3346,    3267,    3185,    3100,    3012,    2923,
   2831,    2737,    2642,    2545,    2447,    2348,    2248,    2147,
   2047,    1948,    1847,    1747,    1648,    1550,    1453,    1358,
   1264,    1172,    1083,     995,     910,     828,     749,     673,
    600,     531,     465,     403,     345,     291,     242,     197,
    156,     120,      88,      61,      39,      22,      10,       2,
      0,       2,      10,      22,      39,      61,      88,     120,
    156,     197,     242,     291,     345,     403,     465,     531,
    600,     673,     749,     828,     910,     995,    1083,    1172,
   1264,    1358,    1453,    1550,    1648,    1747,    1847,    1948,
};

 int sel = 0;
 
void DAC_Int(void)
{
    
    // Sine wave
    dac = sinetable[sel];
    sel = (sel+1)%(sizeof(sinetable)/sizeof(sinetable[0]));
}

int main()
{
   

    tim.start();

    tic.attach_us(&DAC_Int, 1000000 / DAC_Frequency);

    while(1)
    {
    }
}

Please let me know if you have any questions!

- Peter, team Mbed

If this solved your question, please make sure to click the "Thanks" link below!


To post an answer, please log in.