|
|
View previous topic :: View next topic |
Author |
Message |
Jackman Guest
|
EEPROM's data was lost |
Posted: Sat Dec 02, 2006 11:24 am |
|
|
Hi to all,
I have had some problems with my EEPROM's data. I'm using a PIC16F877A with PCW+ICD-U40. Sending a float number to a address location (using #include <internal_eeprom.c> library), I can see how the bytes are changing when I write over there in the debugger window , but when I switch off the PIC, the EEPROM is "white" again. Probably, there is a command or fuses that I'm not using well. Please, see the program below and feel free to comment it, I 'm just a beginner in C...
Thanks a lot and Saludos.
#include <16F877A.h>
#device ICD=TRUE
#fuses HS,LVP,NOWDT,NOPUT,NOPROTECT,NOWRT,DEBUG
#use delay (clock=10000000)
#include <lcd.c>
#include <math.h>
#include <internal_eeprom.c>
set_tris_e (0x0F);
////////////////////////////////////// GLOBALES //////////////////////////////////////
int address=0;
const int v_max=5.00;
const int escala=1023;
const float ctte=1.667;
const float mbar=11.33;
char s[16],i;
float voltage,expo,expo1,pressure,pressure1,value, data;
char CONST set[]="Set Level Alarms";
char CONST welcome[]=" IRWFS VACUUM ";
char CONST error[]="SensorNotConnect";
////////////////////////////////////// SUBRUTINAS ////////////////////////////////////////
void print(float press)
{
lcd_gotoxy(1,2);
sprintf(s,"Vac=%1.2Embar\n",press);
for(i=0;s[i]!='\0';i++)
{
lcd_putc(s[i]);
}
delay_ms(200);
}
float calcula_voltage(float value, float &voltage)
{
value=0;
value=read_adc();
delay_ms(100);
voltage=(((value*v_max)/escala)*2);
}
float calcula_exp(float v)
{
return (ctte*v)-mbar;
}
float calcula_pressure(float xx)
{
return pow(10,xx);
}
void not_sensor()
{
lcd_gotoxy(1,2);
for(i=0;error[i]!='\0';i++)
{
lcd_putc(error[i]);
}
output_high(PIN_A3);
delay_ms(1000);
return;
}
void alarm_enable ()
{
while(input (PIN_E1))
{
read_float_eeprom(address);
if (input (PIN_E0))
{
output_low(PIN_A3);
set_values();
}
if (data<=voltage)
{
char mess[]=" Vacuum Alarm!! ";
lcd_gotoxy(1,1);
for(i=0;mess[i]!='\0';i++)
{
lcd_putc(mess[i]);
}
print(pressure);
output_high(PIN_A3);
//restart_wdt();
delay_ms(300);
break;
//restart_wdt();
}
else
{
output_low(PIN_A3);
calcula_voltage(value,voltage);
expo=calcula_exp(voltage);
pressure=calcula_pressure(expo);
print(pressure);
}
return;
}
}
void set_values()
{
while(input (PIN_E0))
{
read_float_eeprom(address);
lcd_gotoxy(1,1);
for(i=0;set[i]!='\0';i++)
{
lcd_putc(set[i]);
}
print(pressure1);
if (input (PIN_A1))
{
data=data-0.001;
write_float_eeprom(address,data);
expo1=calcula_exp(data);
pressure1=calcula_pressure(expo1);
print(pressure1);
delay_ms(100);
}
else if (input (PIN_A2))
{
data=data+0.001;
expo1=calcula_exp(data);
pressure1=calcula_pressure(expo1);
write_float_eeprom(address,data);
print(pressure1);
delay_ms(100);
}
}
}
/////////////////////////////////////// PRINCIPAL //////////////////////////////////////
void main()
{
setup_adc_ports(AN0);
set_adc_channel(0);
delay_ms(100);
setup_adc(ADC_CLOCK_DIV_8);
lcd_init();
lcd_putc('\f');
//dato1=5.00;
//setup_wdt(WDT_2304MS);
while(TRUE)
{
//restart_wdt();
lcd_gotoxy(1,1);
for(i=0;welcome[i]!='\0';i++)
{
lcd_putc(welcome[i]);
}
calcula_voltage(value,voltage);
expo=calcula_exp(voltage);
pressure=calcula_pressure(expo);
if(voltage<1>8.60)
{
not_sensor();
}
else if(input(PIN_E1) )
{
alarm_enable();
//output_high(PIN_A3);
}
//else if(input(PIN_E0) )
//{
//output_low(PIN_A3);
//set_values();
//}
else
{
print(pressure);
output_low(PIN_A3);
}
}
} |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Dec 02, 2006 12:03 pm |
|
|
Quote: |
HS,LVP,NOWDT,NOPUT,NOPROTECT,NOWRT,DEBUG |
The ICD-U40 is a high voltage programmer. It doesn't use LVP mode.
Change that fuse to 'NOLVP'.
Quote: | set_tris_e (0x0F); |
Because this line is placed above main(), it doesn't do anything.
You have an older version of the compiler, which doesn't give an
error for this line. If you want to set the TRIS, then move this
line to the start of main(). But, you don't need to set the TRIS
because you're using CCS i/o functions. In standard i/o mode
(the default mode of the compiler) the compiler will automatically
set the correct TRIS when you call 'input (PIN_E1)', etc.
Quote: | const int v_max=5.00; |
An 'int' is an unsigned 8-bit integer. You should really just set it to 5.
Your line above will work, because the compiler converts the float to
an int automatically. But it's not the best way to write it.
Quote: | const int escala=1023; |
In CCS, an 'int' is an unsigned 8-bit integer. You need to change
it to 'long' (or use 'int16' -- it's easier to see the size). Example:
Code: | const int16 escala=1023; |
There might be other problems. I didn't look at the whole program
in detail.
Also, when you post code, you should use the Code button to highlight
the code. You should also disable HTML. There is a box below the
posting window to do this. It looks like this:
Quote: | x Disable HTML in this post |
|
|
|
vu2iti
Joined: 02 Sep 2006 Posts: 4
|
Problem with DATA eeprom CORRUPTION |
Posted: Sun Dec 03, 2006 6:58 am |
|
|
Hi every one,
I have the similar problem. I am using 16F877A programmed using teh hex file genrated from C compiled using pic 3.xxx.
Some times, the DATA EEProm is getting corrupted. The pic based system is in production and only in few units, this problem is noticed.
The EPPROM data is modified only once at the time of installation. After that no write operation is attempted. The corrupted chi can be reporgammed and without any problem.
Is it due to the error in the compiler ofr the is the probnlem is in the PIC chip?
Any help?
Thanks,
VU2ITI |
|
|
Ttelmah Guest
|
|
Posted: Sun Dec 03, 2006 8:43 am |
|
|
Have you tried PICs from anither batch?. If the problems remains, I'd say probably neither.
How is the data written 'once at the time of installation'?. If there is a write routine present, then the possibility exists that this is being erroneously called. However the most likely thing, is a voltage going over 5v on the MCLR line. This can corrupt the data anywhere on the chip, but seems to upset the EEPROM first.
Best Wishes |
|
|
Jackman Guest
|
|
Posted: Mon Dec 04, 2006 6:59 am |
|
|
Thanks for your reply!
Ok, by the moment, I changed the wrong fuses and the variable's format, also I try with another chip from a different batch but the problem is still there. I checked that MCL is at least 5V and it isn't going up. I'm agreed with "Ttelmah", probably there is a bug in the program or I'm calling/using a wrong routine. Be aware that i'm using a internal library called "internal_eeprom.c" to write and read the EEPROM. Thanks and let's think about it!
Saludos, |
|
|
vu2iti
Joined: 02 Sep 2006 Posts: 4
|
|
Posted: Mon Dec 04, 2006 9:31 am |
|
|
Ttelmah wrote: | Have you tried PICs from anither batch?. If the problems remains, I'd say probably neither.
How is the data written 'once at the time of installation'?. If there is a write routine present, then the possibility exists that this is being erroneously called. However the most likely thing, is a voltage going over 5v on the MCLR line. This can corrupt the data anywhere on the chip, but seems to upset the EEPROM first.
Best Wishes |
Thank you for your comments.
All the chips are from the same batch. There is no chance of MCLR pin going at a higher voltage than VCC (it is tied using a resistor to VCC)
Yes, there is a Write routine and this routine is called only when a serial write command ( which is three charactors long) is send through RS232. In run time, the serial link is disconnected. Even if a write operation is accidently activated, there is no chance of corruption of the data eeprom, as write operation to the location depends on another variable which also need to be corrupted for erratic write operation.
Program memory corruption is never occured in any of the chips where the eeprom data memory was corrupted.
Thanks again for the repsonse.
VU2ITI |
|
|
|
|
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
|