Mike -- No longer here
Mike -- No longer here

Reputation: 2092

Software algorithm to test sram on microcontroller at high speed

I have an 8051 microcontroller with external ram attached to it and I want to test the ram to see that it can store and load data correctly (which I think it currently does not).

In my program, I have it where the value 80h is written to 1st byte of memory and the value increments as each memory address is incremented but the value rolls over to zero every 256 bytes starting with the 128th byte.

This is my function:

;extended memory test. C=1=memory fault
memtest:
  mov DPTR,#0h
  mov R7,#80h
  ;fill with incrementing values
  post1:
    mov A,R7
    movx @DPTR,A
    inc R7
    inc DPTR
    mov A,DPH
    orl A,DPL
  jnz post1
  ;Test for incrementing values
  mov DPTR,#0h
  mov R7,#80h
  post2:
    clr C
    movx A,@DPTR
    subb A,R7
    setb C
    jnz isbadram
    movx @DPTR,A
    mov A,R7
    inc R7
    inc DPTR
    mov A,DPH
    orl A,DPL
    clr C
  jnz post2
  isbadram:
ret

But I think I need to do more of a rigorous test. I think I need to write and read different values multiple times to the same locations but I don't know how many times to test a location and I don't know the best values to try.

I'm just afraid if I test a location too many times, then my program will spend forever testing memory before it begins doing anything useful.

Luckily I own some microcontrollers that can execute instructions at about 40nS each. I have others of the same family that execute instructions at about 0.5uS each.

So whats the best way to test a ram chip already installed in the system without spending too much time on the testing?

Upvotes: 3

Views: 1087

Answers (2)

the busybee
the busybee

Reputation: 12610

The number of repetitions of a RAM test depends on what you like to check and when in the life cycle of your product you check.

If you're checking the output of the production line, you could repeat the test "for ever" to check under different environment conditions like temperature. But one run should suffice for most cases.

If you want to test one specific board, you could also test "for ever" until you switch off. This is helpful to probe the wiring with an oscilloscope, too.

If you want to test in the field while running the application software, you can use a high priorised timer interrupt to test one byte at a time. This runs "for ever", too, of course. And make sure that your test restores the old value.

But first you have to decide what kind of errors you are looking for:

  1. Hardware errors like open or short circuits in the wiring. This is quite possible.
  2. Hardware errors like a partly defective RAM. I never had any of these. The RAMs I tested worked perfectly or not at all, put aside mistakes like wrong access cycles.

For the first kind I would test like this:

  1. Write and check all 8 patterns with only one 1-bit into any address (data 0x01 ... 0x80)
  2. Write and check all 8 patterns with only one 0-bit into any address (data 0xFE ... 0x7F)
  3. Write different patterns (like incrementing numbers) into the address with all 0-bits and all (up to 16) addresses with only one 1-bit (addresses 0x0000, 0x0001 ... 0x8000)
  4. Check the patterns at the addresses
  5. Write different patterns (like incrementing numbers) into the address with all 1-bits and all (up to 16) addresses with only one 0-bit (addresses 0xFFFF, 0xFFFE ... 0x7FFF)
  6. Check the patterns at the addresses

If a check fails, you could abort the test loop and report the error. The tested data bit or address bit gives some hint for the actual error. If you like to probe the wiring, just report and keep going.

This is really fast and reveals many permanent errors. For transient errors you need to repeat the test.

For the second kind you need more sophisticated tests. Some of these depend on the real physical organization in the RAM, concerning rows and columns of bits. You might like to search the web for "factory RAM tests" like "galloping patterns" ("galpat").

Unfortunately these tests take a long time, as you noticed. But I'm afraid that there is no way around.

A very simple test will write a sequence of pseudo-random numbers into the RAM and then check the sequence. Make sure that your number generator produces a period at least as long as the size of the RAM, for example by using a number wide enough. You will use just the lower 8 bits of it, however. You could use a LFSR.

Upvotes: 1

Mike
Mike

Reputation: 4288

There are a lot of 'on the fly' RAM test available. They had to be used for security systems. Just ask google.
A first document is here or here

Upvotes: 0

Related Questions