no-software internal RTC

Current solutions and designs.
Petari
Trusted Guru
Trusted Guru
Posts: 558
Joined: Tue Nov 28, 2017 1:32 pm

Re: no-software internal RTC

Post by Petari » Tue Jul 17, 2018 1:34 pm

I traced it down, and looked in literature - ProfiBuch has all needed except TOS code .

So, time, date goes to, comes from IKBD chip in packed BCD format. Every value is 1 byte - year, month, day, hours, minutes, secs. - total 6 bytes.
And that means too, that max year span is 100 years - 0 to 99 . Values over 99 are invalid, so supposed $B8 is bad. Or any value what contains not 0-9 cypher. And max 99 is OK - that means that max year value would be 1980+99 = 2079 . And why it is not so in reality ? Because TOS coders had again some 'great' solution - their TOS code (I looked 1.04) adds $80 to packed BCD value of year before writing it to IKBD, so it will keep real year (of century), after xx80. But that lowered year span to only 20 . After reading year from IKBD, BCD value is converted to binary and $50 is subtracted - what is same - 80 .
I made quick test by removing those 2 operations in TOS 1.04 and with it IKBD chip really handles well year 2018, or 2066 ... Problem solved.
Another TOS fix is done . What I know is that it must be little different in 2.06, but that for some other time .
There is 2 kind of people: one thinking about moving to Mars after here becomes too bad, the others thinking about how to keep this planet habitable.

tzok
Posts: 88
Joined: Sat Dec 30, 2017 2:27 pm

Re: no-software internal RTC

Post by tzok » Mon Aug 27, 2018 1:38 pm

Today I've finally done some tests.

First of all - it works!
Petari wrote:
Tue Jul 17, 2018 1:34 pm
Values over 99 are invalid, so supposed $B8 is bad.
I've checked that and although IKBD won't accept or would never send a year byte higher than 0x99, yet TOS 1.62 and 2.06 will accept and correctly handle such values.

My simple solution works without ANY additional software only on TOS 2.06, on TOS 1.62 it requires CONTROL.ACC to be loaded, otherwise TOS won't query the IKBD about the date, on TOS 1.00 it does not work at all.

There is absolutely no problem with a year byte of 0xB8 (for 2018) and TOS displays it correctly (as file creation time, and also in control panel and software like SysInfo). IKBD ignores all values higher than 99, but TOS correctly handles such responses from IKBD.

Here is a sample Arduino code for injecting a static date/time into IKBD<->ST transmission.
Wiring is as follows:
ARD_RX0 from KB_5
ARD_TX1 to ST_5
ARD_D10 from/to KB/ST_6

Wire no 5 has to be cut, and the KB side goes to RX0, while ST side goes to TX1, rest of the wires remain intact. Command listening is on pin 6, pin 1 is GND and pin 4 is 5V (can be used to feed the Arduino).

Code: Select all

#include <SoftwareSerial.h>

// software serial : RX = digital pin 10, TX = digital pin 11
SoftwareSerial Control(10, 11);
int inject = -1;
byte date[7] = {0x13, 0x42, 0x12, 0x27, 0x08, 0xB8, 0xFC};

void setup()
{

    // write your setup code here, to run once
    pinMode(LED_BUILTIN, OUTPUT);
    Serial.begin(7812);
    Control.begin(7812);
    Control.listen();

}

void loop()
{

    // write your main code here, to run repeatedly
    
    if (Control.available()) {
      if (Control.read() == 0x1C) {
        inject = 6;
        digitalWrite(LED_BUILTIN, HIGH);
      }
    }
        
    if (Serial.available()) {
                if (inject == -1)
                  Serial.write(Serial.read());
                else {
                  Serial.read();
                  Serial.write(date[inject--]);
                  if (inject== -1) digitalWrite(LED_BUILTIN, LOW);
                }
    }
}

Petari
Trusted Guru
Trusted Guru
Posts: 558
Joined: Tue Nov 28, 2017 1:32 pm

Re: no-software internal RTC

Post by Petari » Mon Aug 27, 2018 2:16 pm

tzok wrote:
Mon Aug 27, 2018 1:38 pm
...
My simple solution works without ANY additional software only on TOS 2.06, on TOS 1.62 it requires CONTROL.ACC to be loaded, otherwise TOS won't query the IKBD about the date, on TOS 1.00 it does not work at all.

There is absolutely no problem with a year byte of 0xB8 (for 2018) and TOS displays it correctly (as file creation time, and also in control panel and software like SysInfo). IKBD ignores all values higher than 99, but TOS correctly handles such responses from IKBD.
...
So, what year is then that value $B8 ? 2018 - by what calculation ? It would be 11x10 + 8 + 1980 ... Or maybe just (11-8)x10 + 8 + 1980 .
TOS 1.04 and 1.62 have same code for IKBD chip date/time.
You should test will it switch to correct next year at midnight of Dec 31 . I mean "absolutely no problem" - maybe should wait with such statements.
In any case it is not according to docs I seen in ProfiBuch . Probably just some side effect.
There is 2 kind of people: one thinking about moving to Mars after here becomes too bad, the others thinking about how to keep this planet habitable.

tzok
Posts: 88
Joined: Sat Dec 30, 2017 2:27 pm

Re: no-software internal RTC

Post by tzok » Mon Aug 27, 2018 3:01 pm

Petari wrote:
Mon Aug 27, 2018 2:16 pm
You should test will it switch to correct next year at midnight of Dec 31 .
23:59:00 31.12.2019 (0xFC, 0xB9, 0x12, 0x31, 0x23, 0x59, 0x00) TOS 2.06 and CONTROL.ACC:


tzok
Posts: 88
Joined: Sat Dec 30, 2017 2:27 pm

Re: no-software internal RTC

Post by tzok » Tue Aug 28, 2018 10:28 am

Petari wrote:
Tue Jul 17, 2018 1:34 pm
Because TOS coders had again some 'great' solution - their TOS code (I looked 1.04) adds $80 to packed BCD value of year before writing it to IKBD, so it will keep real year (of century), after xx80. But that lowered year span to only 20 . After reading year from IKBD, BCD value is converted to binary and $50 is subtracted - what is same - 80 .
Maybe internally it is done like so, but I've captured an actual communication between ST and IKBD and if you set year 1999, a value of 0x99 is set for a year byte, same for reading a date. It also works for years over 1999, where values like 0xA0 are sent for 2000 ans so on, but IKBD ignores such entries. These are however dependent on the software used to set the clock. TOS itself maybe is keeping only a number of years after 1980, but IKBD keeps actual year. TOS doesn't pool the IKBD regularly for date/time - it keeps its own clock. For some reason SysInfo doesn't change/refresh a date at midnight at all.

Petari
Trusted Guru
Trusted Guru
Posts: 558
Joined: Tue Nov 28, 2017 1:32 pm

Re: no-software internal RTC

Post by Petari » Tue Aug 28, 2018 10:41 am

tzok wrote:
Tue Aug 28, 2018 10:28 am
Petari wrote:
Tue Jul 17, 2018 1:34 pm
Because TOS coders had again some 'great' solution - their TOS code (I looked 1.04) adds $80 to packed BCD value of year before writing it to IKBD, so it will keep real year (of century), after xx80. But that lowered year span to only 20 . After reading year from IKBD, BCD value is converted to binary and $50 is subtracted - what is same - 80 .
Maybe internally it is done like so, but I've captured an actual communication between ST and IKBD and if you set year 1999, a value of 0x99 is set for a year byte, same for reading a date. It also works for years over 1999, where values like 0xA0 are sent for 2000 ans so on, but IKBD ignores such entries. These are however dependent on the software used to set the clock. TOS itself maybe is keeping only a number of years after 1980, but IKBD keeps actual year. TOS doesn't pool the IKBD regularly for date/time - it keeps its own clock. For some reason SysInfo doesn't change/refresh a date at midnight at all.
Sorry, but I see contradiction in what you write: "but IKBD ignores such entries" - how can it work if it ignores it ? Yes, TOS uses own clock. But it must start with something after power on. At 1.02 it will try to read Ricoh (present in Mega ST, Mega STE) chip if available.
IKBD can not keep actual year, only year in century. I guess that CONTROL.ACC just writes there real value, without +80, so is good for years over 1999. And then it is not 'no-software internal RTC' :D
There is 2 kind of people: one thinking about moving to Mars after here becomes too bad, the others thinking about how to keep this planet habitable.

tzok
Posts: 88
Joined: Sat Dec 30, 2017 2:27 pm

Re: no-software internal RTC

Post by tzok » Tue Aug 28, 2018 1:01 pm

My solution works without any software on TOS 2.06. On TOS 1.04 and 1.06/1.62 it requires CONTROL.ACC. IKBD ignores bytes higher than 0x99, allowing to set only an hour or day (rest of fields have to be set to 0xFF or 0xAA or whatever value higher than 0x99). However my solution is to intercept these requests and substitute own answers. Both TOS 2.06 and CONTROL.ACC correctly interpret year 0xB8 as 2018 in both directions - when reading from IKBD and when writing to IKBD.

Petari
Trusted Guru
Trusted Guru
Posts: 558
Joined: Tue Nov 28, 2017 1:32 pm

Re: no-software internal RTC

Post by Petari » Tue Aug 28, 2018 1:11 pm

Congratulations. You solved it without understanding how it works. That must be not bad thing.
I gave you explanation why it works not in 1.04-1.62 .
I think that thread title is not exactly correct.
There is 2 kind of people: one thinking about moving to Mars after here becomes too bad, the others thinking about how to keep this planet habitable.

tzok
Posts: 88
Joined: Sat Dec 30, 2017 2:27 pm

Re: no-software internal RTC

Post by tzok » Tue Aug 28, 2018 2:50 pm

Petari wrote:
Tue Aug 28, 2018 1:11 pm
I gave you explanation why it works not in 1.04-1.62 .
Because Rainbow TOS itself won't query the IKBD for a current time? I don't see this 0x50 being added/subtracted while communicating with IKBD. As I said - I was physically intercepting communication between ST and IKBD and values sent by/to IKBD are just a BCD encoded years (actually it is a compressed BCD - 2 digits in 1 byte).

Petari
Trusted Guru
Trusted Guru
Posts: 558
Joined: Tue Nov 28, 2017 1:32 pm

Re: no-software internal RTC

Post by Petari » Tue Aug 28, 2018 3:15 pm

tzok wrote:
Tue Aug 28, 2018 2:50 pm
Petari wrote:
Tue Aug 28, 2018 1:11 pm
I gave you explanation why it works not in 1.04-1.62 .
Because Rainbow TOS itself won't query the IKBD for a current time? I don't see this 0x50 being added/subtracted while communicating with IKBD. As I said - I was physically intercepting communication between ST and IKBD and values sent by/to IKBD are just a BCD encoded years (actually it is a compressed BCD - 2 digits in 1 byte).
Obviously you did not read what I wrote, and you don't care for. How can you see what is added and what not by looking only signals and not code ?
But I don't see any reason to discuss further here ...
There is 2 kind of people: one thinking about moving to Mars after here becomes too bad, the others thinking about how to keep this planet habitable.

Post Reply