FAT SD Card Data Logger

An area to discuss 8-bit PIC specific problems and examples

Moderator: Benj

George_B
Posts: 128
Joined: Wed Jul 04, 2012 11:21 pm
Location: Greece
Has thanked: 51 times
Been thanked: 19 times
Contact:

FAT SD Card Data Logger

Post by George_B »

Hello !


I would like to use the SD componet. I read in the forum a few topics for reading from and writing to sd card and based on the examples i implement a data logger with gps data.

The simulator working good. The created file in the PC does contain the correct data as i want to be desplayed.

The problem i am facing is with real hardaware and the file which is created by the MCU.

Attached is the program i am using to make the logs onto the SD card every 5 secs.

As you can see the data seems to be corrupted in real tests.

Is it something i am doing wrong?

Thanks in advance!

Regards
George
Attachments
FAT_Data_Logger_Simple_Slow.fcfx
(27.26 KiB) Downloaded 205 times
log1(real Test with hardware).txt
(220 Bytes) Downloaded 217 times
log1(Created in Simulation).txt
(246.41 KiB) Downloaded 199 times

George_B
Posts: 128
Joined: Wed Jul 04, 2012 11:21 pm
Location: Greece
Has thanked: 51 times
Been thanked: 19 times
Contact:

Re: FAT SD Card Data Logger

Post by George_B »

I just figure out that the problem has to do with the string variable in the program.

The string "filestring" could not hold the sum of all other strings that i wanted.

I made a small change in the structure of the program and now i am able to write the way i want in SD.

Here is the solution for me.

It looks like the string variable could not hold more than 20 characters even if i tried to increase its array inside the brackets [].


Hope that helps and someone else having the same issue.


Happy Easter and my best wishes to you all.


George
Attachments
FAT_Data_Logger_Simple_Slow.fcfx
(32 KiB) Downloaded 199 times

George_B
Posts: 128
Joined: Wed Jul 04, 2012 11:21 pm
Location: Greece
Has thanked: 51 times
Been thanked: 19 times
Contact:

Re: FAT SD Card Data Logger

Post by George_B »

Hi,

For a project it is required to log GPS positioning data in an SD card every few seconds.
I have a few GPS modules available for testings but i get correct and valid position only with L76X module using U-center software.

Unfortunately i can not read the module's data when i try to write a simple program in flowcode 7 with GPS component.
It seems that the current component for GPS in flowcode can not identify the data inside the incoming string.


I captured a few lines of data from GPS module L76X to show you the format of the data that the mcu is receiving.
samle.txt
(118.26 KiB) Downloaded 215 times
hope someone can help with this one.

Regards
George

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT SD Card Data Logger

Post by Benj »

Hi George,

Please can you post your flowcode project file and I'll have a look at this for you. The gps output should be fairly standard but i will check the file you sent to make sure.

George_B
Posts: 128
Joined: Wed Jul 04, 2012 11:21 pm
Location: Greece
Has thanked: 51 times
Been thanked: 19 times
Contact:

Re: FAT SD Card Data Logger

Post by George_B »

Hello Ben

note that this program works with anothe gps module that i have which unfortunately gives me totaly wrong coordinates in relation to when i am at that point.

I couldn't read data from the L76X GPS module(which gives me correct data) using the attached program.

Can you check and let me know the reason i can not read the L76X GPS module with the current GPS component?

Regards
George
Attachments
L76X GPS output data.txt
(118.29 KiB) Downloaded 197 times
FAT_Data_Logger_Simple_Slow.fcfx
(28.92 KiB) Downloaded 199 times

George_B
Posts: 128
Joined: Wed Jul 04, 2012 11:21 pm
Location: Greece
Has thanked: 51 times
Been thanked: 19 times
Contact:

Re: FAT SD Card Data Logger

Post by George_B »

Hello,

still i am trying to find a solution for gps module L76X but no success with the flowcode.


Would it be possible to check the attached txt file and see the reason that the flowcode component can not get the right information ?


Thanks in advance
George

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT SD Card Data Logger

Post by Benj »

Hi George,

What speed is you crystal on your board? If this doesn't match the setting in the Flowcode project options then this could be the cause of the problem.

Does it ever start logging with the L76X, i.e. tell you the data is accurate?

George_B
Posts: 128
Joined: Wed Jul 04, 2012 11:21 pm
Location: Greece
Has thanked: 51 times
Been thanked: 19 times
Contact:

Re: FAT SD Card Data Logger

Post by George_B »

Hello Ben,

The crystal speed is configures correctly in flowcode at 19.6608MHz.

If i use a different GPS module from another manufacturer the same program works fine but then i have accuracy issues.

I would like to build a device that it will track a route and keep a log with the gps position every 5 seconds.

I have managed to write in SD card successfully but i am stuck on this one..

I hope you can give me a hand

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT SD Card Data Logger

Post by Benj »

Hello,

