Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - garysdickinson

Pages: 1 ... 7 8 [9] 10 11 ... 34
121
Technical support / Re:week number
« on: January 09, 2018, 08:00:23 PM »
I am glad that you have a good working algorithm.

As a suggestion, there are more direct ways to determine if something can be divided by 4 without a remainder.

Your code sample:

'PUT DATE IN M$
M$ = STR$(DATE[1])
'DIVIDE YEAR NUMBER BY 4
M# =VAL(M$)/4.0
'PUT NUMBER INTO STRING
N$ = STR$(M#)
'PUT FIRST DECIMAL PLACE INTO O$
O$ = MID$(N$,6,1)
'IF DECIMAL IS ZERO, THEN SET LEAP YEAR
IF VAL(O$) = O THEN
SETIO LEAP_YEAR
ELSE CLRIO LEAP_YEAR
ENDIF
[/color]

Could probably be written in a much more direct way using the modulo (MOD) operator:

If (DATE[1] MOD 4)
   ClrIO LEAP_YEAR
else
   SetIO LEAP_YEAR
endif
[/color]

I'm certain that you are aware that your algorithm for determining leap year is not technically correct as it will fail on some years that are divisible by 100.

The only other thing that you should give a little bit of thought to is the accessing of the DATE[] and TIME[] registers.  The issue is that you access these registers multiple times in your algorithm.  The values in these registers are updated by PLC low-level firmware and it is possible for the register values to change between the first and last access that your CF makes to these registers.  For the DATE[] registers these changes tend to happen at the last second of the day.  The worst case is on the last day of the year 31-12-2018 the registers will update to 1-1-2019 and it is possible for your PLC software to read a mixture of the old and new date as the registers are updated one at a time.

One approach is to use the SETSYSTEM 253,0    to shut down updates of the RTC registers, read all of the DATE[] registers and store the values, store them in DM[] and then use the SETSYSTEM 253,1 statement to turn back on the RTC registers.

Another approach is to NOT access the DATE[] registers around midnight.

Best regards,

Gary D*ckinson

122
Technical support / Julian Date Algorithm for TRI PLC
« on: January 04, 2018, 07:44:41 PM »
This is the PLC code that I use to calculate the Julian date:

' GenJD - custom function to compute Julian Date.
'  Algorithm agrees with USNO (United States Naval Observatory) online Julian Date Converter
'  at http://aa.usno.navy.mil/data/docs/JulianDate.php
'
' 9/17/2013 is JD 2456553
'
' On entry:
'   I = year 2013
'   J = month 1..12
'   K = day of month
'
' On exit:
'   A holds Julian date
'
A = K-32075+1461*(I+4800+(J-14)/12)/4+367*(J-2-(J-14)/12*12) /12-3*((I+4900+(J-14)/12)/100)/4
[/color]

I didn't write this stuff, I just trans-coded it form FORTRAN to TBASIC.

OK how to you use it to calculate how many days into 2018 the date, February 1 occurs.

Set: I = 2018   ' year
Set: J = 2         ' month
Set: K = 1        ' day

Then run the algorithm.  The answer should be 2458150.

Now calculate the Julian date for January 1, 2018. This answer should be 2458119.

Now you can calculate how many days into 2018 February 1st is by a bit of subtraction:

31 = 2458150 - 2458119

Now you know that you February 1, 2018 is the 31 day in 2018 (the first day is day 0).

And if you will find that a bit of division will give you the week into 2018 that February 1 is the 5th week in 2018:

5 = 31 / 7 + 1

Pretty slick.  

If you definition of week number is for weeks that start on a set day like Monday, then you will need to adjust the algorithm.  2018 started on a Monday, but 2019 will not.

Work weeks or factory weeks, usually, have some interesting rules. Google "ISO 8601" for the international standards for counting weeks within a year.  I'll bet you didn't know the first week in the year must have a Thursday...otherwise the first few days of the year belong to the last week of the previous year.  Obviously!

I'll give you a bit of a hint about what you might consider.  The Julian date algorithm starts at the following date:  Tuesday, 4713 B.C. Jan 2

Day 0 was Tuesday.   Every seven days since Day 0 will be a Tuesday.  So you can take any Julian date and MOD it by 7 and the resulting value (0..7) will represent the days Tuesday, Wednesday..Monday.

Best regards

Gary D*ckinson

123
Technical support / Re:week number
« on: January 04, 2018, 07:04:27 PM »
"Quick" is up to you to decide.

If you start counting at 0 until you get to the current day of the year, then you know how many days have passed since the first of the year.  Take that number and divide it by 7 and add 1 to get the week into the year that the current day represents.

OK.  Pretty simple.

The more difficult bit is to quickly calculate the day number within a year based on knowing the month, day of month and year.  Oh and you need to know the number of days in each month and you need to know if you need to deal with February that may have 28 or 29 days.

The solution is "Julian Dates". I'll present the TBASIC algorithm to calculate Julian Dates in the next post.  

Gary D*ckinson

124
Technical support / Re:One Wire Sensors
« on: December 15, 2017, 02:15:52 PM »
I would suggest using a low cost micro controller such as an audrino based system.  Interconnect the audrino and the PLC via RS232/RS485.

Have the audrino handle all of the one-wire, I2C, SPI ... communicators. The audrino can handle this stuff fairly easily.

The PLC doesn’t get involved with the bit fiddling but just gets the data it needs from the audrio via the serial interconnect.

Gary D*ckinson

125
Technical support / Re:Tic Tac Toe game for PLC
« on: December 14, 2017, 10:43:37 AM »
Lorne,

I am glad that you enjoyed my post. My PLC programming is “recreational”.

I try to share ideas on how to get the most out of the TRI PLCs. Three of the most powerful features of these PLCs, in my opion, is the specialized counters (Sequencers), the TBASIC programming language and the raw horse power of the 32-bit CPU core that is buried in the PLC.  

I had started to write a tutorial on using the Sequencers as the basis of finite element state machines over 10 years ago, but never got very far.

The Tic Tac Toe gave was, initially, written using only a single state machine.  I wrote all of the game strategy (checking for win, block, special moves...) using custom functions.  The use of CFs is much simpler to write and debug.  Once I got the game strategy working I replaced the CFs with ladder logic.

I thought that Tic Tac Toe was a better vehicle to give people a hint of the power of using state machines in PLC code.  All of my PLC code is based on this sort of state machine approach.  My code has logged hundreds of thousands of hours for my clients without problems.  And, better yet, years later I can add fetatures to old PLC programs with ease.

As, always, if you have questions about how to get the PLC to do your bidding, please feel free to ask.

Best regards,

Gary D*ckinson

126
Technical support / Re:Tic Tac Toe game for PLC
« on: December 11, 2017, 03:18:32 PM »
I broke up the documentation over the next 5 posts to attempt to stay under the 200K file size limitiation

Best regards

Gary D*ckinson

127
Technical support / Re:Tic Tac Toe game for PLC
« on: December 11, 2017, 03:17:44 PM »
I broke up the documentation over the next 5 posts to attempt to stay under the 200K file size limitiation

Best regards

Gary D*ckinson

128
Technical support / Re:Tic Tac Toe game for PLC
« on: December 11, 2017, 03:17:31 PM »
I broke up the documentation over the next 5 posts to attempt to stay under the 200K file size limitiation

Best regards

Gary D*ckinson

129
Technical support / Re:Tic Tac Toe game for PLC
« on: December 11, 2017, 03:17:18 PM »
I broke up the documentation over the next several posts to attempt to stay under the 200K file size limitiation

Best regards

Gary D*ckinson

130
Technical support / Re:Tic Tac Toe Documentation
« on: December 11, 2017, 03:16:56 PM »
I broke up the documentation over the next 5 posts to attempt to stay under the 200K file size limitiation

Best regards

Gary D*ckinson

131
Technical support / Re:HMI code for Tic Tac Toe
« on: December 08, 2017, 11:42:34 AM »
I've attached a zip file for the Wientek HMI code for the Tic Tac Toe Game.

This code is written for one of the 7" Wientek HMI's.  You can rework it to fit on the smaller 4.3" HMI.

The HMI code communicates with the PLC via an RS-232 connection and uses Modbus RTU protocol.  If you want to use this code, be certain that the PLC's RS-232 port is set up for 38.4K BAUD, 8 bit data, no parity and 1 stop bit.  This is the default (as shipped) data rate on the TRI PLCs.

If you want to run this HMI code and connect it to the NANO-10, you will need to modify the HMI program to use the RS-485 connection to communicate to the PLC.  Modbus RTU and 38.4K, 8N1 setup for both serial ends of the cable.

Please note that the PC6 program does not initialize the PLC's serial port.  You may want to add a custom function that runs on the first scan to initialize the serial port.  I was just being a bit lazy.

Gary D*ckinson

132
Technical support / Tic Tac Toe game for PLC
« on: December 08, 2017, 11:35:22 AM »
I got bored.  So I wrote PLC program to play Tic Tac Toe (Noughts and Crosses).  

The game will run on any of the current TRI PLCs.  The program does not use any physical INPUTs or OUTPUTs. You could run it with a Nano-10.  The game can be played using the on-line monitor or using a touch screen HMI.  I'll put up the code for the Weintek HMI that I am using in a future post.

The game is written in 99.9% ladder logic.  It is a good demo of the use of PLC sequencers to implement finite element state machines.

I'll put up some documentation that helps explain my use of state machine design and the PLC sequencer mechanism.

I've attached the PC6 program to this posting.

Gary D*ckinson

133
Technical support / Re:INTRDEF
« on: November 16, 2017, 02:55:55 PM »
Lorne,

The scan time of the PLC is not a fixed rate.  It is dependent of a number of things, including:
  • The number of I/O ports that the PLC is supporting.
  • The size and complexity of the ladder logic program that you created
  • The amount of time that the ladder is suspended waiting for your custom functions to execute.
  • The overhead of the PLC low level firmware.
  • Are you using online monitoring for debug.  On-line monitoring is constantly "talking" to the PLC low level firmware to get data to display.  This takes time.
  • And a bunch of other stuff...

The maximum scan rate that the Fx (Smart Tile) PLC can achieve is surprisingly fast if your PLC program is trivial.

There are a couple of things that you can do to monitor the scan rate of your program:
1. Add ladder logic that toggles the state of an OUTPUT on each scan.  You can monitor this pin using an oscilloscope or logic analyzer.  I have attached the ladder logic for this approach.
2. Add a CF that is invoked on every scan of the ladder logic.  This CF records the current CPU time and on each subsequent call will calculate the time between scans.  You can keep track of the min, max and average scan times.   The function, STATUS(21) returns a 32-bit number that is in the units of 0.1us.

You put this sort of code in a CF that is called on every ladder scan:

A = Status(21)   ' current CPU time
C = ABS(A - B)    ' scan time in C, 0.1 us units
B = A                  ' save current CPU time for next call to this CF


I hope that this is useful.

Best regards,

Gary D*ckinson

134
Technical support / Re:Update to i-TRiLOGI
« on: November 09, 2017, 08:37:05 AM »
Thanks for the hint.  The html file directs me to a working web page on your site.

Gary d

135
Technical support / Update to i-TRiLOGI
« on: November 07, 2017, 06:25:15 PM »
I just tried to see if a new update to the i=TrRiLOGI software was available by clicking

Help->TRiLOGI Update  (from i-TRiLOGI V 7.12 Build 04)

This opened my default web browser  with this URL: http://www.triplc.com/TRiLOGI/Help/upgrade.htm

Unfortunately this URL cannot be found and my browser returned a 404 error.

I assume that things are in flux and I will check back later.

Best Regards,

Gary D*ckinson

Pages: 1 ... 7 8 [9] 10 11 ... 34