DmaDac:

 

    This 12-Bit  Dual Output Dma powered Timer cotrolled Waveform Generator program ( TCWG ) is the long promised Dma variant of the already published

 

Mini-DDS pure Software version. As an AVR assembler disciple, It took me quite a while to come to terms with the whole notion of understanding how the seemingly 

 

complex ARM Stm32 F4 Dma Direct Memory Access peripheral actually works. First things first, hats off to Denis, whose well worked examples of Stm32 F1Dma apps

 

helped me to grasp some of the basics of what lies behind their practical use :-) And a further acknowledgement to Denis ; thanks for this short Basicprogram here, 

 

which can be used to pre-calculate the SineWave values for the 12-Bit Lookup table: The SineWave values are then moved from Flash into Ram whenever a Sinewave 

 

must be output. The TCWG uses the basic programmable timer, (Timer_6),  to trigger the Dac1, which in turn "clocks" the 256 * 32-Bit Ram array and sends the contents

 

out to the Dac. So the Cpu must only correctly initialise the needed peripherals and then finally enable the Dma and that's that! The Cpu then goes to sleep until it's 

 

awoken from its slumber by the next keypress of the onboard Blue-button. What an amazing thing the Stm32 Dma is and what a difference it makes in comparison to

 

the good ol AVR, where almost everything had to be done in software :-( To further reduce power consumption in Sleep mode the peripheral clocks can also be 

 

disabled just prior to executing the WFI instruction.  

 

    For N = 0 to 255

 

        S= Abs ( 2048 + ( 2047 * ( Sin ( N * Pi * 2 / 256 ) ) ) )

 

        Print S

 

        Next N  ]


    The other waveforms are, so to say, calculated on the fly and are also stored into Ram, The Dma1 then fetches the stored data array in Ram @ 0x20000000 and 

 

dumps the 32-bit values into the Dac peripheral register @ DAC_DHR12RD. Timer_6 is used to trigger the Dma and consulting the Dma request map, we can see that 

 

Dac1 is connected to the Dma using Channel_7 and Stream_5. All very straight forward and logical, but it took me ages to wade through all the documentation in 

 

order to make sense of things. Patience and the grace and favour of the Gods are what's needed when working with the Stm F4 and sometimes an awful lot of luck!

 

 

     SquareWave  @ 41,016Hz


    Triangle Wave @ 41,016 Hz
    Sawtooth Wave @ 41,016 Hz
    Sine Wave @ 41,016 Hz
    Some Waveform Parameters of the above signals
     
    Operating the device is really quiet simple. On power up the default Green led lights up and we can see a nice Sinewave on the scope. Depress and release the 
User-push button once and we can now see the Orange led coming on and the waveform changes to a SawToothWave. Hit the button again, and this time we can 
observe both the Red led and a TriangleWave to boot. With the next button sequence it's a Blue led in conjunction with a SquareWave. And the whole process loops 
back again to Green / SineWave with the next button operation!  The formula for calculating the Dma Update Event frequency is given in the Stm 
AN4013 Application 
note, where on page 7 it reads as follows .....[ Dma Update Event APB1 Clock / ( ( ( PreScaler + 1 ) * ( AutoReload + 1 ) ) * Counter ) ]. The Maximum allowed 
frequency of the low-speed APB1 domain is 42 Mhz. I've found out through a wee bit of empirical research, that the formula was not giving the correct values, 
when measured with an accurate digital frequency meter, so I lashed together a simple DmaDac.exe gui program to do the boring calculations for us :-) One simply 
enters the desired frequency between 2.504 and 41,016 Hz in decimal and the required Auto-Reload value is output in hexadecimal format. As always it's the case, that 
garbage in garbage out remains the watchword ;-) This small program is to be found in the dowloaded Zip file.

         Enter  Frequency                                                Valid Result

 

                                 

    " Supposin, supposin three men were frozen. Two died. How many were left ? "  Anonymous.

    Download