What are you using as your power source for the GPS? Could it be that the current is too low and this is causing your first module to give unreliable data and your second module not to boot up at all?

With projects like this I have used Li-ion and Lipo cells with a lot of success. I've also used a 9V PP3 battery and a switch mode power supply to drop the voltage and boost the current.

George_B
Posts: 128
Joined: Wed Jul 04, 2012 11:21 pm
Location: Greece
Has thanked: 51 times
Been thanked: 19 times
Contact:

Re: FAT SD Card Data Logger

Post by George_B »

Hi,


I am using two Li-ion 3.7V in series and a switching step down (3A maX) to power the hardaware.

Have you ever tried to read the L76X GPS module with the current flowcode GPS component?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT SD Card Data Logger

Post by Benj »

Hello,

I've found what might be causing the problem. The RMC message that contains the data validity flag is usually $GPRMC but in this case it is $GNRMC.

I've updated the component to allow for this and hopefully that should solve the problem for you. The other messages all seem to be ok so fingers crossed this allows the module to work.
GPS.fcpx
(160.94 KiB) Downloaded 172 times

George_B
Posts: 128
Joined: Wed Jul 04, 2012 11:21 pm
Location: Greece
Has thanked: 51 times
Been thanked: 19 times
Contact:

Re: FAT SD Card Data Logger

Post by George_B »

will let you know the results the soonest.


Finger crossed.



Many thanks!

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: FAT SD Card Data Logger

Post by AbhijitR »

Hello! George
good morning
George_B wrote:
Sat May 01, 2021 7:57 pm

Hope that helps and someone else having the same issue.
Indeed your post and example was very helpful to me, thank you for that.

Now i am facing one more problem, when i run the flow chart using 16MHz crystal then everything works fine as per your present chart, but in my application i need to use 16+PLL=64MHz so i could use the OLED display too.

May i request you and other friends who used 64MHz and FAT component together, how it is possible to manage the Initialization process below 400KHz as mentioned in the properties. May i request if someone could give a direction.

Thank you.

Abhi

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: FAT SD Card Data Logger

Post by AbhijitR »

Hello!

Any suggestions from the experts, team members regarding my previous post, or i am asking something wrong or not possible so i could think for another option.

Thank you.

Abhi

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT SD Card Data Logger

Post by Benj »

Hello Abhi,

Are you using v7 or v8? It should be possible to set the SPI prescaler so that the initial speed is less than 400KHz.

A PIC at 64MHZ will actually be running at an instruction rate of 16MHz. 16MHz / 1:64 Prescaler = 250KHz

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: FAT SD Card Data Logger

Post by AbhijitR »

Hello! Ben
good afternoon

Thanks to revert back.

I am using FC8, yes as you said i tried all the available options but without success, it only initialize at 16MHz without PLL, once i enable the PLL it stops responding or i can say the card writer do not initialize so nothing happens further.

Just imagine only to write the data in the card i need to think of using another PIC at 16MHz and to display (i am forced to use OLED) etc. another PIC running at 64MHz.

Do you really think there is no other option to initialize the FAT component running at 64MHz.

Abhi

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: FAT SD Card Data Logger

Post by AbhijitR »

Hello!

I want to update my recent progress on FAT component, i am able to initialize and run the component using 8MHz+PLL=32MHz, with Initial Prescaler=foc/64 (500KHz, little more then mentioned 400KHz) and High Speed Prescaler=foc/4

Is there any last hope to run the PIC micro at 16MHz+PLL=64MHz, because of only the FAT component i am not able to run the display and micro at 64MHz, some operations are getting slow and it really matters.

I wish if there is some process to initialize the FAT component at 64MHz it will be life saver.

Thank you.

Abhi

EDIT: 4th Oct 2021

Is it possible to add one more option in the Properties window of the FAT component at Initial Prescaler Fosc/128, i dont know if i ask logical question kindly excuse if i am wrong and this is not possible, but if possible then this will help to initialize the SD card using 64Mhz too, 64000Khz/128=500Khz. i was able to initialized the SD card at 500Khz using 32Mhz.

NOTE: correction 64000KHz, i wrote 64000MHz ( :roll: ) before in hurry.

Thank you.
Last edited by AbhijitR on Mon Oct 04, 2021 4:31 pm, edited 1 time in total.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT SD Card Data Logger

Post by Benj »

Hello Abhi,

What chip are you using, I think we expose the prescalers available on the chip but it could be we have missed a setting on the specific device you're using. I also wonder if it is possible to start at a slower speed, startup the SD card and then switch to a faster speed. Again knowing which device you're using will help here.

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: FAT SD Card Data Logger

Post by AbhijitR »

Hello! Ben
good afternoon

Thanks for your reply, i am using PIC18F46K22.

Oh! i never imagined that, about exposing the options of available prescalers on device/chip, if i have not mistaken i also tried using PIC18F26K22 and PIC18F26K42, but never saw any other option other then Fosc/4,16,64

