Author Topic: Can an unitialised bit change it's state?  (Read 1287 times)

0 Members and 1 Guest are viewing this topic.

Offline CirclotronTopic starter

  • Super Contributor
  • ***
  • Posts: 3180
  • Country: au
Can an unitialised bit change it's state?
« on: August 04, 2022, 12:17:02 am »
Background to the question - I used several bits in a particular RAM byte as flags. They would be set at power up if certain external conditions were yes. The mistake I made was not clearing the RAM first, and so sometimes those bits that should have been clear would be randomly set...  :palm:

So, the question is, if a bit is not specifically set or cleared at power up, can it be kind of borderline halfway and perhaps be read as a 0 for a while and later drift be read as a 1?  Sort of like when an input pin is left floating and eventually drifts across the low/hi threshold.
------
I never picked up this non-cleared RAM problem until just now. HC908 micros never gave a problem for quite a few years. Switched to S08PA micros three years ago and still no problems. Then switched to S08FL because of chip shortages and this is where it all started. Those micros have been a pain in the butt for a number of reasons, but it's an ill wind that blows nobody no good. At least I found a bug that I probably wouldn't have otherwise. 
« Last Edit: August 04, 2022, 02:34:48 am by Circlotron »
 

Offline ejeffrey

  • Super Contributor
  • ***
  • Posts: 3717
  • Country: us
Re: Can an unitialised bit change it's state?
« Reply #1 on: August 04, 2022, 02:00:06 am »
No.  SRAM is bistable.  It will land on a 0 or 1 within nanoseconds after the power rail is stable and stay there indefinitely.  DRAM will be driven to a logical state at the first read or refresh
 

Offline Geoff-AU

  • Regular Contributor
  • *
  • Posts: 148
  • Country: au
Re: Can an unitialised bit change it's state?
« Reply #2 on: August 04, 2022, 02:01:18 am »
SRAM will pick a state and stay there

DRAM will be refreshed and whatever state is read the first time will be reinforced by the refresh so it'll stay there too

but *.RAM being in an unknown state at startup is an important paradigm to be aware of.  Your startup sequence should initialise anything it's using in RAM to a known state (the C compiler does this for simple variables but if you're assigning a flag to a fixed RAM address then the compiler won't automatically zero it for you).  Also..  if you assign but don't initialise an array then its contents will be whatever was in that memory beforehand.
 

Offline srb1954

  • Super Contributor
  • ***
  • Posts: 1091
  • Country: nz
  • Retired Electronics Design Engineer
Re: Can an unitialised bit change it's state?
« Reply #3 on: August 04, 2022, 02:24:06 am »
No.  SRAM is bistable.  It will land on a 0 or 1 within nanoseconds after the power rail is stable and stay there indefinitely.
Unless it is hit by a powerful cosmic ray.
 

Offline free_electron

  • Super Contributor
  • ***
  • Posts: 8517
  • Country: us
    • SiliconValleyGarage
Re: Can an unitialised bit change it's state?
« Reply #4 on: August 04, 2022, 03:01:37 am »
No.  SRAM is bistable.  It will land on a 0 or 1 within nanoseconds after the power rail is stable and stay there indefinitely.
Unless it is hit by a powerful cosmic ray.
one alpha particle is enough ...
Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 

Offline CirclotronTopic starter

  • Super Contributor
  • ***
  • Posts: 3180
  • Country: au
Re: Can an unitialised bit change it's state?
« Reply #5 on: August 04, 2022, 03:10:23 am »
Okay. I'll put something like the following in right at the start.
Code: [Select]
CLRX
CLR_LOOP CLR $40,X
        DBNZX CLR_LOOP
It would only clear the first 256 bytes (starting at $40) of course, but my stuff only uses about 50-60 bytes max.
 

Offline CirclotronTopic starter

  • Super Contributor
  • ***
  • Posts: 3180
  • Country: au
Re: Can an unitialised bit change it's state?
« Reply #6 on: August 18, 2022, 01:09:54 am »
I never picked up this non-cleared RAM problem until just now. HC908 micros never gave a problem for quite a few years. Switched to S08PA micros three years ago and still no problems. Then switched to S08FL because of chip shortages and this is where it all started.
Update on this - it turns out it was not the fault of the different micro. When I ported the code to the FL micro I forgot to include the line that specifically clears the flags RAM byte. I should have cleared all used RAM right from the start. If you believe the data sheet then the basic code *should* run on all versions in that micro family, but it ain't so. The DDRs are one example. And the clock setup details...  |O
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf