Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

time(clock_sys) produces HH:MM:SS in Hex!

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions
View previous topic :: View next topic  
Author Message
uhrmacher

Bascom Member



Joined: 15 Sep 2005
Posts: 60
Location: Donauwoerth

germany.gif
PostPosted: Thu Jul 08, 2021 12:57 pm    Post subject: time(clock_sys) produces HH:MM:SS in Hex! Reply with quote

Hello dear Bascom members,

i work with bascom now so many many years and i was surprised to see this:

Normally a clock time which is prepared by the bascom "time" functions shows for example 12:33:43


i read the time from a 1-wire button cell, create from the 5 bytes read an timestring_rtc // 5x8bit = length 40 char

@Interrupt

1wreset : 1wwrite &HCC : 1write &H66
cval(1) = 1wread()
cval(2) = 1wread()
cval(3) = 1wread()
cval(4) = 1wread()
cval(5) = 1wread()

byte1str= bin(cval(1))
byte1str= bin(cval(2))
byte1str= bin(cval(3))
byte1str= bin(cval(4))
byte1str= bin(cval(5))

timestring_rtc = byte5str + byte4str + byte3str + byte2str // byte 1 not read bcause is header , Byte5 is MSB...Byte2 is LSB
get_rtc_irq_sec = binval(timestring_rtc // binary value from string expression
clock_sys = get_rtc_irq_sec - sum_sec_ymd // doing subtraction to get seconds of the day

time$ = time/clock_sys)


as far as nice, in 99,8% everything of that code runs nice and in the VFD Dsiplay the correct time comes up 12:43:25 for example.


But. very rare but more disturbing, the time content can be like this H1:D3:F4..........time in hex. Wow.
If i reboot, it dissapeares and normal time is shown.


I have to add, that these whole routine is IRQ driven, so if GPS second pulse come in, the subroutine is executed, that is essential for exact timing


The hex numbers appears very rare and only at startup of the unit. never while operation.
it is very hard to find because if you repower the unit to produce it, it never will happen. But sometimes it happens randomly and this is worse.

anybody out there having experienced this or similar effects at using "time"?
any kind of comment is very appreciated,

Thanks!
Ingolf















H1:F4:D3

[b][color=red](BASCOM-AVR version : 2.0.8.0 , Latest : 2.0.8.3 )[/b][/color]
Back to top
View user's profile Visit poster's website
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2156

netherlands.gif
PostPosted: Thu Jul 08, 2021 8:51 pm    Post subject: Reply with quote

Hi,
Hard to say what could be going wrong without sharing us the mcu your are using, stack and frame size, declaration of you variable and a compilable example.

This is what I find strange so far:
byte1str is overwritten by bin(cval(2)) and then by bin(cval(3)) and then by the next one.

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Fri Jul 09, 2021 7:45 am    Post subject: Re: time(clock_sys) produces HH:MM:SS in Hex! Reply with quote

uhrmacher wrote:
Code:
time$ = time/clock_sys)

Time$ expects a string and not the result of a division, and as Evert wrote: multiple consecutive assignments to the same variable are nonsense.
Thus it's to assume this is not real, but fictional code.

Neither it is nice to present fictional code to the audience, nor watchmakers with this sloppy attitude will make good watches.

There are that many reasons for the fault, especially with an 1wire-device within an interrupt.

You can do some of your homework by doing a plausibility check of the resulting time, as it's easy to check what range of the result to expect.
If the result is incorrect, push out the controller's state (interrupts pending, vars) via USART or save it to EEProm.
Back to top
View user's profile
uhrmacher

Bascom Member



Joined: 15 Sep 2005
Posts: 60
Location: Donauwoerth

germany.gif
PostPosted: Mon Aug 02, 2021 10:30 am    Post subject: Re: time(clock_sys) produces HH:MM:SS in Hex! Reply with quote

[quote="MWS"][quote="uhrmacher"][code]time$ = time/clock_sys)[/code][/quote]
Time$ expects a string and not the result of a division, and as Evert wrote: multiple consecutive assignments to the same variable are nonsense.
Thus it's to assume this is not real, but fictional code.

Neither it is nice to present fictional code to the audience, nor watchmakers with this sloppy attitude will make good watches.

There are that many reasons for the fault, especially with an 1wire-device within an interrupt.

You can do some of your homework by doing a plausibility check of the resulting time, as it's easy to check what range of the result to expect.
If the result is incorrect, push out the controller's state (interrupts pending, vars) via USART or save it to EEProm.[/quote]



I'sorry confusing you with an typo, the correct line is:


time$=time(clock_sys)
Back to top
View user's profile Visit poster's website
uhrmacher

Bascom Member



Joined: 15 Sep 2005
Posts: 60
Location: Donauwoerth

germany.gif
PostPosted: Mon Aug 02, 2021 11:09 am    Post subject: Reply with quote

[quote="Evert Smile"]Hi,
Hard to say what could be going wrong without sharing us the mcu your are using, stack and frame size, declaration of you variable and a compilable example.

This is what I find strange so far:
[b]byte1str[/b] is overwritten by [b]bin(cval(2)[/b]) and then by[b] bin(cval(3)[/b]) and then by the next one.[/quote]



Hi Evert,

i apologize for not posting the complete code but it is used within an unit of our flight test equipment and company policy rules restrics me to make the whole code public. Honestly i dont want to bother the forum colleages with over 3000 lines.... Smile
so i paste here the relevant part:




the header is:

$regfile = "m2561def.dat"
$HWStack = 512
$SWStack = 512
$Framesize = 2048
$crystal = 14745600
$lib "i2c_twi.lbx"
$loadersize = &H1F000


dim cval(5) as byte ' 5 byte array of the i-Button realtime clock
dim byte1str as string*8
dim byte2tr as string*8
dim byte3str as string*8
dim byte4str as string*8
dim byte51str as string*8

dim timestring_rtc as string * 40
dim get_rtc_irq_sec as dword
dim clock_sys as long


1wreset : 1wwrite &HCC : 1wwrite &H66
cval(1) = 1wread()
cval(2) = 1wread()
cval(3) = 1wread()
cval(4) = 1wread()
cval(5) = 1wread()

byte1str = bin(cval(1)
byte2str = bin(cval(2)
byte3str = bin(cval(3)
byte4str = bin(cval(4)
byte5str = bin(cval(5)


timestring_rtc = byte5str+byte4str+byte3str+byte2str ' MSB....LSB, byte1 is only control byte and therefore discarded here

get_rtc_irq_sec = binval(timestring_rtc)
clock_sys = get_rtc_irq_sec
time$ = time(clock_sys)

.....continuing the start sequence....


do
.
.
.
loop
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum