Problems w. division - unsigned long

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
Cyberzim
Posts: 104
Joined: 12 Jun 2008 00:09
Location: Denmark

Problems w. division - unsigned long

#1 Post by Cyberzim » 24 Jun 2010 03:15

Hi,
I have a code for a time bar for my mp3-player used on a QVGA color touch screen.
My problem is, when I do the calculation to determine how long I'm in the song, it wont give me any number but 0.
Every variable here is a unsigned long.
I have tested the code, and after I divide 'percent' with 'startsize' I get this bug.
I init the mmc with 'startsize' and transfer the number to 'filesize' afterwards.

Code: Select all

unsigned long percent;

percent = startsize-filesize;
percent *= 2; // Works fine, providing number larger than 0
percent = percent/(startsize/100); // does not work. Only result is zero, no matter for how long time the song is playing.
.....more code.....


And by the way, I have splitted my project in more files so filesize is in another file which is included in the main file. Shouldn't have any affect on the code.

Regards,

Simon H.A.
Name: Simon H.A.
Age: 17

User avatar
slavisa.zlatanovic
mikroElektronika team
Posts: 1321
Joined: 07 Apr 2009 09:39

Re: Problems w. division - unsigned long

#2 Post by slavisa.zlatanovic » 24 Jun 2010 12:45

Hi!

I couldn't reproduce the issue you're talking about.
Can you give me a number combination (startsize, filesize) using which when calculated manually
the percent value differs from the value given by compiler in the simulator.

Best regards
Slavisa
Best regards
Slavisa

Cyberzim
Posts: 104
Joined: 12 Jun 2008 00:09
Location: Denmark

Re: Problems w. division - unsigned long

#3 Post by Cyberzim » 15 Jul 2010 01:01

Hi Slaviza,
Haven't been able to answer for some time due to Roskilde festival and glandular fever.

I use a number generated from the mmc_fat_reset function. In my testrun, the song had a filesize of 13MB. I'm using 'filesize' with the mmc_fat_reset and then copies the number to startsize so I have a number to calculate the percentage.d
I have discovered more problems with my code. I can't make it stop when the song is finished. I have tried many methos for example checking if 'filesize' is larger or equal to 32 and then return 1 if not. The function won't return 1 at any time.
I can't figure out what I'm doing wrong, if I am doing something wrong.

Regards,

Simon H.A.
Name: Simon H.A.
Age: 17

User avatar
slavisa.zlatanovic
mikroElektronika team
Posts: 1321
Joined: 07 Apr 2009 09:39

Re: Problems w. division - unsigned long

#4 Post by slavisa.zlatanovic » 15 Jul 2010 14:05

Hi!
...I use a number generated from the mmc_fat_reset function...
Use function Mmc_Fat_Get_File_Size() to retrieve the size of active file (in bytes).

It would be best that you create a minimal project that depicts the problem you're experiencing.
I must reproduce it and only then I will be able to help you.
You can send your project to my e-mail:
slavisa.zlatanovic@mikroe.com

Best regards
Slavisa
Best regards
Slavisa

Cyberzim
Posts: 104
Joined: 12 Jun 2008 00:09
Location: Denmark

Re: Problems w. division - unsigned long

#5 Post by Cyberzim » 15 Jul 2010 15:09

Awesome!
That solved all my problems I had.

Thank you,

Simon H.A.
Name: Simon H.A.
Age: 17

Post Reply

Return to “mikroC PRO for PIC General”