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 (code1)
(code2) 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?