monkeyhead
Member
So I've got an SLC 5/02 that I need to do some up/downtime counters with. But I also want to reset the counts at shift changes and keep track of a few days worth of Data automatically.
Since the 5/02 doesn't have a real time clock, I set up a fairly slick STI interrupt, that's suprisingly accurate, to keep track of the time and increment the minutes, hours, days, etc. Problem is that if the PLC is off, the clock stops. I then realized that the UniOp touchscreen has a hardware clock and writes the date and time to the PLC's memory.
The date is written as two bytes to N7:105 for month and day, and one byte to the high bits of N7:106 for the year. Then the time is written in 00:00:00 format. Each digit occupies 4 bits. The hours are the lower byte of N7:106. The first 4 bits represent the 10's position and the the last 4 bits represent the 1's position of the of the hours (does this qualify as BCD?). Then the 16 bits of N:107 are used to represent each of the remaing four digits for minutes and seconds.
I set up a goofy JSR that runs once the PLC and the HMI are talking after a power up to sync my STI based clock with the hardware clock in the UniOp. It's basically a bunch of bitwise AND insturctions (AND with - F000H, 0F00H, 00F0H, or 000FH) to pick out each of the digits of the clock that I want and then I bit shift the result so the signifigant numbers occupy the lowest four bits of the register. Then I multiply the 10's position by 10 and add the 1's position to it.
Long story, but the point is... is there an easier way to do this? I know this works, but it comes off as kludgy to me. Seems like I should be able to accomplish this much easier than using a bunch of ANDs and BSRs. It's definately not an 'ol electrician friendly routine. I ended up giving the whole silly mess it's own file because of how many rungs it took up.
Any ideas on how I might accomplish this more elagantly?
Since the 5/02 doesn't have a real time clock, I set up a fairly slick STI interrupt, that's suprisingly accurate, to keep track of the time and increment the minutes, hours, days, etc. Problem is that if the PLC is off, the clock stops. I then realized that the UniOp touchscreen has a hardware clock and writes the date and time to the PLC's memory.
The date is written as two bytes to N7:105 for month and day, and one byte to the high bits of N7:106 for the year. Then the time is written in 00:00:00 format. Each digit occupies 4 bits. The hours are the lower byte of N7:106. The first 4 bits represent the 10's position and the the last 4 bits represent the 1's position of the of the hours (does this qualify as BCD?). Then the 16 bits of N:107 are used to represent each of the remaing four digits for minutes and seconds.
I set up a goofy JSR that runs once the PLC and the HMI are talking after a power up to sync my STI based clock with the hardware clock in the UniOp. It's basically a bunch of bitwise AND insturctions (AND with - F000H, 0F00H, 00F0H, or 000FH) to pick out each of the digits of the clock that I want and then I bit shift the result so the signifigant numbers occupy the lowest four bits of the register. Then I multiply the 10's position by 10 and add the 1's position to it.
Long story, but the point is... is there an easier way to do this? I know this works, but it comes off as kludgy to me. Seems like I should be able to accomplish this much easier than using a bunch of ANDs and BSRs. It's definately not an 'ol electrician friendly routine. I ended up giving the whole silly mess it's own file because of how many rungs it took up.
Any ideas on how I might accomplish this more elagantly?