Author Topic: HST  (Read 15257 times)

artkraft

  • Newbie
  • Posts: 22
  • I'm a llama!
    • View Profile
HST
« on: October 05, 2017, 06:59:20 AM »
How do I use a Cf to create 2 HST and keep that setting with loss of power or reset. I understand that I need HSTIMER 2. I have this CF called on 1st scan
 // Initialize parameters
Setsystem 4,3 ' Enable enhanced high-speed counter modes

// Setbaud 1, 6
Setbaud 3, 4  '19200 baud to HMI panel

DM[200]=192
DM[201]=168
DM[202]=0
DM[203]=210
DM[204]=9080

//Set_IPAddr 200

DM[205]=255
DM[206]=255
DM[207]=255
DM[208]=0

//Set_Subnet 205

//SetSystem 252,0
Can I add syntax here ?

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:HST
« Reply #1 on: October 05, 2017, 11:16:04 AM »
Art,

You probably need to add the following sort of statements to your startup up CF to enable the high speed counters #1 and #2:
Code: [Select]
' InitHSC - Initialize High Speed Counters that are used by the turbine flow sensors
'
' The first argument is the high speed counter number 1..3
'
' The second argument is the custom function to be called when the counter reaches the
' value specified by the third argument. This custom function is responsible for
' keeping the running total of gallons and for resetting the high speed counter back to 0
' to start counting the next gallon.
'
' The third argument is the number of pulses per gallon
' &H7ffffff is a really large positive integer that effectively disables the interrupt from ever
' being called. The interrupt mechanism is buggy in F91.2 (Fx series PLCs).
' I am periodically polling the high speed counters and directly managing their count values
' without using the interrupt CFs mechanism as a work-around for the F91.2 issues.
'
HSCDEF  1, TotalizeProdFlw,  &h7fffffff
HSCDEF  2, TotalizeBrineFlw, &h7fffffff

' Reload counter values from EEPROM
'
HSCPV[1] = Load_EEP32(HSC1EEPAddr)
HSCPV[2] = Load_EEP32(HSC2EEPAddr)

You will need to add a CF to save the count values of your high speed counters to non-volatile memory.  You have to decide when to save the count values. You can set up a CF that saves the values periodically or based on the power fail interrupt. The CF to save the values would look something like this:
Code: [Select]
Save_EEP32 HSCPV[1], HSC1EEPAddr
Save_EEP32 HSCPV[2], HSC1EEPAddr

Gary D*ckinson

artkraft

  • Newbie
  • Posts: 22
  • I'm a llama!
    • View Profile
Re:HST
« Reply #2 on: October 05, 2017, 03:04:00 PM »
I have HSC I want High Speed Timer

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:HST
« Reply #3 on: October 05, 2017, 08:48:13 PM »
If you put HSTIMER 2 on an INIT custom function invoked by 1st.Scan then every time the PLC is reset the high speed timer 1 and 2 will be enabled.

However, the present values of the timers are not saved when power is lost.

If you need to keep the present values of these two timers you could set up a power failure interrupt (see INTRDEF function) and inside the power failure interrupt service routine  you can save the present values of the two timers to FRAM area.

Inside the INIT function you will then load the timer's present value from the FRAM location that holds the previous data. This way the high speed timer can resume its count down after a power failure or reboot.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:HST
« Reply #4 on: October 05, 2017, 09:15:06 PM »
Art,

Sorry, I misread your question.

About all that makes sense for High Speed Timers is to put the "HSTIMER 2" statement in a custom function that is called on the first scan of the ladder logic.  

I see no reason to save the PV (present value) for a TIMER and attempt to restore it after the PLC reboots.

The Set Value of the TIMER is defined by in the I/O table and will be initialized when the PLC restarts.  

If, however, your program changes the SV for TIMERs and COUNTERs during the execution of the code and you need to restore the changed SV, then you need to save to EEPROM and restore the SV of these items.  

I do change the SV for TIMERs and COUNTERs to values other than what is defined in the "I/O Table" while the PLC is running.  I have clients that need to customize the behavior of a PLC based system for specific clients.  Rather than writing a different PLC program for each of these customers, I have the PLC read the system configuration from an ASCII text file stored in the PLC filesystem.  This configuration file can be changed either via the HMI attached to the PLC or by uploading via FTP a new configuration file.

I do use High Speed Timers in my PLC programming.  But I am very careful to ensure that the worst case scan time through my ladder logic program is less than the time-base of the TIMERs to ensure that the TIMER is reasonably accurate.  

Sorry for not reading your question correctly.

Gary D*ckinson
« Last Edit: October 05, 2017, 09:23:00 PM by garysdickinson »