CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Is there a better way to store calibration values?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bschriek



Joined: 18 Dec 2007
Posts: 83

View user's profile Send private message Send e-mail

Is there a better way to store calibration values?
PostPosted: Mon Feb 09, 2026 9:25 am     Reply with quote

<16F15223.H> CCS compiler 5.121

I use the following code to read and write calibration values to the memory of my PIC's for years. Although it works fine can somebody tell me if a better solution is available for the modern pic's like the 16F15223?


//---------------Configuration-----------------//
#define HEF 0X0780
#ROM int16 HEF = {160,160}

struct twobytes
{
int8 l;
int8 h;
};

union prog_mem
{
int16 word;
struct twobytes b;
};


//-----------------Main loop-------------------//
struct {
union prog_mem I_cal_hef_24V;
union prog_mem U_cal_hef_24V;
}


//--------Read calibration values from memory--------//
read_program_memory(HEF,&values,2);
I_cal_24V = values.I_cal_hef_24V.b.l;
U_cal_24V = values.U_cal_hef_24V.b.l;

//--------Write calibration values to memory--------//
values.I_cal_hef_24V.b.l = I_sense_24V;
values.U_cal_hef_24V.b.l = U_sense_24V;
write_program_memory(HEF,&values,2);


Sorry for this question but I'm a hardware engineer.......
newguy



Joined: 24 Jun 2004
Posts: 1928

View user's profile Send private message

PostPosted: Mon Feb 09, 2026 5:56 pm     Reply with quote

Not really. Two things: the address of the high endurance flash should be available using the getenv feature so that you don't have to look it up yourself. Second, I always guard writes to memories that are either slow or can wear out (or both). I always read the contents of the memory first and only write if the value is different than what I intend to write.

Other than those minor nit picks, you're doing it right.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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