Hello.
My deluxe nixie clock V2.0 project is almost complete, PCBs assembled and tested, enclosures made and software written, however, I'm trying to debug a nasty bug with no success. The issue is as follows, I have option for auto brightness, which gradually decreases brightness starting at 18:00, till 23:00 then keeps at low level till 06:00 and gradually increases it till 10:00. This is done via this subroutine:

Code:
DIMMER: 'auto dim routine
IF Z2=06 THEN HPWM 2,150,2000
IF Z2=08 THEN HPWM 2,200,2000
IF Z2=10 THEN HPWM 2,255,2000
IF Z2=18 THEN HPWM 2,200,2000
IF Z2=19 THEN HPWM 2,150,2000
IF Z2=20 THEN HPWM 2,100,2000
IF Z2=21 THEN HPWM 2,20,2000
IF Z2=23 THEN HPWM 2,10,2000
return
Z2 is decoded from RTC reading (DS3231) and converted to DEC with this:
Code:
Z2=(RTCHour >> 4)*10+RTCHour // 16 'decode hours
But there is a strange problem. After time reaches 18:00, in each minute, clock enters setup mode! I exit setup mode, it works fine, but when minute changes, instead of doing display refresh, as it is defined in software, it goes into setup again. This happens all night long, but during the daytime, after 10 o'clock, it works all fine!

Setup mode is called via pressing a button, which is connected to ADC:

Code:
if ticker>150 and ard<100 then  ticker=1: goto premakro (ticker is delay loop counter for de-bouncing and ARD is ADC input)
So what I have done:

Checked Z2 variable, it is "exclusive" and only used in these two code samples posted above.
"premakro" subroutine is being called from only one place in the code and there are no other entries referring to it.

Any ideas?
I can post complete code, but it is over 700 lines long, so I guess no one will bother reading it...