Datalogger printf/ timer
응답
18. 6. 5 오전 10:44

Hi all,

Regarding the Datalogger demo, I want to prinf to display my value & strings on the console but unfortunately it will only print the init setting when I have tried added, edited and deleted it from my workbench.

What could be the problem here and how do I print my values out?

Secondly, I have issue with the Sampling Rate after I have added in acoustic sensor in to my datalogger project. It will always sample at 4ms when I have change the log config.

Where can I hardcode/ do the configuration so that I can log the data for every sec?

Do I need to create a seperate time task to sample 50 data sample in a second or can I just read it 50 times during the 1 second sample time in my datalogger project?

Thank you,

K Ming

0 (0 투표)
RE: Datalogger printf/ timer
응답
18. 6. 5 오후 1:47 as a reply to K Ming L.
Hello K Ming L,

I see four possible reasons as to why the printf changes for printing are not working:
 
  • The printf strings do not end with "\n", hence the print buffer is never flushed (and therefore, the messages are not sent via USB yet)
  • You are not saving the file after making changes, hence the old version of the code is used instead. The Workbench does not detect file changes until a file is saved.
  • You press the Flash button, but the project is not recompiled. Sometimes, compilation is not triggered upon trying to Flash, and compilation must be done manually. For this, right-click the project and select "Build"
  • An incorrect project is flashed. To flash the correct project, make sure that a file from within the correct project is selected in the Project Explorer (left-click the Main.c of your project, for example)


If none of these reasons apply to your case, I would kindly ask you to make a screenshot of the XDK-Workbench, with some of the printf statements that you have added. Please make sure that the essential parts are visible and not blocked by any popups (i.e. the project in Project Explorer, the editor, and the added/modified lines of code).

Regarding your other issue about the implementation of the acoustic sensor in the Data Logger demo, could you please provide some sample code about how you implemented the functionality of the acoustic sensor? Otherwise, I am only able to make guesses as to why you are unable to configure a sampling rate of one second. In any case, keep in mind that depending on which/how many sensors are used, the minimal sampling rate of the entire application will increase.

Regarding your last question, I assume you want to calculate the root mean square value of the sensor values of the acoustic sensor. For that, I would recommend to create an additional task, which makies 50 samples per second second and then use those samples to calculate the root mean square value.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Alex
0 (0 투표)
RE: Datalogger printf/ timer
응답
18. 6. 7 오전 10:34 as a reply to Alexander Sawtschuk.

Hello,

I have solve the first issue already. Thank you.

Regarding the second issue, i have follow the basic implementation of the acoustic sensor from this post https://xdk.bosch-connectivity.com/community/-/message_boards/message/300506#_19_message_324127

I believe that because from the above implementation the sensor wasn't configured hence it runs at the fastest speed which overwrites the configuration from logger.ini of the other sensors.

What is the reason behind creating a task? How about timer or just go through a for loop?

 

0 (0 투표)
RE: Datalogger printf/ timer
응답
18. 6. 7 오후 1:35 as a reply to K Ming L.
Hello K Ming L,

could you please clarify your exact use case, since I seem to be misunderstanding something.

Do you want to store the data of every sensor, including the acoustic sensor, once every second? Or is there more to your use case than that?

In the first case, you may want to take a look at my answer in another thread , where I explain how to configure the timers.

If you want to create 50 samples of the acoustic sensor (and only the acoustic sensor) within one second, you will need an additional task, because otherwise all other tasks may be blocked during sampling, which can result in unexpected behavior.

In any case, before I can give more suitable advice, I would need to know what exactly your intention is.

Kind regards,
Alex
0 (0 투표)
RE: Datalogger printf/ timer
응답
18. 6. 8 오전 4:00 as a reply to Alexander Sawtschuk.

Hi Alex,

I want to collect all sensors data including acoustic data at 1 second. But the acoustic sensor data reading woudn't be accurate if I sample it at 1 second. Hence, I would like to get the RMS OF 50 readings and store that RMS value in to my SD card.

After reading the FreeRTOS task guide at 2.3, I'm not entirely sure how does a task flow works in my program.

Could you share with me how does a new task normally flows?

Thanks,

Kuan Ming

 

 

 

0 (0 투표)
RE: Datalogger printf/ timer
응답
18. 6. 8 오전 7:57 as a reply to K Ming L.
Hello K Ming L,

Tasks are what one would refer to as a Process or Thread when coming from other Operating Systems.

Multiple tasks can run in parallel in an interveawing fashion, and the FreeRTOS scheduler determines which task receives computation time on the MCU's processor next.

Most applications require only one task, but for example the Datalogger already requires at least two tasks. One for reading the sensor data, and one for writing it to the SD Card. This is necessary because otherwise the functionality for writing would severely block out the functionality for reading. Writing is usually more expensive in regards to time than reading is.

And as such, if you were to further extend one of these tasks by adding the 50 samples of the acoustic sensor, the timing of the other tasks may be affected in unexpected ways.

I would therefore recommend to add a task to your application, that simply stores a sample of the acoustic sensor in a Ring Buffer every 20 milliseconds. For this, you can add a function such as the following to the Acoustic Sensor interface you took from Ronald Tan's post:

 
 uint32_t samples[50] = { 0 };
uint8_t index = 0;
void aku_340_sample(void) {
    samples[index] = BSP_Mic_AKU340_Sense();
    index += 1;
    index %= 50;
} 


And then modify aku_340_getData() to calculate the RMS of all 50 values inside that array.

Keep in mind that if a task runs on the processor, it will occupy at least one FreeRTOS tick, even if it does not require the entire tick to finish computation before going into a blocked state.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Alex
0 (0 투표)