cancel
Showing results for 
Search instead for 
Did you mean: 

continous conversion of ADC and storing the data in memory card

Apill
Senior

Hi,

I am trying to store the converted data from ADC to memory card. as of now i can able to store the data and read the values of adc but when i tried to store the values of adc in memory card i could not able to do. i have used the below code.

I have mounted and declared objects related to sd card(FATFS) globally.

By using the below code i could only able to save the last value of adc but i would like to store every value of adc that has been converted since beginning to end ( till i stop).

I presumed as i have declared adc in interrupt mode after every conversion of adc it comes to the below function9cnvcpltcallback) so i have added lines related to sd card. right now, i would like to konw how can i continously store the values of adc pin in sd card.

Please let me know.

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

{

 /* Prevent unused argument(s) compilation warning */

 UNUSED(hadc);

unsigned int temp=0; 

adcval= HAL_ADC_GetValue(&hadc1);

 /* NOTE : This function Should not be modified, when the callback is needed,

      the HAL_ADC_ConvCpltCallback could be implemented in the user file

  */

temp = adcval; 

f_open(&myFILE, "Write1.TXT\0", FA_WRITE | FA_CREATE_ALWAYS);

f_printf(&myFILE, "%d\r\n",temp);

f_close(&myFILE); 

}

-

Thanks,

Ashok

1 ACCEPTED SOLUTION

Accepted Solutions
AvaTar
Lead

Using a text format, i.e. a literal number strings instead of binaries, will make the evaluation much easier.

If you are concerned about throughput, don't write each value individually, rather collect and write blocks.

FATFS access in an interrupt context will break your application.

View solution in original post

4 REPLIES 4
AvaTar
Lead

Using a text format, i.e. a literal number strings instead of binaries, will make the evaluation much easier.

If you are concerned about throughput, don't write each value individually, rather collect and write blocks.

FATFS access in an interrupt context will break your application.

For speed and efficiency you'd want to write 16 KB or 32 KB blocks.​ Do it in a foreground task.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Apill
Senior

@Community member​  you mean i shouldnt use interrupts interfacing with FATFS ? could you please elaborate your last sentence.

AvaTar
Lead

No, I mean you should call lengthy code like FATF calls from within interrupts.

This will block other interrupts, or follow-ups.

A SD card is an opaque unit. If a simple write happens to involve a block erase, it could take several milliseconds.