CNCzone.com-The Largest Machinist Community on the net!



Home Page Mark Forums Read Today's Posts My Replies Classifieds Reviews Photo Gallery Web Links Share Files Advertise With Us Ad List
Go Back   CNCzone.com-The Largest Machinist Community on the net! > Electronics > PIC Programing / Design


PIC Programing / Design Discuss programing of PIC chips here and design of electronics using PIC chips.


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Ban this user!
Old 11-05-2007, 02:40 PM
 
Join Date: Feb 2006
Location: USA
Posts: 91
llilrex is on a distinguished road
PIC problem

I am having a problem with my PIC18F1220 keeping its EEPROM settings. it has thrown me for a loop for a while. Here is how it goes.

In simulation it works perfectly,

When running for the first time it loads default settings by detecting the presents of settings within the EEPROM

There after you load your settings Via. RS232 it places them in the EEPROM the EEPROM is then referenced every time the board is turned on.

Global variables are referenced and set when ever you communicate the settings as a "working" table independent from the EEPROM and are used for program operation.

What happens in real life is:

It does not load default settings on the first start up

it will set the working table as can be verified by the RS-232 com. but the program will not use them for program operation I.E. the Duty Cycle will show changed but the board will not use the new settings and the EEPROM will not be updated with the new settings.

A problem with my program you say? (of course!)

But here is the kicker!

if you program the PIC and then read the EEPROM from the programmer the first time it will show blank "all FFs" but if you load it the second time it will show that the internal (load default) subroutine has worked.

And on top of that. It all works perfectly after that!

I don’t get it! Its simple you just program it and run it and it does not work! You read the EEPROM two times and it Works exactly as it was designed!

if you mess with the power (brown outs) rapid on-off on-off cycles it will loose the EEPROM settings and you will have to re read the EEPROM twice to get it to work again.

I tried resetting with /MCLR but to no avail!

Has anyone else had this problem? ANY help will be greatly appreciated!

If you have an idea and want to see part of the code I will be happy to post it!

Thank you.
Tweet this Post!Share on Facebook
Reply With Quote

  #2   Ban this user!
Old 11-09-2007, 01:42 PM
MacGyver's Avatar  
Join Date: Oct 2007
Location: usa
Posts: 240
MacGyver is on a distinguished road

