CMSIS libraries example to DAC output of NUCLEO boards (that have them e.g F429ZI) to an Oscilloscope to display frequency domain bins
Revision 0:05e2c9ca68e2, committed 2018-04-13
- Comitter:
- martinsimpson
- Date:
- Fri Apr 13 08:59:47 2018 +0000
- Commit message:
- 1st Commit; FFT using CMSIS libraries to generate a DAC output to a front end of a basic Oscilloscope to obseverve a FFT scan with bins (see code for resolution)
Changed in this revision
diff -r 000000000000 -r 05e2c9ca68e2 .gitignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Fri Apr 13 08:59:47 2018 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
diff -r 000000000000 -r 05e2c9ca68e2 README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Fri Apr 13 08:59:47 2018 +0000 @@ -0,0 +1,87 @@ +# Getting started with Blinky on mbed OS + +This guide reviews the steps required to get Blinky working on an mbed OS platform. + +Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). + +## Import the example application + +From the command-line, import the example: + +``` +mbed import mbed-os-example-blinky +cd mbed-os-example-blinky +``` + +### Now compile + +Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5: + +``` +mbed compile -m K64F -t ARM +``` + +Your PC may take a few minutes to compile your code. At the end, you see the following result: + +``` +[snip] ++----------------------------+-------+-------+------+ +| Module | .text | .data | .bss | ++----------------------------+-------+-------+------+ +| Misc | 13939 | 24 | 1372 | +| core/hal | 16993 | 96 | 296 | +| core/rtos | 7384 | 92 | 4204 | +| features/FEATURE_IPV4 | 80 | 0 | 176 | +| frameworks/greentea-client | 1830 | 60 | 44 | +| frameworks/utest | 2392 | 512 | 292 | +| Subtotals | 42618 | 784 | 6384 | ++----------------------------+-------+-------+------+ +Allocated Heap: unknown +Allocated Stack: unknown +Total Static RAM memory (data + bss): 7168 bytes +Total RAM memory (data + bss + heap + stack): 7168 bytes +Total Flash memory (text + data + misc): 43402 bytes +Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin +``` + +### Program your board + +1. Connect your mbed device to the computer over USB. +1. Copy the binary file to the mbed device. +1. Press the reset button to start the program. + +The LED on your platform turns on and off. + +## Export the project to Keil MDK, and debug your application + +From the command-line, run the following command: + +``` +mbed export -m K64F -i uvision +``` + +To debug the application: + +1. Start uVision. +1. Import the uVision project generated earlier. +1. Compile your application, and generate an `.axf` file. +1. Make sure uVision is configured to debug over CMSIS-DAP (From the Project menu > Options for Target '...' > Debug tab > Use CMSIS-DAP Debugger). +1. Set breakpoints, and start a debug session. + +![Image of uVision](img/uvision.png) + +## Troubleshooting + +1. Make sure `mbed-cli` is working correctly and its version is `>1.0.0` + + ``` + mbed --version + ``` + + If not, you can update it: + + ``` + pip install mbed-cli --upgrade + ``` + +2. If using Keil MDK, make sure you have a license installed. [MDK-Lite](http://www.keil.com/arm/mdk.asp) has a 32 KB restriction on code size. \ No newline at end of file
diff -r 000000000000 -r 05e2c9ca68e2 img/uvision.png Binary file img/uvision.png has changed
diff -r 000000000000 -r 05e2c9ca68e2 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Apr 13 08:59:47 2018 +0000 @@ -0,0 +1,73 @@ +#include "mbed.h" +/* Include arm_math.h mathematic functions */ +#include "arm_math.h" +/* Include mbed-dsp libraries */ +#include "arm_common_tables.h" +#include "arm_const_structs.h" +#include "math_helper.h" + +/* FFT settings */ +#define SAMPLES 512 /* 256 real party and 256 imaginary parts */ +#define FFT_SIZE SAMPLES / 2 /* FFT size is always the same size as we have samples, so 256 in our case */ + +/* Global variables */ +float32_t Input[SAMPLES]; +float32_t Output[FFT_SIZE]; +bool trig=0; +/* MBED class APIs */ +DigitalOut myled(LED1); +AnalogIn myADC(A1); +AnalogOut myDAC(D13); +Serial pc(USBTX, USBRX); +Ticker timer; + +void sample(){ + trig=1; + } + +int main() { + + //arm_cfft_instance_f32 S; // ARM CFFT module + float maxValue; // Max FFT value is stored here + uint32_t maxIndex; // Index in Output array where max value is + bool once=0; + pc.baud(115200); + pc.printf("Starting FFT\r\n"); + while(1) { + timer.attach_us(&sample,20); //20us 50KHz sampling rate + for (int i = 0; i < SAMPLES; i += 2) { + while (trig==0){} + trig=0; + Input[i] = myADC.read() - 0.5f; //Real part NB removing DC offset + Input[i + 1] = 0; //Imaginary Part set to zero + } + timer.detach(); + // Init the Complex FFT module, intFlag = 0, doBitReverse = 1 + //NB using predefined arm_cfft_sR_f32_lenXXX, in this case XXX is 256 + arm_cfft_f32(&arm_cfft_sR_f32_len256, Input, 0, 1); + + // Complex Magniture Module put results into Output(Half size of the Input) + arm_cmplx_mag_f32(Input, Output, FFT_SIZE); + + //Calculates maxValue and returns corresponding value + arm_max_f32(Output, FFT_SIZE, &maxValue, &maxIndex); + + if (once==0){ + pc.printf("Maximum is %f\r\n",maxValue); + once = 1; + } + + //maxValue /= 100.0f; + + myDAC=1.0f; //SYNC Pulse to DAC Output + wait_us(20); //Used on Oscilliscope set trigger level to the highest + myDAC=0.0f; //point on this pulse (all FFT data will be scaled + //90% of Max Value + + for (int i=0; i<FFT_SIZE/2 ; i++){ + myDAC=(Output[i]/maxValue)*0.9f; // Scale to Max Value and scale to 90% + wait_us(10); //Each pulse of 10us is 50KHz/256 = 195Hz resolution + } + myDAC=0.0f; + } +} \ No newline at end of file
diff -r 000000000000 -r 05e2c9ca68e2 mbed-dsp.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-dsp.lib Fri Apr 13 08:59:47 2018 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/mbed_official/code/mbed-dsp/#3762170b6d4d
diff -r 000000000000 -r 05e2c9ca68e2 mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Fri Apr 13 08:59:47 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#5f6572179d66ce4c09d6517b659ac51133cc980d