Ben if you could add this (Fosc/128) option or something similar to reduce the speed for initialization it will be great.

Your last comment does that mean to start the chip at slower speed and then increase that after initializing the FAT component, but in that case user may insert the micro sd card any time while the chip is working, did i understand you correct or i am speaking...... :shock:

Thank you.

Abhi

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: FAT SD Card Data Logger

Post by AbhijitR »

Hello! Ben
Good morning

Any good news for me, waiting desperately for your answer.

Thank you.

Abhi

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT SD Card Data Logger

Post by Benj »

Hello Abhi,

The K22 device only has /4 /16 and /64 settings for the SPI I'm afraid so not a lot I can do there in terms of adding more prescaler settings.

However using the OSCCON and OSCCON2 registers it looks like you should be able to toggle the PLL functionality on and off to allow you to clock switch.

for example.

Code: Select all

OSCCON = 0x30;   //Set clock source to configuration settings @ 64MHz
and

Code: Select all

OSCCON = 0x7A;   //Set clock source to internal oscillator @ 16MHz
This will need testing, maybe with a one second flasher to make sure it's doing what you want. One second flasher should be 1s on and 1s off at 64MHz but 4s on and 4s off at 16MHz.

When there is no card present or the card hasn't been initialised then switch to the slower speed. If the card is present and initialised then switch to the faster speed.

If you configure the Flowcode clock for the faster speed then delays and bauds etc will be correct when running at the faster speed as this is likely where you will spend most of the useful time. If you need baud rates etc at the slow clock speed then there are ways to acheive this.

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: FAT SD Card Data Logger

Post by AbhijitR »

Hello! Ben
good morning

Yes, i anticipated that probability yesterday about the availability/unavailability of the prescaler, so i took a chance of trying your suggestion in your previous post
I also wonder if it is possible to start at a slower speed, startup the SD card and then switch to a faster speed.
I did exactly the same what you mentioned, i started the micro at 64Mhz on external crystal, and when i detect the presence of the micro SD card in the slot i run a macro in which i started with internal clock, completed the initialization and before exiting the macro again shift to external clock, i repeat the same when i write to the card as i noticed SD card do not except writing commands at 64Mhz/64.

And for my surprise this worked so well, but i don't know if this process i did is legitimate theoretically, practically it works, my concern is this arrangement should not create any problems in long run.

May i request you to share your opinion on what i did, is this correct in all respect, i have deleted the other part from the chart so excuse the placements of the characters on the display, also can you please check the settings in project options, i know i am asking more but it will be good to get experts opinion.

Thank you.

Abhi
Attachments
Ben_SDCard_06-10-2021.fcfx
(35.88 KiB) Downloaded 113 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT SD Card Data Logger

Post by Benj »

Hi Abhi,

What you have looks great and if it's working then I don't see any problems. Did you confirm the clock speeds with a flasher just to triple check the speeds are correct.

Here is a simplified version that would allow you to unplug and replug a card during the main loop without having to reset.
Ben_SDCard_06-10-2021.fcfx
(37.58 KiB) Downloaded 129 times

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: FAT SD Card Data Logger

Post by AbhijitR »

Hello! Ben
good morning

Many many thanks for checking and the new suggestions, i implement the new changes now in my chart.

Yes i have checked the difference between both the speeds, program works at a high speed once it leaves the macro i.e the C calculation box from Check_SDCard_Status.

Thank you once again.

Abhi

George_B
Posts: 128
Joined: Wed Jul 04, 2012 11:21 pm
Location: Greece
Has thanked: 51 times
Been thanked: 19 times
Contact:

Re: FAT SD Card Data Logger

Post by George_B »

Benj wrote:
Thu Jun 17, 2021 11:44 am
Hello,

I've found what might be causing the problem. The RMC message that contains the data validity flag is usually $GPRMC but in this case it is $GNRMC.

I've updated the component to allow for this and hopefully that should solve the problem for you. The other messages all seem to be ok so fingers crossed this allows the module to work.

GPS.fcpx
Hi,

I am still trying to run this project with no big success.

The given component is not working with the GPS module L76X. However, since i know where the information of the position(lon & lat) is inside the incoming packets of the GPS serial output, i was trying to implement a custom routine to read this line:

$GNGLL,4057.5749,N,02432.5390,E,104911.000,A,D*4F

The problem i am facing is that the packet comes fast and i can not catch the data i need from the whole data packet.

The attached program is one of my considerations in order to catch the line above and get the position information i need.

If i change the NumBytes from 28 to 10 , the program can read the first 10 bytes of the line. When i try 28 bytes it can not catch the data.

Any ideas? is it timing/speed issues?


Thanks in advance

George
Attachments
tst_F4523_LCD_GPS.fcfx
(26.31 KiB) Downloaded 103 times
samle (1).txt
(118.26 KiB) Downloaded 114 times

Post Reply