Post the routines (and any supporting code, such as #defines) related to your EEPROM read/write functionality. Unless your write routine is seriously unprotected, poor startups should not cause any issue with loss of EEPROM data. This leads me to believe either your code is not actually writing the EEPROM (and your programmer is), or you're calling the write routine without realizing it.
__________________
Hi-TecDesigns.com -- Automotive Lighting Systems
Tweet this Post!Share on Facebook
Reply With Quote

  #3   Ban this user!
Old 11-17-2007, 02:50 PM
 
Join Date: Feb 2006
Location: USA
Posts: 91
llilrex is on a distinguished road

Hmmm. I didn’t think of it writing to the EEPROM randomly I will have to look into it further. But it will reliably loose its settings after four hours of being turned off.

There is code that will look for an "off value" in one of the settings and if it sees this setting is "off value" it will automatically write the default to all of the setting. The default routine uses the routines listed below when writing to the EEPROM and is at a higher level and does it explicitly using hard coded data for values.

void PTEE (int DAT,int ADRS) //Writes data into the EEPROM
{
EEADR = ADRS;
EEDATA = DAT;
EECON1bits.EEPGD = 0;
EECON1bits.WREN = 1;
INTCONbits.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR = 1;
while(PIR2bits.EEIF == 0); //wait for write to complete
PIR2bits.EEIF = 0;
}

int GTEE (int ADRS) //Returns a byte stored in the address denoted by ADRS
{
EEADR = ADRS;
EECON1bits.EEPGD = 0;
EECON1bits.RD = 1;
return EEDATA;
}

int GetDutyCycle (void)
{
return GTEE(0);
}

void PutDutyCycle (int DC)
{
PTEE(DC,0);
}
Tweet this Post!Share on Facebook
Reply With Quote

  #4   Ban this user!
Old 11-19-2007, 08:07 AM
 
Join Date: Dec 2005
Location: Usa
Posts: 93
Horsedorf is on a distinguished road
Buy me a Beer?

Is it possible that you have some of this stuff going on in an interrupt routine? And that you have an interaction with some variables between the background interrupt processing and the foreground processing that is touching variables inccorectly? ie.. in teh foreground, you go to read something, so you set up some registers, then in teh background something happens to alter one of those registers, then it returns from interrupt and your foreground routine tries to complete the read or write, only to have had the register change values?

Also, could you be using an array in an interrupt process that writes 'out of bounds' of the array and stomps on a foreground variable that is being used to index into the data you are working with?

Just a few kinds of things to look at that can seem totally unrelated until suddenly you notices that one peice of code that 'aint quite right'.

Good luck.
Tweet this Post!Share on Facebook
Reply With Quote

  #5   Ban this user!
Old 11-20-2007, 06:05 PM
 
Join Date: Feb 2006
Location: USA
Posts: 91
llilrex is on a distinguished road

thank you for the idea, I will look into this kind of thing, I am not using interupts in the software (exept for flagging) but there still can be other conflicts.
Tweet this Post!Share on Facebook
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 11-20-2007, 10:18 PM
 
Join Date: Dec 2005
Location: Usa
Posts: 93
Horsedorf is on a distinguished road
Buy me a Beer?

Originally Posted by llilrex View Post
thank you for the idea, I will look into this kind of thing, I am not using interupts in the software (exept for flagging) but there still can be other conflicts.
Yeah, unless the device is like.. HORRIBLY broken, the kind of behaviour you are describing sounds symptomatic of 'rules of touch' being violated somewhere. It sounds like you have the kind of bug that is actually just an artifact of a completely unrelated section of code. Those are the ones that are usually hardest to find.

Some tricks to try.. Use one or more unused IO pins to drive led's (Or a logic analyzer if you are lucky enough to have one) when sections of code are entered or exited or variables are set or cleared. They can sometimes help you find what's going on. ANother trick is if you have teh serial port free, to simply write a character into the serial port or the value of a variable of interest and do so at different points of execution of the code to see if it is changing in ways you don't expect.

The downside is, of course, that this will slow down execution of the code which could make it work correctly, or break it even further. Anyways, I hope one of these tricks helps you find what's going on . If it DOES get you to the solution, then you owe me a beer. LOL

Good luck!
Rick
Tweet this Post!Share on Facebook
Reply With Quote

  #7   Ban this user!
Old 11-21-2007, 02:08 AM
neilw20's Avatar  
Join Date: Jun 2007
Location: Australia
Age: 62
Posts: 2,189
neilw20 is on a distinguished road
Angry Environment?

What programmer/development paltform are you using?

I have had weird EEPROM telling lies type issuse before.

PC gets confused between what is in it's EE image which it displays.
I have have had issuses where you write some stuff.
PC says it not here. PIC says it is. Exit, restart PC program. Magically appears.

Some screwy logic regarding stale/fresh EE state in PC can be misleading.
Believe what the PIC does, and guess waht the PC sees!

50% chance you've screwed it, 25% USB latency, 25% opearting system (today anyway).
__________________
Super X3. 3600rpm. Two possible way to fix things: The right way or the other way.
Tweet this Post!Share on Facebook
Reply With Quote

Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
machine problem or software problem? bcnc Syil Products 8 10-26-2009 10:51 AM
G81 problem rob jerico Fadal 17 10-10-2007 02:42 PM
Problem Tazzer Haas Mills 1 02-27-2007 05:11 PM
MV-80 Problem, Tien_Luu Machine Problems, Solutions , Wireless DNC, serial port 0 08-04-2006 04:48 PM
What's Your Problem??????????? murphy625 CNCzone Club House 22 05-31-2005 02:43 AM




All times are GMT -5. The time now is 11:01 PM.





Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO
Template-Modifications by TMS

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353