problems about operations between vars in ram & rom

Discuss about beta versions of mikroC compiler.
Post Reply
Author
Message
CGEngineering
Posts: 144
Joined: 09 May 2007 23:31
Location: Florence - Italy
Contact:

problems about operations between vars in ram & rom

#1 Post by CGEngineering » 06 Nov 2007 12:21

Hi everyone,

today i encountered a problem, solved by a workaround, but a little annoying:

I have :

Code: Select all

unsigned int  iV;
const float g_fTCGain[] = {......};
iV = 20 and g_fTCGain[0] = 1.0

but if i do

Code: Select all

(float)iV * g_fTCGain[0]
it returns a 0 (instead of 20.0), even with the explicit cast (i think it won't be useful there)...

Instead, if i do:

Code: Select all

float V;
float G;
float GV;
V = (float)iV;
G = g_fTCGain[0];
GV = G * V;
it works correctly, so i think that there are problems accessing to a ROM constant inside a (little) complex operation.

I am running mikroC 7.0.0.3 and programming a PIC18F8722

Regards
CG

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

Re: problems about operations between vars in ram & rom

#2 Post by srdjan » 06 Nov 2007 15:02

Hi,
I could not reproduce the problem you are talking about. Could you send me a small sample code which will demonstrate this to srdjan@mikroe.com or post the same.

CGEngineering
Posts: 144
Joined: 09 May 2007 23:31
Location: Florence - Italy
Contact:

Re: problems about operations between vars in ram & rom

#3 Post by CGEngineering » 06 Nov 2007 16:30

srdjan wrote:Hi,
I could not reproduce the problem you are talking about. Could you send me a small sample code which will demonstrate this to srdjan@mikroe.com or post the same.
Hi Srdjan,
that's a code that reproduces the problem presented above:

Code: Select all

const float g_fTCGain[8] = {1.0, 0.91, 0.905, 1.0, 1.0, 1.0, 1.0, 1.0};

void Test(unsigned int iVoltage){
  printf("test: %f \r\n", (float)iVoltage * g_fTCGain[0]]);
}

void main(){
    Test(20);
)

This prints 0.0000 instead of 20.0000.

Regards
CG

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

Re: problems about operations between vars in ram & rom

#4 Post by srdjan » 06 Nov 2007 17:01

Hi,
I do not have printf routine on my side. I have used our sprintf instead and it works. Could it be the problem in you printf routine? Could you try this code?

Code: Select all

const float g_fTCGain[8] = {1.0, 0.91, 0.905, 1.0, 1.0, 1.0, 1.0, 1.0};

char buffer[20];
void Test(unsigned int iVoltage){
  sprintf(buffer, "test: %f \r\n", (float)iVoltage * g_fTCGain[0]);
}

void main(){
    Test(20);
}
Its for pic18 family (pic16 does not have sprintf).

CGEngineering
Posts: 144
Joined: 09 May 2007 23:31
Location: Florence - Italy
Contact:

Re: problems about operations between vars in ram & rom

#5 Post by CGEngineering » 06 Nov 2007 18:30

srdjan wrote:Hi,
I do not have printf routine on my side. I have used our sprintf instead and it works. Could it be the problem in you printf routine? Could you try this code?

Code: Select all

const float g_fTCGain[8] = {1.0, 0.91, 0.905, 1.0, 1.0, 1.0, 1.0, 1.0};

char buffer[20];
void Test(unsigned int iVoltage){
  sprintf(buffer, "test: %f \r\n", (float)iVoltage * g_fTCGain[0]);
}

void main(){
    Test(20);
}
Its for pic18 family (pic16 does not have sprintf).
Of course, i missed a "s" and the string to fill.
This code doesn't work to me, and i write in the post above that i am running mikroC 7.0.0.3 and programming a pic18f8722.

My MikroC version hasn't been updated since the release. Have i to update some libraries?

Regards
CG

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

Re: problems about operations between vars in ram & rom

#6 Post by srdjan » 07 Nov 2007 11:37

Hi,
CGEngineering wrote:
srdjan wrote:Hi,
I do not have printf routine on my side. I have used our sprintf instead and it works. Could it be the problem in you printf routine? Could you try this code?

Code: Select all

const float g_fTCGain[8] = {1.0, 0.91, 0.905, 1.0, 1.0, 1.0, 1.0, 1.0};

char buffer[20];
void Test(unsigned int iVoltage){
  sprintf(buffer, "test: %f \r\n", (float)iVoltage * g_fTCGain[0]);
}

void main(){
    Test(20);
}
Its for pic18 family (pic16 does not have sprintf).
Of course, i missed a "s" and the string to fill.
This code doesn't work to me, and i write in the post above that i am running mikroC 7.0.0.3 and programming a pic18f8722.

My MikroC version hasn't been updated since the release. Have i to update some libraries?

Regards
CG
I have tried the fresh v7.0.0.3 installation, icd and release build on pic18f8722 and it works. Could you please send me the whole project with the above code to srdjan@mikroe.com. Also send me a screenshot of the result that you get in buffer variable while debugging.

CGEngineering
Posts: 144
Joined: 09 May 2007 23:31
Location: Florence - Italy
Contact:

Re: problems about operations between vars in ram & rom

#7 Post by CGEngineering » 10 Nov 2007 18:48

I have tried the fresh v7.0.0.3 installation, icd and release build on pic18f8722 and it works. Could you please send me the whole project with the above code to srdjan@mikroe.com. Also send me a screenshot of the result that you get in buffer variable while debugging.
Hi,
i can't send you the whole project as firm policy... and my programmer resolved the problem by the way i explained you.
The problem, howewer, doesn't appear simulating or in-circuit-debugging.
It appears if i want to send the string through a serial, using that as debugger tool, programming a real microprocessor

Bye, thanks
CG

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

Re: problems about operations between vars in ram & rom

#8 Post by srdjan » 12 Nov 2007 09:37

Hi,
Just a few additional questions.
CGEngineering wrote: The problem, howewer, doesn't appear simulating or in-circuit-debugging.
- Are you referring to your whole project or just the code snippet I have asked you to try? That is, the problem doesn't appear simulating or in-circuit-debugging your whole project or the code above?
CGEngineering wrote: i can't send you the whole project as firm policy... and my programmer resolved the problem by the way i explained you.
- I'm not asking you for the whole project. We would really appreciate if you or your programmer could take some time and try to isolate the specific code that causes the problem, make a small project with such code and send it to me. We are eager to resolve this problem, so that the other users would not have such issues.

Thank you in advance.

bruno
Posts: 767
Joined: 10 Sep 2005 02:10
Location: Lyon, France
Contact:

#9 Post by bruno » 12 Nov 2007 16:41

@CGEngineering : if you have interrupts enabled I suggest you to read this topic :
http://www.mikroe.com/forum/viewtopic.php?t=7717
Bruno
Bored with 7-segment ? Try the [url=http://www.micro-examples.com/public/microex-navig/doc/079-touchclock.html]TouchClock[/url]

CGEngineering
Posts: 144
Joined: 09 May 2007 23:31
Location: Florence - Italy
Contact:

Re: problems about operations between vars in ram & rom

#10 Post by CGEngineering » 12 Nov 2007 21:44

I know, in fact i'm asking him for that, but i know that he dodged the problem buffering in ram the rom readings. Tomorrow i will suggest bruno's solution and to take some time to reproduce that error...
Here i am... bruno's solution worked perfectly!

Thank you very much!

(did you see my last post on wish list?)

Bye
CG

Post Reply

Return to “mikroC Beta testing”