cancel
Showing results for 
Search instead for 
Did you mean: 

HOW TO SAVE ADC RESULTS?

MSimo
Associate II

Hi everyone, I am new to the community and I am also not very expert on microcontrollers. I own a STM32F407G-DISC1. I was able to write the code for ADC (at least I think), but I don't know how to save the data on the memory. Can anyone tell me how to do it.

attached you can find the code I'm using

Thanks a lot.

7 REPLIES 7
Ozone
Lead

Depends on what you mean with "saving to memory".

The ADC data already end up in the RAM of the MCU.

If you need them only for debugging, try semi-hosting to get them to your PC via debugger.

Or push them out via UART (RS232) or USB.

For permanent storage, you can add a SD card/interface to your discovery board, and use FatFS to store the values there.

And is there a method to copy the results from RAM to a text file for example?

The input signal is a sinusoid and in the debug mode I use the "function editor", so that I can see the results on the "command window" as the sine wave advances. But with this method the ADC seems quite slow. (100Hz signal)

Ozone
Lead

> And is there a method to copy the results from RAM to a text file for example?

Sure you could do.

You can collect a number of samples in RAM, and write them to a PC via semihosting. This assumes you need those values only in the debug phase.

Actual implementation/code depends on your requirements, and your toolchain.

I don't use / work with Cube code, though.

> ... in the debug mode I use the "function editor", so that I can see the results on the "command window" as the sine wave advances. But with this method the ADC seems quite slow. (100Hz signal)

Not sure what you describing here, and what your environment is.

But any way of saving this ADC data will have an impact on application timing. Saving collected data concurrently in realtime makes an application more complex.

This might be a bit over the head for a beginner.

Start simple, and do small steps.

But is there any way to write the result of my conversion on the flash memory?

example: my ADC has 10 channels.

         -1 conversion -> 1 memory cell

         -2 conversion -> 2 memory cell

                      .

                      .

                      .

        -1 conversion again -> 11 memory cell.

Is such a thing possible?

In RAM I understand that data is overwritten every time it is converted (or is it wrong?)

Writing to Flash would be possible, yes.

Problems associated with Flash are:

- only page-wise erase possible (check for page sizes, usually 64 kbyte)

- writing (AFAIK) only in 32 bit words

- word write takes millisecond, during which code execution stalls

- limited durability (10k erase/program cycles guaranteed)

- values in Flash are as invisible to the outside as in RAM

Milliseconds, woow !! Too slow.

At this point I do as you suggested before, or take a number of samples from the RAM and write them later on the PC. I thank you for your help and excuse my ignorance hahah

> ... and excuse my ignorance hahah

Learning is a process, and embedded SW is a complex field.

You can search for example applications with similar tasks/requirements, and examine the source code, how they do it.

Could be STM32, or another Cortex M family, or even a different architecture. Learning never stops.