Assembly Accessing SRAM malfunction

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hey there
a program expected to indicate an LED 100ms/sec , i used Timer 2 with Asynchronous operation. i read this tiny article "AVR134: Real Time Clock (RTC)", then used 22pf capacitors for TOSC1/TOSC2, 32khz crystal, a LED connected to PB1, Fusebits of L:E3  H:D9, chip = Atmega8A

the problem is:
from Emulator every thing is OK.
from physical tests, after startup, LED does not blinking, when some random times passed (20 sec, 40, 100) led starts blinking. after that if i Power OFF - re Power ON the MCU, that beginning delay goes away and LED starts indicating instantly! even i hold MCU without power for about 5 sec's.

 

TLDR; program uses timer2 with 32 prescaler, CTC mode, OCR=0, Compare math interrupt enabled.
inside the Interrupt sub routine:
A) i divided interrupts with 10(m_hsecdiv), and then 100(m_hsecdiv+1) to stores approximate value for hundredths of seconds
B) i counts 0-1024(m_sec) to detect if a real/accurate second is passed (32768/32 = 1024)
i used data segment to reserve memory locations for holding that counters
LED turned ON when [m_hsecdiv+1] is 90, then turned OFF when [m_sec] is 1024

 

problem occurred when i used dynamic memory (SRAM) to store counter values (code1no)
(code2yes) is a fix by replacing all data segment parameters with internal Registers, it has no .DSEG   no memory access   no problem   no delay for blinking, every thing starts as expected.


what is my misunderstand of using RAM in assembly format? am i defined segments correctly?
 

Attachment(s): 

This topic has a solution.

I'm new, please help me.

Last Edited: Sat. Jan 19, 2019 - 09:56 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If it works in the simulator, but not on your hardware, then surely you have a hardware problem?

 

So, show us your schematic and show us your actual hardware.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

added schematic , and actual hardware is Atmega8a-PU mounted on breadboard equal to its schema.

i think it is rare to get hardware problem with internal ram? however its a probability until some one tell me i wrote that short piece of code correctly or not, at least verify its communication with ram via directives & instructions.

I'm new, please help me.

Last Edited: Fri. Jan 18, 2019 - 01:14 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Never mind, not related to issue!

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
stack gold/silver https://www.onegold.com/join/713...

 

 

 

 

Last Edited: Fri. Jan 18, 2019 - 01:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you dear jim, i did not enabled them. I left CKOPT, 0 in fuse bits.

I'm new, please help me.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Pin 22 should be connected to 0V.

What is your power supply?

 

 

[E2A]

I don't see where you are waiting the 1 second required for the external crystal to stabilise.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

Last Edited: Fri. Jan 18, 2019 - 02:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried a loop of 64*65000 with "nop" instruction inside...
But no success. The only change that i found to makes this assembly snippet working, was replacing memory variables with mcu registers, im not sure if i use memory in wrong way.
But an un stabilised crystal will be stabillised during run time? Is it true? I mean it shall not generate freezed state of timer.

And about pin22, forgive me, it was connected. just a mistake in drawing schematic

I'm new, please help me.

Last Edited: Fri. Jan 18, 2019 - 08:10 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I didn't look too hard at your code, but I didn't see the memory variables initialised. Should they be set to zero? Maybe the simulator starts with "memory" cleared but the real processor starts with random stuff in memory.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

oh my god just at the same time with you i shot my last bullet to solve this problem and set all variables to 0 

thanks a lot for reading the code, it was my first time accessing data segment.

clr R16
sts m_hsecdiv , R16
sts m_hsecdiv+1 , R16
sts m_sec , R16
sts m_sec+1 , R16 

 

ajcashin wrote:

Maybe the simulator starts with "memory" cleared but the real processor starts with random stuff in memory.

 

its that place where simulator show every thing true but in actual test it is not.

but one more thing, without initializing memory... after passing some seconds, the code starts working!!!! and after a power off / power on (fully reset the MCU) the led starts blinking without any delay!

is there any data retention for a short time when no power consumpted? does SRAM uses capacitors to store data?

 

I'm new, please help me.

Last Edited: Sat. Jan 19, 2019 - 10:06 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

payam_sbr wrote:

...and after a power off / power on (fully reset the MCU) the led starts blinking!

 

How are you turning the power on and off?

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

just unplug battery and plug it back after 4 ~ 5 seconds

I'm new, please help me.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

payam_sbr wrote:

is there any data retention for a short time when no power consumpted? does SRAM uses capacitors to store data?

I have seen this happen with other processors. Once the processor stops running, there's very little draw on the 100nF capacitor and it may have enough voltage left to maintain memory for a few seconds.

Pleased it's solved. Good fortune with your programming.