ADDS Porting for STM32F4-Discovery

Introduction

The STM32F4-Discovery is, imho, one of best developing board with an exellent quality/price ratio. Then I wanted port my old ADDS designed in VHDL for Atlys board for the ARM equiped on STM32F4.

The line-guides are the same for the old project and (obviously) you can find mome details in the description of VHDL version...

Anyway the system work properly, it generate a sine wave (mapped in a LUT) and change the tone frequency under proper USB commands.

The usual problem is that STM32F4, like ATLYS, have an audio DAC. Therefore the max frequency that we can produce is in the audio range.... for RF freenquency we have to change the DAC and use a proper one.

Description

How to use DDS (Digital Direct Synthesis) for generate an arbitrary waveform is not a mystery. We can storage the samples in a LUT and then read them at the right moment for generate a waveform of needed frequency. For change the output frequency we can simply change the rate in which we read from LUT.

 

In the STM32F4xx we have a several modules useful for implement the tecnique summarized above. We can use for example the large memory for store the LUT, the advanced 32bits Timers in several ways (like PWM.. great idea if you want use an external Filter to recostruct the signals) and an audio codec (CS4342) if you want work in audio frequencies band.

 

For this (initial) release I choised to work in audio band... therefore I used the CS4342 instead that an external DAC or a singe pole LP-filter.

While I used the on board codec, I choise to use the Timer (TMR2) in Up Counting mode with interrupts. The timer interrupt implement the needed steps to obtain the samples from LUT in the fullness of time. The fullness of time is the time required from timer for complete the UpCounting.

I know what's your question.... But how long I have to count ... and at which frequency?

The problem, how I hint at ADDS VHDL version, is that the resolution of the DCO is related to the parameters above.

The main formula to find the right offset is:

offset=2*pi*(fo/fs)=2^32*(fo/fs).

Therefore if for example we want obtain a 440Hz waveform and we set our ARM to work at 168MHz and his TMR to count to 100KHz we can use the next formula: offset=2^32*(440/100000)=18897856 (rounded actually).

Each interrupt the Interrupt Handler set a new value of a phase accumulator (like in ADDS vhdl) and a shift of 22 position is needed to match the number of samples that I stored in the LUT.

 

The approach summurized above produced good results in all audio-band. The system is affected by armonic noise at hi-frequency (near 20kHz).

But a FIR can resolve this ... I suppose.

 

Another great features that I implemented in this release is that the frequency can be set by a serial terminal (like minicom) and an USB-USART traslator. For send commands to the device we must send a string in which an header and a footer guard against the corruption of bad commands transmission and the remained string content is the frequency in Hz.

Photos

System
System
STM32F4-Discovery
STM32F4-Discovery
20Hz
20Hz
44Hz
44Hz
100Hz
100Hz
440Hz
440Hz
960Hz
960Hz
4.4kHz
4.4kHz
9.6kHz
9.6kHz
15.678kHz
15.678kHz
Terminal view
Terminal view

In the videos above, I show the presented ADDS with a new feature that I implemented last night: a rudimental AM-Modulator. In the second one I change several time (via USB Terminal) the carrier frequency (sorry for low quality of the second one but I'm wrong something in the downgrade converting process from MTS to FLV.. when I have a minute I change it with a new one).

 

UPDATE 29/09/2013:

IN the last video instead I'm evaluating another (more simple DDS tecnique). The synthesis with timers, dma module and DAC improve the max frequency obtainable and lower the quantization noise. I noted a strange cutting effect ... I think that it's due to the way to obtain the value respect the reference voltage of DAC module... (the lazy don't pay.. :)).

Observations

The intersting tests shows that the armonic noise is present and it increase with the frequencies (start at 15kHz).

Another thing is that there is a spread-band noise (the woolly in all photos).

This noise decrese while we set a lower value of output attenuation (I find this very natural... :)). This fact is not relevant actually ...and we can reduce dastically this parrassitic effect lowering the attenuation of output analog channel... with 0dB attenuation the effect is negligible... In this situation the output level became very high... I suggest you don'y keep your hearphone in your ears... deaf hazard!!! and you risk of damage your hearphone.

Another aspect is that for test the effective resolution of the adds we have to use a more precise tool rather then the displayed index (in LCD of the oscilloscope). The "manual" period measure is more precise (measuring the number of divisions)... but require also more time... (1 hour... at least for all audio spectrum)... In this cases the use of a frequency-meter is a better idea.... an automatic measure system... an exellent idea.. :) ! 

The next release should provide an external DAC (suitable for RF) or the combination of a PWM with a LP-filter... Another intersting upgrade can be the use of DMA module for manage the samples and OTG module for drive the system with an USB rather then the USART port.

Thank for your attention.

26/09/2013

 

UPDATE 29/09/2013:

I done the new release that use DMA channels for manage the samples without CPU use, the DAC for improve the max frequency obtainable and a new (simpler) algorithm modify the waves frequencies.

The new algorithm consist to read ALL samples from memory (by DMA) but in fullness of time. The fullness of time is the time elapsed in which a timer count to a number that depend from a frequency needed (and asked) by user with a serial terminal connection (USB-USART).

With this new version the max frequency rised upto 80kHz (actually) with 128 samples in unsigned integers 16bit format. The DMA module permit to generate 2 waves in the same time, driven by the same control mechanism. Therefore I've generated 4 channels: Sine, Saw, Triangular, Noise.

The third video show how this version act.