|
|
View previous topic :: View next topic |
Author |
Message |
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
getting garbage data by using "byte const " |
Posted: Fri Apr 06, 2007 1:59 am |
|
|
Dear Sir,
here i am using 16f684, MPLAB 7.5 Ver. & CCS PCM C Compiler, Version 3.249, 34534.
in this programe i want to store arrays data in ROM.
so i declare arrays like this,
BYTE CONST RPM_COUNT[14] = {7500,6000,5000,4839,3571,3333,3000,2727,2308,2143,2000,1875,1765,1667};
BYTE CONST SLOPE[13] = {89,1,-106,4,24,3,3,3,-16,-95,11,-102,18};
BYTE CONST DELAY_COUNT[13] = {542,17,14,81,60,37,33,30,21,25,79,83,120};
These are called in function.But after compling & doing single steping i found that the value
stored in these arrays is different.
So plz tell me what is wrong with my code,Plz Refer following code.
Code: |
#include <16F684.h>
#fuses INTRC_IO,NOWDT,PUT,NOMCLR,PROTECT,NOCPD,NOBROWNOUT,NOPROTECT,NOIESO,NOFCMEN
//Internal RC Osc, no CLKOUT,No Watch Dog Timer,Power Up Time ON,Internal MCLR,Code Protect ON,No EE protection,Brownout detect OFF,
#use delay(clock=8000000)
void init_CPU();
unsigned int16 CALCULATION_FUNCTION(unsigned int16);
BYTE const RPM_COUNT[14] = {7500,6000,5000,4839,3571,3333,3000,2727,2308,2143,2000,1875,1765,1667};
BYTE const SLOPE[13] = {89,1,-106,4,24,3,3,3,-16,-95,11,-102,18};
BYTE const DELAY_COUNT[13] = {542,17,14,81,60,37,33,30,21,25,79,83,120};
unsigned int16 DLY_CNT,RPM_CNT;
void main()
{
int8 j =0;
init_CPU();
while(j != 12)
{
RPM_CNT = 6500;
DLY_CNT = CALCULATION_FUNCTION(RPM_CNT);
RPM_CNT += 500;
j++;
}
}
unsigned int16 CALCULATION_FUNCTION(unsigned int16 TIMER_COUNT)
{
int8 i;
signed int32 DLY_CNT1;
unsigned int16 DLY = 0;
for(i = 0; i <= 12; i++)
{
if((TIMER_COUNT <= RPM_COUNT[i]) && (TIMER_COUNT >= RPM_COUNT[i + 1]))
{
DLY_CNT1 = RPM_COUNT[i] - TIMER_COUNT;
DLY_CNT1 = (signed int32)(SLOPE[i] * DLY_CNT1); // int32
DLY_CNT1 = (signed int32)DLY_CNT1 >> 8;
DLY = (unsigned int16) (DELAY_COUNT[i] - (DLY_CNT1));
//if(BIT_TEST(DLY,16))
// DLY *= -1;
break;
}
}
return (DLY);
}
void init_CPU()
{
/**************** PORT SETTINGS ***********************/
PORT_A_PULLUPS(FALSE);
SET_TRIS_A(0X1B); // I/P = RA0,RA1,RA3. O/P = RA2,RA4,RA5.
SET_TRIS_C(0X18); // I/P = RC4. O/P = RC0,RC1,RC2,RC5.
/**************** COMPARATOR SETTINGS ***************/
SETUP_COMPARATOR(NC_NC_NC_NC);
/*************** END OF CPU INIT ******************/
}
|
_________________ Thank You,
With Best Regards,
Deepak. |
|
|
Ttelmah Guest
|
|
Posted: Fri Apr 06, 2007 2:18 am |
|
|
How big isa 'BYTE'?...
What is the biggest number that can fit in this?...
int16 const...
Best Wishes |
|
|
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
getting garbage data by using "byte const " |
Posted: Fri Apr 06, 2007 2:52 am |
|
|
soory sir,
at 1st i couldn't understand the meaning of "BYTE CONST ".
but ,PLZ Refer following code......
Code: |
#include <16F684.h>
#fuses INTRC_IO,NOWDT,PUT,NOMCLR,PROTECT,NOCPD,NOBROWNOUT,NOPROTECT,NOIESO,NOFCMEN
//Internal RC Osc, no CLKOUT,No Watch Dog Timer,Power Up Time ON,Internal MCLR,Code Protect ON,No EE protection,Brownout detect OFF,
#use delay(clock=8000000)
void init_CPU();
unsigned int16 CALCULATION_FUNCTION(unsigned int16);
unsigned int16 DLY_CNT,RPM_CNT;
void main()
{
int8 j =0;
init_CPU();
while(j != 12)
{
RPM_CNT = 6500;
DLY_CNT = CALCULATION_FUNCTION(RPM_CNT);
RPM_CNT += 500;
j++;
}
}
unsigned int16 CALCULATION_FUNCTION(unsigned int16 TIMER_COUNT)
{
/***** Value in watch window getting different when "using const " **/
//const unsigned int16 RPM_COUNT[14] = {7500,6000,5000,4839,3571,3333,3000,2727,2308,2143,2000,1875,1765,1667};
//const signed int8 SLOPE[13] = {89,1,-106,4,24,3,3,3,-16,-95,11,-102,18};
//const int16 DELAY_COUNT[13] = {542,17,14,81,60,37,33,30,21,25,79,83,120};
/*********************************************************
/*******programe works fine without using " const " ********/
unsigned int16 RPM_COUNT[14] = {7500,6000,5000,4839,3571,3333,3000,2727,2308,2143,2000,1875,1765,1667};
signed int8 SLOPE[13] = {89,1,-106,4,24,3,3,3,-16,-95,11,-102,18};
int16 DELAY_COUNT[13] = {542,17,14,81,60,37,33,30,21,25,79,83,120};
/***************************************************/
int8 i;
signed int32 DLY_CNT1;
unsigned int16 DLY = 0;
for(i = 0; i <= 12; i++)
{
if((TIMER_COUNT <= RPM_COUNT[i]) && (TIMER_COUNT >= RPM_COUNT[i + 1]))
{
DLY_CNT1 = RPM_COUNT[i] - TIMER_COUNT;
DLY_CNT1 = (signed int32)(SLOPE[i] * DLY_CNT1); // int32
DLY_CNT1 = (signed int32)DLY_CNT1 >> 8;
DLY = (unsigned int16) (DELAY_COUNT[i] - (DLY_CNT1));
//if(BIT_TEST(DLY,16))
// DLY *= -1;
break;
}
}
return (DLY);
}
void init_CPU()
{
/**************** PORT SETTINGS ***********************/
PORT_A_PULLUPS(FALSE);
SET_TRIS_A(0X1B); // I/P = RA0,RA1,RA3. O/P = RA2,RA4,RA5.
SET_TRIS_C(0X18); // I/P = RC4. O/P = RC0,RC1,RC2,RC5.
/**************** COMPARATOR SETTINGS ***************/
SETUP_COMPARATOR(NC_NC_NC_NC);
/*************** END OF CPU INIT ******************/
}
So, if used "const" the data showing in watch windows is garbage,but i haven't used "const "the prog. works fine.
Plz reply. |
_________________ Thank You,
With Best Regards,
Deepak. |
|
|
Ttelmah Guest
|
|
Posted: Fri Apr 06, 2007 4:15 am |
|
|
What are you trying to 'watch'?. You can only 'watch' RAM variables, so if you 'watch' a value that is declared as a constant, expect garbage. Do the numbers actually come out 'right' at the end?.
Constants are 'odd', they are actually a declaration to a program, held in the ROM, which returns the expected value, not directly a 'number' held in the ROM. hence 'watches' cannot be used in relation to these. If you want to 'see' a const value, you have to code like:
Code: |
int16 dummy;
dummy=RPM_COUNT[0];
//now a 'watch' on 'dummy', will show the RPM_COUNT[0] value.
|
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|