You are here:

C++/Data in memory going to zero.

Advertisement


Question
QUESTION: Bill, I'm at my wits end with this problem I have.  I'm using an old compiler, Wintek, to program a MC6809 micro.  I have a problem with data in ram going to zero after a period of time.  The data is made up of two sets of 6 structures that I will call here set A and set B.  In the main loop I have a call to a function that copies set A to set B continuously.  The logic board has an 8 MHZ crystal and the ram is an 8k Dallas DS1225. I have checked and rechecked the hardware for noise problems and replaced the IC's.  This seems to be a very random event that occurs on more than one logic board.  (this is a product we make that is at our customer's plant)  Is it possible, doing a read from ram, that the memory can go to zero on the copied set A?  Is there something about 'C' compiled code that causes a problem like this?  Thank you for being patient with my question.

ANSWER: Hi Jim,

Is that an 8MHz crystal attached to the 6809 or are you running at 8MHz using e.g. a 1 or 2MHz crystal?  I ask because 8MHz crystals were out of spec with 6809's of the past. I've used the 68S08 recently and that was out of spec even for a processor spun this decade.

Do you have interrupts running in this system?  Are you using memcpy?  Can you write you own memcoy in C or assembly in case the built-in one has limitations or problems.  How random?  How long or short between clears?  So to be clear, you're copying A to B and A is wiped out?  When you see A is wiped out, is B ok? Can you detect A is bad and copy B back to A to keep at least an older copy?  Does exactly sizeof A get wiped or more (or less) RAM than that?  Can you create C and copy A to B and copy B to C?  Does B then corrupt copying to C?  Finally, do you have an ICE to use to use write breakpoints on A?

Sorry for all the questions.  Sometimes a shotgun of questions uncovers the problem answering them.

Bill

---------- FOLLOW-UP ----------

QUESTION: Hi Bill,
Thank you for your immediate reply.  I'm using an 8MHZ crystal and actually the 68B09 is a Hitachi HD63B09P chip.  I do have interrupts running.  The timebase of 1 mS coming from a 68681 duart runs all the time.  I'm not using memcpy but a assembly routine shown below:
; COPY TX BUFFER AT EACH MAIN LOOP
       DSCT
       EXTERN   begbuf
       EXTERN  endbuf
       PSCT
       GLOBAL  copybuf
copybuf equ *
  ORCC #50H
       LDX     #begbuf+1
       LDY     #endbuf+1
cop1   ldd 0,x++
  std 0,y++
  cpx #004BH
  ble cop1
  ANDCC #0AFH
  nop
  ORCC #50H
cop2   ldd 0,x++
  std 0,y++
  cpx #0095H
  ble cop2
  ANDCC #0AFH
  nop
  ORCC #50H
cop3   ldd 0,x++
  std 0,y++
  cpx #00DDH
  ble cop3
  ANDCC #0AFH
  nop
  ORCC #50H
cop4   ldd 0,x++
  std 0,y++
  cpx #0125H
  ble cop4
  ANDCC #0AFH
  nop
  ORCC #50H
cop5   ldd 0,x++
  std 0,y++
  cpx #016DH
  ble cop5
  ANDCC #0AFH
  nop
  ORCC #50H
cop6   ldd 0,x++
  std 0,y++
  cpx #01B5H
  ble cop6
  ANDCC #0AFH
  nop
  ORCC #50H
cop7   ldd 0,x++
  std 0,y++
  cpx #01FDH
  ble cop7
  ANDCC #0AFH
  nop
  ORCC #50H
cop8   ldd 0,x++
  std 0,y++
  cpx #256H
  ble cop8
  ANDCC #0AFH
  nop
       rts
I don't have an ICE and yes this is old technology, but I am forced to use this micro for our old time customers.  Set B memory is data that would be transmitted to our data collection software and Set A is thr regular data that is used for incrementing counts, cycle times, parts made etc.  
Only parts of Set B get zeroed and I know that some constants in Set A get zeroed too.
Thanks again, Jim  

Answer
Boy it's hard to see what's going on from here, but perhaps a simple thing to try is to disable (sti) and enable (cli) interrupts at the beginning and end of the memory copy routine.  You would want to do this to ensure the integrity of the entire contents and perhaps an interrupt is using/writing to the data.  Also, be sure your ISR saves everything it uses.

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Bill A

Expertise

I can answer questions about C++, programming algorithms, Windows programming in MFC (which is C++). I cannot answer questions about STL (templates) and I have no experience with Linux. I do enjoy reviewing code and critiquing it or finding problems in it. I will also gladly show better algorithms or methods if you want to take advantage of that.

Experience

I've developed a commercial embedded C compiler/assembler and IDE with debugger toolset, of which the IDE and debugger are written in C++. I work in the industry writing high tech embedded programs and Windows programs to communicate with the embedded devices.

Publications
Book: Embedded Systems Design using the Rabbit 3000 Microprocessor Authored Chapter 10 in its entirety.

Education/Credentials
BS Computer Engineering

©2016 About.com. All rights reserved.