View previous topic :: View next topic |
Author |
Message |
gaminid
Joined: 27 Nov 2007 Posts: 10
|
Variable @ specific location gets corrupted at initilization |
Posted: Mon Sep 29, 2008 4:07 pm |
|
|
Hello,
I am using PIC 16F917 microcontroller. In my code I initialize several 32 bit variables. . When I run the code all variable gets initialized correctly except one variable at a specific location (06D). Regardless the variable as long as its location is 06D the 8 msb bits never get the values called in the initializing values. The 8 msb bits get the values from somewhere else!!
In my troubleshooting I just created a dummy variable (Test; never used in anywhere else) located at 06D and I cannot initialize correctly
In my troubleshooting I just created a dummy variable (Test; never used in anywhere else) located at 06D and I cannot initialize correctly.
I have on idea what is happening...
Can anyone tell me what I am doing wrong?
Here is my variable initialization .... the variable Test not used anywhere else.
Code: |
unsigned int32 Volt_1p8; // MUX[1]
unsigned int32 Volt_27; // MUX[2]
unsigned int32 TxPwrVolt; // MUX[3]
unsigned int32 Test = 0x00000000; // MUX[4] LOCATION @ 06D; problem with 8 MSB
unsigned int32 nicVolt; // MUX[4]
unsigned int32 minus5V; // MUX[5]
unsigned int32 plus5V; // MUX[6]
unsigned int32 tempCurrent;
|
Thanks in Advance
Gamini
Last edited by gaminid on Mon Sep 29, 2008 4:17 pm; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 29, 2008 4:14 pm |
|
|
Post a small test program that demonstrates the problem.
The program should declare the variables as shown in your post above,
and it should have code in main() that initializes the variables, and it
should use printf statements to display the variables. These are the
only things that your test program should do.
Make sure that you post the #include, #fuses, and #use delay()
statements. The program should compile without errors. You should
run the program and post the results (and also post the program).
Also, post your compiler version. |
|
|
gaminid
Joined: 27 Nov 2007 Posts: 10
|
|
Posted: Mon Sep 29, 2008 6:09 pm |
|
|
Thanks for the prompt response. Here is the test code I just wrote. As you suggested I made sure it gets compiled without errors. While I was testing my Test code I noticed that I am having the same problem with address locations 06E and 06F as well. Each time the the two bytes get shifted towards the LSB.
I used the MPLABS ICD2 debugger to find the location of the register Test. The compiler version is PCWH 3.235
Here is the test code:
Code: |
/*----------------------------------------------------
* Here is the test code to demonstrate the problem
* of getting corrupted initialized values at address
* locations 06D. This is true for 06E and 06F address
* locations as well.
*
* PCWH compiler version is 3.235
* --------------------------------------------------*/
#include "16F917.h"
////////////////////////////////////////////////////////////////////////////////
#FUSES NOWDT //Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES MCLR //Master Clear pin enabled
#FUSES NOCPD //No EE protection
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES DEBUG //Debug mode for use with ICD
#device adc=10 //sets the adc to return a 10-bit value
#use delay(clock=4000000)
#use rs232(BAUD=9600,XMIT=pin_c6, RCV=pin_c7)
unsigned int8 which_switch ;
unsigned int8 int_count = 0;
unsigned int1 I_flag = FALSE;
unsigned int8 startup_count = 30;
unsigned int1 Ierror_flag = FALSE;
unsigned int1 ErrorFlag_1p8V = FALSE;
unsigned int1 ErrorFlag_27V = FALSE;
unsigned int1 ErrorFlag_Neg5V = FALSE;
unsigned int1 ErrorFlag_Pos5V = FALSE;
/////////////////////////////////////////////////////////////////////////////////////////
//Main Program
/////////////////////////////////////////////////////////////////////////////////////////
void main()
{
/////////////////////////////////////////////////////////////////////////////////////////
//Operation variables
/////////////////////////////////////////////////////////////////////////////////////////
unsigned int32 tempVolt;
unsigned int32 BoxTemp;
unsigned int8 itemp = 0;
unsigned int16 batt_hysteresis;
unsigned int32 volt_array[6] = {0,0,0,0,0,0};
unsigned int8 i;
unsigned int8 mux_order[6] = {0,1,2,5,6,7};
unsigned int32 Volt_1p8 = 0x00000000;
unsigned int32 Volt_27 = 0x00000000;
unsigned int32 TxPwrVolt;
// Test registers for trubleshooting
// unsigned int8 Test1 = 0x00; // add this for 06F
// unsigned int8 Test2 = 0x00; // add this for 06E
unsigned int8 Test3 = 0x00;
unsigned int16 Test4 = 0x0000;
unsigned int32 Test5 = 0x00000000;
unsigned int32 Test6 = 0x00000000;
unsigned int32 Test7 = 0x00000000;
unsigned int32 Test8 = 0x00000000;
// now this Test register at 06D
unsigned int32 Test = 0xFFFF0000; // gets initialized to 1CFF0000 instead FFFF000
unsigned int32 nicVolt = 0x00000000;
unsigned int32 minus5V = 0x00000000;
unsigned int32 plus5V = 0x00000000;
unsigned int32 tempCurrent = 0x00000000;
/////////////////////////////////////////////////////////////////////////////////////////
//initial setup of MCU and port initialization
//////////////////////////////////////////////////////////////////////////////////////////
setup_lcd(LCD_DISABLED); //Disable LCD functionality
setup_wdt(WDT_OFF);
setup_low_volt_detect(LVD_23); //enable low voltage detect @ 2.3V
setup_adc_ports(sAN0|sAN1|sAN2|sAN3|VSS_VDD); //set a/d ports
setup_adc(ADC_CLOCK_DIV_8);
setup_comparator(NC_NC_NC_NC|COMP_DISABLE_WAKEUP); //disable comparator
setup_vref(FALSE); //no reference voltage used, since comparators disabled
setup_CCP1(CCP_OFF);
setup_CCP2(CCP_OFF);
while (true)
{
printf("\n\rvariable Test: %8X ",Test);
delay_ms(500);
}
}
|
Thanks
Gamini |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 29, 2008 6:53 pm |
|
|
Quote: | printf("\n\rvariable Test: %8X ",Test); |
You must use a format string of "%LX" with an int16 or int32 variable.
Example:
Code: |
printf("\n\rvariable Test: %8LX ",Test);
|
|
|
|
gaminid
Joined: 27 Nov 2007 Posts: 10
|
|
Posted: Mon Sep 29, 2008 6:58 pm |
|
|
Yes, it was my mistake. However I actually didn't use the rs232 to look at the value. Instead I was using the debugger to look at valriable value.
Thanks
Gamini |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 29, 2008 7:14 pm |
|
|
Try it with the RS-232. Run the program in stand-alone mode. Don't
run it in Debug mode. |
|
|
gaminid
Joined: 27 Nov 2007 Posts: 10
|
|
Posted: Mon Sep 29, 2008 7:18 pm |
|
|
My hardware doesn't support RS232. I have no way of doing that!!
Thanks
Gamini |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 29, 2008 8:11 pm |
|
|
I installed your version of the compiler. I installed a 16F917 in my
PicDem2-Plus board. I selected ICD2 as the debugger in MPLAB.
I compiled the program and programmed it from the Debugger menu
in MPLAB. I opened a Watch window and added 'Test' as an item to
watch. I put a breakpoint on the printf line in the source window.
I selected "Run" from the Debugger menu. It displayed 0xFFFF0000
in the Watch window. It works for me. I used MPLAB vs. 7.41.
Make sure the Debug file type is set to "COFF" in the Build Options menu
in MPLAB. |
|
|
gaminid
Joined: 27 Nov 2007 Posts: 10
|
|
Posted: Tue Oct 07, 2008 6:06 pm |
|
|
Many thanks for the hint. I figured the problem.
I had not set the compiler for the use with ICD debugger check box. It is in the same menu box you mentioned.
Thanks again...
Gamini |
|
|
|