Attribute VB_Name = "Module1"
'#Uses "..\classes\FunctionClass.cls"
'#Uses "..\classes\ParameterClass.cls"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Pages.inc"
'#Uses "..\include\Port.inc"
'#Uses "Include.inc"

Option Explicit
'*****************************************************************************
' Module:
'        GPT2
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'GPT2'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ----------------------------------------------------------------------
'        2.0   ahe         13.06.00     final version for C167CS
'
'        ----------------------------------------------------------------------
'        2.1   ahe         02.08.00     final version for C167CS and C161CS/JC/JI
'                                       - check if T5EUD and T6EUD exists
'              ahe         03.08.00     - added GPT2-vInit disabled if modul is
'                                         is disabled
'
'              ahe         04.09.00     - changes
'                                         Call ReleaseAlternateInputPin(r, "CAP")
'                                         to Call ReleaseAlternateInputPin(r, "CAPIN")
'                                        - added T5CON_T5SC = 0 and T5CON_T5CLR = 0 in
'                                          optDISx_1 action
'
'              ahe         04.10.00     - added 'Call DisableSRN(r, "GPT2", "CRIC", "CRIE", "CAPREL")'
'                                         in action for optCI_0
'
'        ---------------------------------------------------------------------
'              ahe         25.10.00    final version for
'                                      - C167CS
'                                      - C161CS/JC/JI
'                                      - C167CR/SR r2
'
'              ahe         25.10.00    changes the Modul Clock Pages (check SYSCON3)
'
'        ----------------------------------------------------------------------
'        5.0   ahe         19.04.01     final version for Pegasus
'
'        5.1   ahe         08.08.02     - neu interrupt page
'                                       - changed page name
'        5.2   ste         24.02.03    caption for module clock changed
'
'*****************************************************************************

Const MSG_GPT_DISABLE = "If you disable the module clock the configuration of the GPT1 AND GPT2" & vbCrLf & _
                        "modules will be reseted. Do you really want to continue ?"

'*****************************************************************************
'Description:
'        This function is called from DAvE just before the Peripherals
'        window is shown.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnLoad(ps As Peripherals) As Boolean
    On Error GoTo OnLoadError

    OnLoad = False

    '-------------------------------------------------------------------------
    ' page: ModuleClock
    '-------------------------------------------------------------------------
    If (Not OnLoadPageModuleClock(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: AuxiliaryTimerx
    '-------------------------------------------------------------------------
    If (Not OnLoadPageAuxiliaryTimer5(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: CoreTimer3
    '-------------------------------------------------------------------------
    If (Not OnLoadPageCoreTimer6(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: CaptureReload
    '-------------------------------------------------------------------------
    If (Not OnLoadPageCaptureReload(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnLoadPageInterrupts_32(ps, 0)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnLoadPageInterrupts_32(ps, 1)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: PEC
    '-------------------------------------------------------------------------
    If (Not OnLoadPagePEC(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions
    '-------------------------------------------------------------------------
    If (Not OnLoadPageFunctions(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnLoadPageParameters(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Notes
    '-------------------------------------------------------------------------
    If (Not OnLoadPageNotes(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' end of pages
    '-------------------------------------------------------------------------
    
    '-------------------------------------------------------------------------
    ' call function to initialize the menu
    '-------------------------------------------------------------------------
    If (Not InitMenu(ps, "GPT2\Dialog")) Then Exit Function

    OnLoad = True
    Exit Function

OnLoadError:
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE just before a page
'        is shown.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Page            no. of the page (starts with 1)
'        Pagename        name of the page
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPage(ps As Peripherals, Page As Integer, Pagename As String) As Boolean
    On Error GoTo OnChangingPageError
    Dim sVarPre As String
    sVarPre = "GPT2"

    OnChangingPage = False

    '-------------------------------------------------------------------------
    ' page: ModuleClock
    '-------------------------------------------------------------------------
    If (Not OnChangingPageModuleClock(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: AuxiliaryTimerx
    '-------------------------------------------------------------------------
    If (Not OnChangingPageAuxiliaryTimer5(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: CoreTimer3
    '-------------------------------------------------------------------------
    If (Not OnChangingPageCoreTimer6(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: CaptureReload
    '-------------------------------------------------------------------------
    If (Not OnChangingPageCaptureReload(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnChangingPageInterrupts_32(ps, Pagename, 0)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnChangingPageInterrupts_32(ps, Pagename, 1)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: PEC
    '-------------------------------------------------------------------------
    If (Not OnChangingPagePEC(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Functions
    '-------------------------------------------------------------------------
    If (Not OnChangingPageFunctions(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnChangingPageParameters(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Notes
    '-------------------------------------------------------------------------
    If (Not OnChangingPageNotes(ps, Pagename, sVarPre)) Then Exit Function


    OnChangingPage = True
    Exit Function

OnChangingPageError:
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE in two cases:
'
'        1.
'            The contents of the peripherals window must be refreshed.
'            In this case the 'Controlname' parameter is a empty string
'            and the values array 'v()' contains nothing.
'
'        2.
'            A control on the peripherals has been changed.
'            In this case the 'Controlname' parameter contains the name
'            of the changed control and the values array 'v()' contains the
'            changed value(s).
'
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     name of the changed control (for case 2)
'        v()             array with the changed values (for case 2)
'        Page            no. of the page (starts with 1)
'        Pagename        name of the page
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnShow(ps As Peripherals, Controlname As String, v() As Variant, Page As Integer, Pagename As String) As Boolean
    On Error GoTo OnShowError
    Dim sVarPre As String
    sVarPre = "GPT2"

    OnShow = False

    '-------------------------------------------------------------------------
    ' page: ModuleClock
    '-------------------------------------------------------------------------
    If (Not OnShowPageModuleClock(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: AuxiliaryTimer5
    '-------------------------------------------------------------------------
    If (Not OnShowPageAuxiliaryTimer5(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: CoreTimer6
    '-------------------------------------------------------------------------
    If (Not OnShowPageCoreTimer6(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: CaptureReload
    '-------------------------------------------------------------------------
    If (Not OnShowPageCaptureReload(ps, Controlname, Pagename, v)) Then Exit Function
  
    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnShowPageInterrupts_32(ps, Controlname, v, sVarPre, Pagename, 0)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnShowPageInterrupts_32(ps, Controlname, v, sVarPre, Pagename, 1)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: PEC
    '-------------------------------------------------------------------------
    If (Not OnShowPagePEC(ps, Controlname, v, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions
    '-------------------------------------------------------------------------
    If (Not OnShowPageFunctions(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnShowPageParameters(ps, Controlname, Pagename, v)) Then Exit Function
       
    '-------------------------------------------------------------------------
    ' page: Notes
    '-------------------------------------------------------------------------
    If (Not OnShowPageNotes(ps, Controlname, Pagename, sVarPre, v)) Then Exit Function


    OnShow = True
    Exit Function

OnShowError:
    Errorbox "Can not show page", Err.Description
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a button.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnClick(ps As Peripherals, Controlname As String) As Boolean
    On Error GoTo OnClickError

    OnClick = False

    Dim np As Peripherals


    '-------------------------------------------------------------------------
    ' buttons: PEC
    '-------------------------------------------------------------------------
    If (Not OnClickPagePEC(ps, Controlname)) Then Exit Function


    OnClick = True
    Exit Function

OnClickError:
    Errorbox "Can not process the click", Err.Description
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a menu entry.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Toolname        name of the entry
'        ToolId          id of the entry
'        Tooltext        additional text of the entry
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnMenuClick(ps As Peripherals, Toolname As String, ToolId As Long, Tooltext As String) As Boolean
    On Error GoTo OnMenuClickError

    OnMenuClick = False

    If (Not MenuClick(ps, Toolname, ToolId, Tooltext, "GPT2\Dialog")) Then Exit Function

    OnMenuClick = True
    Exit Function

OnMenuClickError:
    Exit Function
End Function
    

'-----------------------------------------------------------------------------
' local functions
'-----------------------------------------------------------------------------
    


'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add the page 'ModuleClock'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageModuleClock(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageModuleClock = False
  Dim r       As ProjectData
  Dim sVarPre As String

  sVarPre = "GPT2"

  Set r = ps.ProjectData

  If Not (GetGPT2DisebleBitName(r, sVarPre) = "") Then
      If (Not ps.AddPage("Module Clock")) Then Exit Function
  End If

  OnLoadPageModuleClock = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPageModuleClock(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageModuleClock = False

  Dim r       As ProjectData
  Dim sVarPre As String

  sVarPre = "GPT2"

  Set r = ps.ProjectData
  
  If Not (GetGPT2DisebleBitName(r, sVarPre) = "") Then
      If (Not ps.ExtenderCollection("Module Clock").Loaded) And (Pagename = "Module Clock") Then
        ps.ExtenderCollection("Module Clock").Loaded = True
  

        '-------------------------------
        ' frame: frmMD
        '-------------------------------
        If (Not ps.AddFrame("frmMD", 100, 100, 5400, 1375, _
          "GPT Disabled Flag (" & GetGPT2DisebleBitName(r, sVarPre) & ")")) Then Exit Function
            If (Not ps.AddOption("optDISx_0", 200, 350, 4800, 380, _
              "Enable GPT1 AND GPT2 modules; the peripherals are supplied with the clock signal")) Then Exit Function
            If (Not ps.AddOption("optDISx_1", 200, 825, 4800, 380, _
              "Disable GPT1 AND GPT2 modules; the clock input of peripherals is disabled")) Then Exit Function

        '-------------------------------
        ' frame: frmInputClock
        '-------------------------------
        If (Not ps.AddFrame("frmInputClock", 100, 1600, 5400, 1000, _
          "Input Clock")) Then Exit Function
            If (Not ps.AddLabel("lbl_txt_InputClock", 0, 200, 450, 3225, 300, _
              "Input clock of the GPT2 module [MHz]")) Then Exit Function
            If (Not ps.AddLabel("lbl_box_InputClock", 1, 3550, 400, 1000, 300, "")) Then Exit Function

        '-------------------------------
        ' frame: frmBPS2
        '-------------------------------
        If (Not ps.AddFrame("frmBPS2", 100, 2700, 5400, 2200, _
          "Timer Block Prescaler 2 (BPS2)")) Then Exit Function
            If (Not ps.AddOption("optBPS2_1", 200, 300, 4800, 300, "")) Then Exit Function
            If (Not ps.AddOption("optBPS2_0", 200, 650, 4800, 300, "")) Then Exit Function
            If (Not ps.AddOption("optBPS2_3", 200, 1000, 4800, 300, "")) Then Exit Function
            If (Not ps.AddOption("optBPS2_2", 200, 1350, 4800, 300, "")) Then Exit Function
            If (Not ps.AddLabel("lbl_txt_BPS2", 0, 200, 1750, 4000, 300, "")) Then Exit Function
            If (Not ps.AddLabel("lbl_box_BPS2", 1, 4000, 1700, 1000, 300, "")) Then Exit Function


      End If
  End If
  OnChangingPageModuleClock = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageModuleClock(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageModuleClockError

  OnShowPageModuleClock = False

  Dim r         As ProjectData
  Dim c         As Object
  Dim e         As Object
  Dim sVarPre   As String
  Dim bDisabled As Boolean
  Dim vIndex    As Variant
  Dim TimerNr   As Variant
  Dim i         As Integer

  vIndex = ""
  sVarPre = "GPT2"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If Not (GetGPT2DisebleBitName(r, sVarPre) = "") Then
      If (Pagename = "Module Clock") Then
        '-------------------------------------------------------------------------
        ' page: ModuleClock (action)
        '-------------------------------------------------------------------------
        Select Case (Controlname)
            '---------------------------------------------------------------------
            ' control: optPERDISx_0 (action)
            '---------------------------------------------------------------------
            Case "optDISx_0"
                 r.v("SYSCON3_" & GetGPT2DisebleBitName(r, sVarPre)) = 0

            '---------------------------------------------------------------------
            ' control: optPERDISx_1 (action)
            '---------------------------------------------------------------------
            Case "optDISx_1"
                 If (ASK(MSG_GPT_DISABLE)) Then
                   If (Not UpdateOnePeripherals(r, "GPT1", SET_MODULE_TO_DEFAULT)) Then Exit Function
                   Call SetModuleToDefault(r)
                   r.v("SYSCON3_" & GetGPT2DisebleBitName(r, sVarPre)) = 1

                 End If

          '---------------------------------------------------------------------
          ' control: optBPS2_0 (action)
          '---------------------------------------------------------------------
          Case "optBPS2_0"
               r.v(GPT12_ & "T6CON_BPS2") = 0

          '---------------------------------------------------------------------
          ' control: optBPS2_1 (action)
          '---------------------------------------------------------------------
          Case "optBPS2_1"
               r.v(GPT12_ & "T6CON_BPS2") = 1

          '---------------------------------------------------------------------
          ' control: optBPS2_2 (action)
          '---------------------------------------------------------------------
          Case "optBPS2_2"
               r.v(GPT12_ & "T6CON_BPS2") = 2

          '---------------------------------------------------------------------
          ' control: optBPS2_3 (action)
          '---------------------------------------------------------------------
          Case "optBPS2_3"
               r.v(GPT12_ & "T6CON_BPS2") = 3

          Case Else
        End Select

        '-------------------------------------------------------------------------
        ' page: ModuleClock (show)
        '-------------------------------------------------------------------------

        '-------------------------------------------------------------------------
        ' control: optDISx_0 (show)
        '-------------------------------------------------------------------------
        With c("optDISx_0")
          bDisabled = False
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("SYSCON3_" & GetGPT2DisebleBitName(r, sVarPre)) = 0)
        End With

        With e("optDISx_0")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("")
          End If
        End With

        '-------------------------------------------------------------------------
        ' control: optDISx_1 (show)
        '-------------------------------------------------------------------------
        With c("optDISx_1")
          bDisabled = False
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("SYSCON3_" & GetGPT2DisebleBitName(r, sVarPre)) = 1)
        End With

        With e("optDISx_1")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("")
          End If
        End With
        '-------------------------------------------------------------------------
        ' control: lbl_txt_InputClock (show)
        '-------------------------------------------------------------------------
        With c("lbl_txt_InputClock")
          bDisabled = IsModuleDisabled(r, sVarPre)
          .Enabled = Not (bDisabled)
        End With

        With e("lbl_txt_InputClock")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleDisabled(r, sVarPre)) Then
              .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, vIndex)
            End If
          End If
        End With

        '-------------------------------------------------------------------------
        ' control: lbl_box_InputClock (show)
        '-------------------------------------------------------------------------
        With c("lbl_box_InputClock")
          bDisabled = IsModuleDisabled(r, sVarPre)
          .Enabled = Not (bDisabled)
          If (GetGPT2ModuleClock(r, vIndex) > GetMaxSystemClock(r)) Then
              .Caption = TO_HIGH
          Else
              .Caption = GetGPT2ModuleClock(r, vIndex)
          End If
        End With

        With e("lbl_box_InputClock")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleDisabled(r, sVarPre)) Then
              .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, vIndex)
            End If
          End If
        End With

        For i = 0 To 3
            '-------------------------------------------------------------------------
            ' control: optBPS2_0 (show)
            '-------------------------------------------------------------------------
            With c("optBPS2_" & i)
              .Caption = "Prescaler for timer block 2 is " & GetBPS2Factor(i)
              bDisabled = (IsModuleDisabled(r, sVarPre))
              .Enabled = Not (bDisabled)
              .Value = -CInt(r.v(GPT12_ & "T6CON_BPS2") = i)
            End With

            With e("optBPS2_" & i)
              If (bDisabled) Then
                .DisabledTooltipText = TOOLTIP_DISABLED_IF
                If (IsModuleDisabled(r, sVarPre)) Then
                  .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, vIndex)
                End If
              End If
            End With
        Next i


        '-------------------------------------------------------------------------
        ' control: lbl_txt_BPS2 (show)
        '-------------------------------------------------------------------------
        With c("lbl_txt_BPS2")
          bDisabled = (IsModuleDisabled(r, sVarPre))
          .Enabled = Not (bDisabled)
          .Caption = "Max. input frequency for timer 5/6 [MHz]"
        End With

        With e("lbl_txt_BPS2")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleDisabled(r, sVarPre)) Then
              .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, vIndex)
            End If
          End If
        End With

        '-------------------------------------------------------------------------
        ' control: lbl_box_BPS2 (show)
        '-------------------------------------------------------------------------
        With c("lbl_box_BPS2")
          bDisabled = (IsModuleDisabled(r, sVarPre))
          .Enabled = Not (bDisabled)
          .Caption = GetGPT2ModuleClock(r, vIndex) / GetBPS2Factor(r.v(GPT12_ & "T6CON_BPS2"))
        End With

        With e("lbl_box_BPS2")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleDisabled(r, sVarPre)) Then
              .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, vIndex)
            End If
          End If
        End With



      End If
  End If

  OnShowPageModuleClock = True
  Exit Function

OnShowPageModuleClockError:
  Errorbox "Can not show page", Err.Description
  Exit Function
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add the page 'Auxiliary Timer Tx'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageAuxiliaryTimer5(ps As Peripherals) As Boolean
  On Error Resume Next

  OnLoadPageAuxiliaryTimer5 = False

  If (Not ps.AddPage("T5")) Then Exit Function

  OnLoadPageAuxiliaryTimer5 = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPageAuxiliaryTimer5(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageAuxiliaryTimer5 = False
  Dim r       As ProjectData
  Dim TimerNr As Variant

  Set r = ps.ProjectData

  TimerNr = 5
  
  If (Not ps.ExtenderCollection("T5").Loaded) And (Pagename = "T5") Then
    ps.ExtenderCollection("T5").Loaded = True
  
    '-------------------------------
    ' frame: frmT5M
    '-------------------------------
    If (Not ps.AddFrame("frmT5M", 100, 100, 2750, 2475, _
      "Timer 5 Mode (T5M)")) Then Exit Function
        If (Not ps.AddOption("optT5M_0", 200, 300, 1975, 300, _
          "Timer mode")) Then Exit Function
        If (Not ps.AddOption("optT5M_1", 200, 775, 1975, 300, _
          "Counter mode")) Then Exit Function
        If (Not ps.AddOption("optT5M_2", 200, 1250, 1975, 380, _
          "Gated timer with gate active low (" & GetPinName("T5IN") & ")")) Then Exit Function
        If (Not ps.AddOption("optT5M_3", 200, 1800, 1975, 380, _
          "Gated timer with gate active high (" & GetPinName("T5IN") & ")")) Then Exit Function

    '-------------------------------
    ' frame: frmT5I
    '-------------------------------
    If (Not ps.AddFrame("frmT5I", 2950, 100, 5600, 1325, "Input Selection")) Then Exit Function
        If (Not ps.AddCombo("cboT5I", 1400, 550, 4050, 315)) Then Exit Function
        If (Not ps.AddLabel("lblT5I", 0, 200, 500, 1175, 435, "xxxx")) Then Exit Function

    '-------------------------------
    ' frame: frmT5UD
    '-------------------------------
    If (Not ps.AddFrame("frmT5UD", 2950, 1475, 2750, 1125, "Up/Down Control (T5UD)")) Then Exit Function
        If (Not ps.AddOption("optT5UD_0", 200, 250, 1975, 380, "Count up")) Then Exit Function
        If (Not ps.AddOption("optT5UD_1", 200, 650, 1975, 380, "Count down")) Then Exit Function

    If (r.Regs.BitFind(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = True) Then
        '-------------------------------
        ' frame: frmT5UDE
        '-------------------------------
        If (Not ps.AddFrame("frmT5UDE", 2950, 2625, 2750, 1025, "External Up/Down Control (T5UDE)")) Then Exit Function
            If (Not ps.AddCheck("chkT5UDE", 200, 350, 2500, 380, "Enable external up/down via T5EUD (" & GetPinName("T5EUD") & ")")) Then Exit Function
    End If
    
    '-------------------------------
    ' frame: frmT5
    '-------------------------------
    If (Not ps.AddFrame("frmT5", 5800, 1475, 2750, 2175, "Timer Register")) Then Exit Function
        If (Not ps.AddText("txtUnFlT5", 1600, 350, 975, 315)) Then Exit Function
        If (Not ps.AddText("txtOvFlT5", 1600, 950, 975, 315)) Then Exit Function
        If (Not ps.AddText("txtTimRegT5", 1600, 1550, 975, 315)) Then Exit Function
        If (Not ps.AddLabel("lblTimRegT5", 0, 150, 1500, 1425, 380, _
          "Timer register " & vbCrLf & "(" & GPT12_ & "T5)")) Then Exit Function
        If (Not ps.AddLabel("lblOvFlT5", 0, 150, 1000, 1100, 310, "Overflow [ms]")) Then Exit Function
        If (Not ps.AddLabel("lblUnFlT5", 0, 150, 400, 1100, 310, "Underflow [ms]")) Then Exit Function

    
    '-------------------------------
    ' frame: frmT5R
    '-------------------------------
    If (Not ps.AddFrame("frmT5R", 100, 2625, 2750, 1025, "Timer Start")) Then Exit Function
        If (Not ps.AddCheck("chkT5R", 200, 350, 2500, 380, "Start T5 after initialization (T5R)")) Then Exit Function

    '-------------------------------
    ' frame: frmT5RC
    '-------------------------------
    If (Not ps.AddFrame("frmT5RC", 100, 3700, 2750, 1025, "Timer 5 Remote Control")) Then Exit Function
        If (Not ps.AddCheck("chkT5RC", 200, 350, 2500, 380, "T5 is controlled by the run bit T6R (T5RC)")) Then Exit Function


    If (r.Regs.BitFind(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = True) Then
        '-------------------------------
        ' frame: frmT5IE
        '-------------------------------
        If (Not ps.AddFrame("frmT5IE", 2950, 3700, 2750, 1025, "Interrupt Control")) Then Exit Function
            If (Not ps.AddCheck("chkT5IE", 200, 350, 2500, 380, "Enable T5 interrupt (IE)")) Then Exit Function
    
    Else
    
        '-------------------------------
        ' frame: frmT5IE
        '-------------------------------
        If (Not ps.AddFrame("frmT5IE", 2950, 2625, 2750, 1025, "Interrupt Control")) Then Exit Function
            If (Not ps.AddCheck("chkT5IE", 200, 350, 2500, 380, "Enable T5 interrupt (IE)")) Then Exit Function
    End If


  End If
  OnChangingPageAuxiliaryTimer5 = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageAuxiliaryTimer5(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageAuxiliaryTimer5Error

  OnShowPageAuxiliaryTimer5 = False

  Dim r           As ProjectData
  Dim c           As Object
  Dim e           As Object
  Dim bDisabled   As Boolean
  Dim i           As Integer
  Dim vIndex      As Variant
  Dim TimerNr     As Variant
  Dim sVarPre     As String
  Dim uTime       As UnitType
  Dim uFrequency  As UnitType
  Dim dDivider    As Double

  sVarPre = "GPT2"
  TimerNr = 5

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (Pagename = "T5") Then

    '-------------------------------------------------------------------------
    ' page: GPT2Timer5 (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: optT5M_0 (action)
        '---------------------------------------------------------------------
        Case "optT" & TimerNr & "M_0"
             If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then 'if in cbo edge selection
               r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 0
             End If
             r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 0

             If (GetPinFunction(r, "T" & TimerNr & "IN") = 1) Then
               Call ReleaseAlternateInputPin(r, "T" & TimerNr & "IN")
             End If

        '---------------------------------------------------------------------
        ' control: optT" & TimerNr & "M_1 (action)
        '---------------------------------------------------------------------
        Case "optT" & TimerNr & "M_1"
             r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1
             r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 0
             
             If (GetPinFunction(r, "T" & TimerNr & "IN") = 1) Then
               Call ReleaseAlternateInputPin(r, "T" & TimerNr & "IN")
             End If

        '---------------------------------------------------------------------
        ' control: optT" & TimerNr & "M_2 (action)
        '---------------------------------------------------------------------
        Case "optT" & TimerNr & "M_2"
             If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then 'if in cbo edge selection
               r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 0
             End If
             r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 2

             If (GetPinFunction(r, "T" & TimerNr & "IN") <> 1) Then
               Call RequestAlternateInputPin(r, "T" & TimerNr & "IN")
             End If

        '---------------------------------------------------------------------
        ' control: optT" & TimerNr & "M_3 (action)
        '---------------------------------------------------------------------
        Case "optT" & TimerNr & "M_3"
             If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then 'if in cbo edge selection
               r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 0
             End If
             r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 3

             If (GetPinFunction(r, "T" & TimerNr & "IN") <> 1) Then
               Call RequestAlternateInputPin(r, "T" & TimerNr & "IN")
             End If

        '---------------------------------------------------------------------
        ' control: cboT" & TimerNr & "I (action)
        '---------------------------------------------------------------------
        Case "cboT" & TimerNr & "I"
             If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 0 Or r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 2 Or r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 3) Then
               For i = 0 To 7
                  If v(1) = GetPrescalerResolution(r, i) Then
                    r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = i
                  End If
               Next i
             End If

             If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
               Select Case (v(1))
                           Case ("T" & TimerNr & " is disabled")
                                r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 0
                                If (GetPinFunction(r, "T" & TimerNr & "IN") = 1) Then
                                  Call ReleaseAlternateInputPin(r, "T" & TimerNr & "IN")
                                End If
                           Case ("Positive transition on T" & TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")")
                                r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 1
                                If (GetPinFunction(r, "T" & TimerNr & "IN") <> 1) Then
                                  Call RequestAlternateInputPin(r, "T" & TimerNr & "IN")
                                End If
                           Case ("Negative transition on T" & TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")")
                                r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 2
                                If (GetPinFunction(r, "T" & TimerNr & "IN") <> 1) Then
                                  Call RequestAlternateInputPin(r, "T" & TimerNr & "IN")
                                End If
                           Case ("Any transition on T" & TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")")
                                r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 3
                                If (GetPinFunction(r, "T" & TimerNr & "IN") <> 1) Then
                                  Call RequestAlternateInputPin(r, "T" & TimerNr & "IN")
                                End If
                           Case ("Positive transition of output toggle latch T6OTL")
                                r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 5
                                If (GetPinFunction(r, "T" & TimerNr & "IN") = 1) Then
                                  Call ReleaseAlternateInputPin(r, "T" & TimerNr & "IN")
                                End If
                           Case ("Negative transition of output toggle latch T6OTL")
                                r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 6
                                If (GetPinFunction(r, "T" & TimerNr & "IN") = 1) Then
                                  Call ReleaseAlternateInputPin(r, "T" & TimerNr & "IN")
                                End If
                           Case ("Any transition of output toggle latch T6OTL")
                                r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 7
                                If (GetPinFunction(r, "T" & TimerNr & "IN") = 1) Then
                                  Call ReleaseAlternateInputPin(r, "T" & TimerNr & "IN")
                                End If
               End Select
             End If

        '---------------------------------------------------------------------
        ' control: optT" & TimerNr & "UD_0 (action)
        '---------------------------------------------------------------------
        Case "optT" & TimerNr & "UD_0"
             r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UD") = 0

        '---------------------------------------------------------------------
        ' control: optT" & TimerNr & "UD_1 (action)
        '---------------------------------------------------------------------
        Case "optT" & TimerNr & "UD_1"
             r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UD") = 1

        '---------------------------------------------------------------------
        ' control: chkT" & TimerNr & "UDE (action)
        '---------------------------------------------------------------------
        'see down

        '---------------------------------------------------------------------
        ' control: txtTimRegT" & TimerNr & " (action)
        '---------------------------------------------------------------------
        Case "txtTimRegT" & TimerNr & ""
             If (IsInputFormatOK(v(1), "H4", c("lblTimRegT" & TimerNr & "").Caption, 0, 65535)) Then
               r.sfr(GPT12_ & "T" & TimerNr) = v(1)
             Else
                 Exit Function
             End If

        '---------------------------------------------------------------------
        ' control: txtOvFlT" & TimerNr & " (action)
        '---------------------------------------------------------------------
        Case "txtOvFlT" & TimerNr & ""
             uTime = ConvertTime(GetOverflow(r, TimerNr))
             dDivider = uTime.dDivider
             If (IsInputFormatOK(v(1), "F", c("lblOvFlT" & TimerNr & "").Caption, _
                 Format(GetMinResolution(r, TimerNr) / dDivider, "0.000"), _
                 Format(GetMaxResolution(r, TimerNr) / dDivider, "0.000"))) Then

               r.l(GPT12_ & "T" & TimerNr & "_T" & TimerNr) = GetTimerNrValue(r, v(1) * dDivider, True, TimerNr)   'True for overflow
             Else
                 Exit Function
             End If

        '---------------------------------------------------------------------
        ' control: txtUnFlT" & TimerNr & " (action)
        '---------------------------------------------------------------------
        Case "txtUnFlT" & TimerNr & ""
             uTime = ConvertTime(GetUnderflow(r, TimerNr))
             dDivider = uTime.dDivider
             If (IsInputFormatOK(v(1), "F", c("lblUnFlT" & TimerNr & "").Caption, _
                 Format(GetMinResolution(r, TimerNr) / dDivider, "0.000"), _
                 Format(GetMaxResolution(r, TimerNr) / dDivider, "0.000"))) Then

               r.v(GPT12_ & "T" & TimerNr & "_T" & TimerNr & "") = GetTimerNrValue(r, v(1) * dDivider, False, TimerNr)   'False for underflow
             Else
                 Exit Function
             End If

        '---------------------------------------------------------------------
        ' control: chkT" & TimerNr & "IE (action)
        '---------------------------------------------------------------------
        Case "chkT" & TimerNr & "IE"
             If v(1) = 1 Then
               Call EnableSRN(r, "GPT2", GPT12_ & "T" & TimerNr & "IC", "Tmr" & TimerNr & "")
             Else
               Call DisableSRN(r, "GPT2", GPT12_ & "T" & TimerNr & "IC", "Tmr" & TimerNr & "")
             End If

        '---------------------------------------------------------------------
        ' control: chkT" & TimerNr & "R (action)
        '---------------------------------------------------------------------
        Case "chkT" & TimerNr & "R"
              r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "R") = v(1)

        '---------------------------------------------------------------------
        ' control: chkT" & TimerNr & "RC (action)
        '---------------------------------------------------------------------
        Case "chkT" & TimerNr & "RC"
              r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "RC") = v(1)


      Case Else
    End Select

    'ahe 02.08.00 start
    If (r.Regs.BitFind(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = True) Then
       If (Controlname = "chkT" & TimerNr & "UDE") Then

           r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = v(1)

           If (v(1) = 1) Then
             If (IsAlternateInputPinFree(r, "T" & TimerNr & "EUD")) Then
               Call RequestAlternateInputPin(r, "T" & TimerNr & "EUD")
             End If
           Else
             Call ReleaseAlternateInputPin(r, "T" & TimerNr & "EUD")
           End If

       End If
    End If
    'ahe end

    '-------------------------------------------------------------------------
    ' page: GPT2Timer5 (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: optT" & TimerNr & "M_0 (show)
    '-------------------------------------------------------------------------
    With c("optT" & TimerNr & "M_0")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 0)
    End With

    With e("optT" & TimerNr & "M_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optT" & TimerNr & "M_1 (show)
    '-------------------------------------------------------------------------
    With c("optT" & TimerNr & "M_1")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1)
    End With

    With e("optT" & TimerNr & "M_1")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optT" & TimerNr & "M_2 (show)
    '-------------------------------------------------------------------------
    With c("optT" & TimerNr & "M_2")
      bDisabled = (Not (IsAlternateInputPinFree(r, "T" & TimerNr & "IN")) Or _
                  IsModuleDisabled(r, sVarPre))
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 2)
    End With

    With e("optT" & TimerNr & "M_2")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (Not (IsAlternateInputPinFree(r, "T" & TimerNr & "IN"))) Then
          .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T" & TimerNr & "IN")
        End If
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optT" & TimerNr & "M_3 (show)
    '-------------------------------------------------------------------------
    With c("optT" & TimerNr & "M_3")
      bDisabled = (Not (IsAlternateInputPinFree(r, "T" & TimerNr & "IN")) Or _
                  IsModuleDisabled(r, sVarPre))
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 3)
    End With

    With e("optT" & TimerNr & "M_3")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (Not (IsAlternateInputPinFree(r, "T" & TimerNr & "IN"))) Then
          .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T" & TimerNr & "IN")
        End If
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: cboT" & TimerNr & "I (show)
    '-------------------------------------------------------------------------
    With c("cboT" & TimerNr & "I")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Clear

      '--- Timer Or Gated mode
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 0 Or r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 2 Or r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 3) Then
        For i = 0 To 7
          .AddItem GetPrescalerResolution(r, i)
        Next i
      .ListIndex = r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I")
      End If


      '--- Counter
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
        .AddItem "T" & TimerNr & " is disabled"

        If (IsAlternateInputPinFree(r, "T" & TimerNr & "IN")) Then   'TxIN frei ?
          .AddItem "Positive transition on T" & TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")"
          .AddItem "Negative transition on T" & TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")"
          .AddItem "Any transition on T" & TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")"
        End If

        .AddItem "Positive transition of output toggle latch T6OTL"
        .AddItem "Negative transition of output toggle latch T6OTL"
        .AddItem "Any transition of output toggle latch T6OTL"

       If (IsAlternateInputPinFree(r, "T" & TimerNr & "IN")) Then    'wegen dem Fehlen von TxI = 4
         If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 5 Or r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 6 Or r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 7) Then
           .ListIndex = r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") - 1
         Else
           .ListIndex = r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I")
         End If

       Else
         If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 0) Then  'keine Vrschiebung notwendich
           .ListIndex = 0
         Else
           .ListIndex = r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") - 4  'Verschiebung, weil 3 Elelemnte fehlen
         End If
       End If
      End If

    End With

    With e("cboT" & TimerNr & "I")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblT" & TimerNr & "I (show)
    '-------------------------------------------------------------------------
    With c("lblT" & TimerNr & "I")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
        .Caption = "Edge selection (T" & TimerNr & "I)"
      Else
        .Caption = "Prescaler     (T" & TimerNr & "I)"
      End If
    End With

    With e("lblT" & TimerNr & "I")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optT" & TimerNr & "UD_0 (show)
    '-------------------------------------------------------------------------
    With c("optT" & TimerNr & "UD_0")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UD") = 0)
    End With

    With e("optT" & TimerNr & "UD_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optT" & TimerNr & "UD_1 (show)
    '-------------------------------------------------------------------------
    With c("optT" & TimerNr & "UD_1")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UD") = 1)
    End With

    With e("optT" & TimerNr & "UD_1")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    'ahe 02.08.00 start
    If (r.Regs.BitFind(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = True) Then

        '-------------------------------------------------------------------------
        ' control: chkT" & TimerNr & "UDE (show)
        '-------------------------------------------------------------------------
        With c("chkT" & TimerNr & "UDE")
          bDisabled = (IsModuleDisabled(r, sVarPre) Or IsAlternateOutputPinFree(r, "T" & TimerNr & "EUD") = 0)
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = 1)
        End With

        With e("chkT" & TimerNr & "UDE")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleDisabled(r, sVarPre)) Then
              .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, vIndex)
            End If
            If (IsAlternateOutputPinFree(r, "T" & TimerNr & "EUD") = 0) Then
              .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T" & TimerNr & "EUD")
            End If
          End If
        End With

    End If
    'ahe end

    '-------------------------------------------------------------------------
    ' control: chkT" & TimerNr & "IE (show)
    '-------------------------------------------------------------------------
    With c("chkT" & TimerNr & "IE")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "IC_IE") = 1)
    End With

     With e("chkT" & TimerNr & "IE")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

   '-------------------------------------------------------------------------
    ' control: chkT" & TimerNr & "R (show)
    '-------------------------------------------------------------------------
    With c("chkT" & TimerNr & "R")
      bDisabled = (IsModuleDisabled(r, sVarPre) Or _
                   r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "RC") = 1)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "R") = 1)
    End With

    With e("chkT" & TimerNr & "R")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
        If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "RC") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledToolTip("timer " & TimerNr & " remote control is enabled")
        End If
      End If
    End With
 

    '-------------------------------------------------------------------------
    ' control: chkT" & TimerNr & "RC (show)
    '-------------------------------------------------------------------------
    With c("chkT" & TimerNr & "RC")
      bDisabled = (IsModuleDisabled(r, sVarPre) Or _
                   r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "R") = 1)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "RC") = 1)
    End With

    With e("chkT" & TimerNr & "RC")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
        If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "R") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledToolTip("the start bit of timer " & TimerNr & " is enabled")
        End If
      End If
    End With
 
    '-------------------------------------------------------------------------
    ' control: txtTimRegT" & TimerNr & " (show)
    '-------------------------------------------------------------------------
    With c("txtTimRegT" & TimerNr & "")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Text = FormatTextOutput(r.sfr(GPT12_ & "T" & TimerNr), "H4")
    End With

    With e("txtTimRegT" & TimerNr & "")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With
 
    '-------------------------------------------------------------------------
    ' control: lblTimRegT" & TimerNr & " (show)
    '-------------------------------------------------------------------------
    With c("lblTimRegT" & TimerNr & "")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
    End With

    With e("lblTimRegT" & TimerNr & "")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With
 
    '-------------------------------------------------------------------------
    ' control: lblOvFlT" & TimerNr & " (show)
    '-------------------------------------------------------------------------
    With c("lblOvFlT" & TimerNr & "")
      bDisabled = (IsModuleDisabled(r, sVarPre) Or _
                   r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1)
      .Enabled = Not (bDisabled)
    End With

    With e("lblOvFlT" & TimerNr & "")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
        If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledToolTip("no timer mode is selected")
        End If
      End If
    End With
 
    '-------------------------------------------------------------------------
    ' control: lblUnFlT" & TimerNr & " (show)
    '-------------------------------------------------------------------------
    With c("lblUnFlT" & TimerNr & "")
      bDisabled = (IsModuleDisabled(r, sVarPre) Or _
                   r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1)
      .Enabled = Not (bDisabled)
    End With

    With e("lblUnFlT" & TimerNr & "")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
        If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledToolTip("no timer mode is selected")
        End If
      End If
    End With
 
    '-------------------------------------------------------------------------
    ' control: txtOvFlT" & TimerNr & " (show)
    '-------------------------------------------------------------------------
    With c("txtOvFlT" & TimerNr & "")
      bDisabled = (IsModuleDisabled(r, sVarPre) Or _
                   r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1)
      .Enabled = Not (bDisabled)
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
        .Text = CALCULATION_NOT_POSSIBLE
      Else
        uTime = ConvertTime(GetOverflow(r, TimerNr))
        .Text = Format(uTime.dValue, "0.000")
        c("lblOvFlT" & TimerNr & "").Caption = "Overflow [" & uTime.sUnit & "]"
      End If
    End With

    With e("txtOvFlT" & TimerNr & "")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
        If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledToolTip("no timer mode is selected")
        End If
      End If
    End With
 
    '-------------------------------------------------------------------------
    ' control: txtUnFlT" & TimerNr & " (show)
    '-------------------------------------------------------------------------
    With c("txtUnFlT" & TimerNr & "")
      bDisabled = (IsModuleDisabled(r, sVarPre) Or _
                   r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1)
      .Enabled = Not (bDisabled)
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
        .Text = CALCULATION_NOT_POSSIBLE
      Else
        uTime = ConvertTime(GetUnderflow(r, TimerNr))
        .Text = Format(uTime.dValue, "0.000")
        c("lblUnFlT" & TimerNr & "").Caption = "Underflow [" & uTime.sUnit & "]"
      End If
    End With

    With e("txtUnFlT" & TimerNr & "")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
        If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledToolTip("no timer mode is selected")
        End If
      End If
    End With
 
  End If

  OnShowPageAuxiliaryTimer5 = True
  Exit Function

OnShowPageAuxiliaryTimer5Error:
  Errorbox "Can not show page", Err.Description
  Exit Function
End Function


'-----------------------------------------------------------------------------
' local functions
'-----------------------------------------------------------------------------

'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageCoreTimer6(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageCoreTimer6 = False

  If (Not ps.AddPage("T6")) Then Exit Function

  OnLoadPageCoreTimer6 = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnChangingPageCoreTimer6(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageCoreTimer6 = False
  Dim TimerNr As Variant
  Dim vIndex  As Variant
  Dim r       As ProjectData
  
  TimerNr = 6

  Set r = ps.ProjectData


  If (Not ps.ExtenderCollection("T6").Loaded) And (Pagename = "T6") Then
    ps.ExtenderCollection("T6").Loaded = True

    '-------------------------------
    ' frame: frmT6M
    '-------------------------------
    If (r.Regs.BitFind(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = True) Then
        If (Not ps.AddFrame("frmT6M", 100, 100, 2750, 2475, "Timer 6 Mode (T6M)")) Then Exit Function
    Else
        If (Not ps.AddFrame("frmT6M", 100, 100, 2750, 3525, "Timer 6 Mode (T6M)")) Then Exit Function
    End If
        
        If (Not ps.AddOption("optT6M_0", 200, 300, 1975, 300, "Timer mode")) Then Exit Function
        If (Not ps.AddOption("optT6M_1", 200, 775, 1975, 300, "Counter mode")) Then Exit Function
        If (Not ps.AddOption("optT6M_2", 200, 1250, 1975, 380, "Gated timer with gate active low (" & GetPinName("T" & TimerNr & "IN") & ")")) Then Exit Function
        If (Not ps.AddOption("optT6M_3", 200, 1800, 1975, 380, "Gated timer with gate active high (" & GetPinName("T" & TimerNr & "IN") & ")")) Then Exit Function

    '-------------------------------
    ' frame: frmT6I
    '-------------------------------
    If (Not ps.AddFrame("frmT6I", 2950, 100, 5600, 1325, "Input Selection")) Then Exit Function
        If (Not ps.AddCombo("cboT6I", 1400, 550, 4050, 315)) Then Exit Function
        If (Not ps.AddLabel("lblT6I", 0, 200, 500, 1175, 430, "xxxx")) Then Exit Function

    '-------------------------------
    ' frame: frmT6UD
    '-------------------------------
    If (Not ps.AddFrame("frmT6UD", 2950, 1475, 2750, 1125, "Up/Down Control (T6UD)")) Then Exit Function
        If (Not ps.AddOption("optT6UD_0", 200, 250, 1975, 380, "Count up")) Then Exit Function
        If (Not ps.AddOption("optT6UD_1", 200, 650, 1975, 380, "Count down")) Then Exit Function

    '-------------------------------
    ' frame: frmT6SR
    '-------------------------------
    If (r.Regs.BitFind(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = True) Then
        If (Not ps.AddFrame("frmT6SR", 100, 2625, 2750, 1025, "Reload Mode")) Then Exit Function
    Else
        If (Not ps.AddFrame("frmT6SR", 2950, 2625, 2750, 1025, "Reload Mode")) Then Exit Function
    End If

        If (Not ps.AddCheck("chkT6SR", 200, 350, 2400, 380, "Reload from CAPREL (T6SR)")) Then Exit Function

    If (r.Regs.BitFind(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = True) Then
        '-------------------------------
        ' frame: frmT6UDE
        '-------------------------------
        If (Not ps.AddFrame("frmT6UDE", 2950, 2625, 2750, 1025, "External Up/Down Control (T6UDE)")) Then Exit Function
            If (Not ps.AddCheck("chkT6UDE", 200, 350, 2500, 380, "Enable external up/down via T6EUD (" & GetPinName("T6EUD") & ")")) Then Exit Function
    End If

    '-------------------------------
    ' frame: frmT6
    '-------------------------------
    If (Not ps.AddFrame("frmT6", 5800, 1475, 2750, 2175, "Timer Register")) Then Exit Function
        If (Not ps.AddText("txtUnFlT6", 1600, 350, 975, 315)) Then Exit Function
        If (Not ps.AddText("txtOvFlT6", 1600, 950, 975, 315)) Then Exit Function
        If (Not ps.AddText("txtTimRegT6", 1600, 1550, 975, 315)) Then Exit Function
        If (Not ps.AddLabel("lblTimRegT6", 0, 150, 1500, 1425, 380, _
          "Timer register " & vbCrLf & "(" & GPT12_ & "T6)")) Then Exit Function
        If (Not ps.AddLabel("lblOvFlT6", 0, 150, 1000, 1100, 305, "Overflow [ms]")) Then Exit Function
        If (Not ps.AddLabel("lblUnFlT6", 0, 150, 400, 1100, 305, "Underflow [ms]")) Then Exit Function

    '-------------------------------
    ' frame: frmT6OE
    '-------------------------------
    If (Not ps.AddFrame("frmT6OE", 100, 3725, 2750, 1450, "Alternate Output Function (T6OE)")) Then Exit Function
        If (Not ps.AddCheck("chkT6OE", 200, 350, 2500, 380, "Enable alternate output function T6OUT (" & GetPinName("T6OUT") & ")")) Then Exit Function
        If (Not ps.AddCheck("chkT6OTL", 200, 850, 2500, 380, "Set output toggle latch to '1' (T6OTL)")) Then Exit Function

    '-------------------------------
    ' frame: frmT6R
    '-------------------------------
    If (Not ps.AddFrame("frmT6R", 2950, 3725, 2750, 1450, "Timer Start")) Then Exit Function
        If (Not ps.AddCheck("chkT6R", 200, 550, 2500, 380, "Start T6 after initialization (T6R)")) Then Exit Function

    '-------------------------------
    ' frame: frmCI
    '-------------------------------
    If (Not ps.AddFrame("frmCIT6", 5800, 3725, 2750, 1450, "Interrupt Control")) Then Exit Function
        If (Not ps.AddCheck("chkT6IE", 200, 550, 2500, 380, "Enable T6 interrupt (T6IE)")) Then Exit Function



  End If
  OnChangingPageCoreTimer6 = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageCoreTimer6(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageCoreTimer6Error

  OnShowPageCoreTimer6 = False
     
  Dim r           As ProjectData
  Dim c           As Collection
  Dim e           As Collection
  Dim bDisabled   As Boolean
  Dim i           As Integer
  Dim vIndex      As Variant
  Dim TimerNr     As Variant
  Dim sVarPre     As String
  Dim uTime       As UnitType
  Dim uFrequency  As UnitType
  Dim dDivider    As Double

  sVarPre = "GPT2"
  TimerNr = 6

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (Pagename = "T6") Then

    '-------------------------------------------------------------------------
    ' page: GPT2_Timer_6 (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: optT6M_0 (action)
        '---------------------------------------------------------------------
        Case "optT" & TimerNr & "M_0"
             If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then 'if in cbo edge selection
               r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 0
             End If
             r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 0
             
             If (GetPinFunction(r, "T" & TimerNr & "IN") = 1) Then
               Call ReleaseAlternateInputPin(r, "T" & TimerNr & "IN")
             End If

        '---------------------------------------------------------------------
        ' control: optT" & TimerNr & "M_1 (action)
        '---------------------------------------------------------------------
        Case "optT" & TimerNr & "M_1"
             r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1
             r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 3

             If (GetPinFunction(r, "T" & TimerNr & "IN") <> 1) Then
               Call RequestAlternateInputPin(r, "T" & TimerNr & "IN")
             End If

        '---------------------------------------------------------------------
        ' control: optT" & TimerNr & "M_2 (action)
        '---------------------------------------------------------------------
        Case "optT" & TimerNr & "M_2"
             If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then 'if in cbo edge selection
               r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 0
             End If
             r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 2
             
             If (GetPinFunction(r, "T" & TimerNr & "IN") <> 1) Then
               Call RequestAlternateInputPin(r, "T" & TimerNr & "IN")
             End If

        '---------------------------------------------------------------------
        ' control: optT" & TimerNr & "M_3 (action)
        '---------------------------------------------------------------------
        Case "optT" & TimerNr & "M_3"
             If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then 'if in cbo edge selection
               r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 0
             End If
             r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 3
             
             If (GetPinFunction(r, "T" & TimerNr & "IN") <> 1) Then
               Call RequestAlternateInputPin(r, "T" & TimerNr & "IN")
             End If

        '---------------------------------------------------------------------
        ' control: chkT6SR (action)
        '---------------------------------------------------------------------
        Case "chkT6SR"
             r.v(GPT12_ & "T6CON_T6SR") = v(1)

        '---------------------------------------------------------------------
        ' control: cboT6I (action)
        '---------------------------------------------------------------------
        Case "cboT" & TimerNr & "I"
             If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 0 Or r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 2 Or r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 3) Then
               For i = 0 To 7
                  If v(1) = GetPrescalerResolution(r, i) Then
                     r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = i
                  End If
               Next i
             End If

             If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
               Select Case (v(1))

                           Case ("T" & TimerNr & " is disabled")
                                r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 0
                                Call ReleaseAlternateInputPin(r, "T" & TimerNr & "IN")

                           Case ("Positive transition on T" & TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")")
                                r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 1
                                If (GetPinFunction(r, "T" & TimerNr & "IN") <> 1) Then
                                  Call RequestAlternateInputPin(r, "T" & TimerNr & "IN")
                                End If

                           Case ("Negative transition on T" & TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")")
                                r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 2
                                If (GetPinFunction(r, "T" & TimerNr & "IN") <> 1) Then
                                  Call RequestAlternateInputPin(r, "T" & TimerNr & "IN")
                                End If

                           Case ("Any transition on T" & TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")")
                                r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") = 3
                                If (GetPinFunction(r, "T" & TimerNr & "IN") <> 1) Then
                                  Call RequestAlternateInputPin(r, "T" & TimerNr & "IN")
                                End If
               End Select
             End If

        '---------------------------------------------------------------------
        ' control: optT" & TimerNr & "UD_0 (action)
        '---------------------------------------------------------------------
        Case "optT" & TimerNr & "UD_0"
             r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UD") = 0

        '---------------------------------------------------------------------
        ' control: optT" & TimerNr & "UD_1 (action)
        '---------------------------------------------------------------------
        Case "optT" & TimerNr & "UD_1"
             r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UD") = 1

        '---------------------------------------------------------------------
        ' control: chkT" & TimerNr & "UDE (action)
        '---------------------------------------------------------------------
        'see down

        '---------------------------------------------------------------------
        ' control: txtTimRegT" & TimerNr & " (action)
        '---------------------------------------------------------------------
        Case "txtTimRegT" & TimerNr
             If (IsInputFormatOK(v(1), "H4", c("lblTimRegT" & TimerNr).Caption, 0, 65535)) Then
               r.sfr(GPT12_ & "T" & TimerNr) = v(1)
             Else
                 Exit Function
             End If

        '---------------------------------------------------------------------
        ' control: txtOvFlT" & TimerNr & " (action)
        '---------------------------------------------------------------------
        Case "txtOvFlT" & TimerNr
             uTime = ConvertTime(GetOverflow(r, TimerNr))
             dDivider = uTime.dDivider
             If (IsInputFormatOK(v(1), "F", c("lblOvFlT" & TimerNr).Caption, _
                 Format(GetMinResolution(r, TimerNr) / dDivider, "0.000"), _
                 Format(GetMaxResolution(r, TimerNr) / dDivider, "0.000"))) Then

               r.l(GPT12_ & "T" & TimerNr & "_T" & TimerNr) = GetTimerNrValue(r, v(1) * dDivider, True, TimerNr)   'True for overflow
             Else
                 Exit Function
             End If

        '---------------------------------------------------------------------
        ' control: txtUnFlT" & TimerNr & " (action)
        '---------------------------------------------------------------------
        Case "txtUnFlT" & TimerNr & ""
             uTime = ConvertTime(GetUnderflow(r, TimerNr))
             dDivider = uTime.dDivider
             If (IsInputFormatOK(v(1), "F", c("lblUnFlT" & TimerNr & "").Caption, _
                 Format(GetMinResolution(r, TimerNr) / dDivider, "0.000"), _
                 Format(GetMaxResolution(r, TimerNr) / dDivider, "0.000"))) Then

               r.v(GPT12_ & "T" & TimerNr & "_T" & TimerNr & "") = GetTimerNrValue(r, v(1) * dDivider, False, TimerNr)   'False for underflow
             Else
                 Exit Function
             End If

        '---------------------------------------------------------------------
        ' control: chkT" & TimerNr & "IE (action)
        '---------------------------------------------------------------------
        Case "chkT" & TimerNr & "IE"
             If v(1) = 1 Then
               Call EnableSRN(r, "GPT2", GPT12_ & "T" & TimerNr & "IC", "Tmr" & TimerNr & "")
             Else
               Call DisableSRN(r, "GPT2", GPT12_ & "T" & TimerNr & "IC", "Tmr" & TimerNr & "")
             End If

        '---------------------------------------------------------------------
        ' control: chkT" & TimerNr & "R (action)
        '---------------------------------------------------------------------
        Case "chkT" & TimerNr & "R"
              r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "R") = v(1)

        '---------------------------------------------------------------------
        ' control: chkT" & TimerNr & "OE (action)
        '---------------------------------------------------------------------
        Case "chkT" & TimerNr & "OE"
             r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "OE") = v(1)
             If v(1) Then
               If (IsAlternateOutputPinFree(r, "T" & TimerNr & "OUT")) Then
                 Call RequestAlternateOutputPin(r, "T" & TimerNr & "OUT")
               End If
             Else
               Call ReleaseAlternateOutputPin(r, "T" & TimerNr & "OUT")
             End If

        '---------------------------------------------------------------------
        ' control: chkT" & TimerNr & "OTL (action)
        '---------------------------------------------------------------------
        Case "chkT" & TimerNr & "OTL"
             r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "OTL") = v(1)


      Case Else
    End Select

    'ahe 02.08.00 start
    If (r.Regs.BitFind(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = True) Then
       If (Controlname = "chkT" & TimerNr & "UDE") Then

           r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = v(1)

           If (v(1) = 1) Then
             If (IsAlternateInputPinFree(r, "T" & TimerNr & "EUD")) Then
               Call RequestAlternateInputPin(r, "T" & TimerNr & "EUD")
             End If
           Else
             Call ReleaseAlternateInputPin(r, "T" & TimerNr & "EUD")
           End If

       End If
    End If
    'ahe end

    '-------------------------------------------------------------------------
    ' page: GPT2_Timer_6 (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: optT" & TimerNr & "M_0 (show)
    '-------------------------------------------------------------------------
    With c("optT" & TimerNr & "M_0")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 0)
    End With

    With e("optT" & TimerNr & "M_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optT" & TimerNr & "M_1 (show)
    '-------------------------------------------------------------------------
    With c("optT" & TimerNr & "M_1")
      bDisabled = (Not (IsAlternateInputPinFree(r, "T" & TimerNr & "IN")) Or _
                  IsModuleDisabled(r, sVarPre))
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1)
    End With

    With e("optT" & TimerNr & "M_1")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (Not (IsAlternateInputPinFree(r, "T" & TimerNr & "IN"))) Then
          .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T" & TimerNr & "IN")
        End If
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optT" & TimerNr & "M_2 (show)
    '-------------------------------------------------------------------------
    With c("optT" & TimerNr & "M_2")
      bDisabled = (Not (IsAlternateInputPinFree(r, "T" & TimerNr & "IN")) Or _
                  IsModuleDisabled(r, sVarPre))
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 2)
    End With

    With e("optT" & TimerNr & "M_2")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (Not (IsAlternateInputPinFree(r, "T" & TimerNr & "IN"))) Then
          .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T" & TimerNr & "IN")
        End If
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optT" & TimerNr & "M_3 (show)
    '-------------------------------------------------------------------------
    With c("optT" & TimerNr & "M_3")
      bDisabled = (Not (IsAlternateInputPinFree(r, "T" & TimerNr & "IN")) Or _
                  IsModuleDisabled(r, sVarPre))
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 3)
    End With

    With e("optT" & TimerNr & "M_3")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (Not (IsAlternateInputPinFree(r, "T" & TimerNr & "IN"))) Then
          .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T" & TimerNr & "IN")
        End If
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkT6SR (show)
    '-------------------------------------------------------------------------
    With c("chkT6SR")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T6CON_T6SR") = 1)
    End With

    With e("chkT6SR")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With
 
    '-------------------------------------------------------------------------
    ' control: cboT6I (show)
    '-------------------------------------------------------------------------
    With c("cboT" & TimerNr & "I")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Clear
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 0 Or r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 2 Or r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 3) Then
        For i = 0 To 7
          .AddItem GetPrescalerResolution(r, i)
        Next i
      .ListIndex = r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I")
      End If

      If r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1 Then
        '.AddItem "T" & TimerNr & " is disabled"
        .AddItem "Positive transition on T" & TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")"
        .AddItem "Negative transition on T" & TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")"
        .AddItem "Any transition on T" & TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")"
      .ListIndex = r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I") - 1
      End If

    End With

    With e("cboT6I")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With
 
    '-------------------------------------------------------------------------
    ' control: chkT" & TimerNr & "OE (show)
    '-------------------------------------------------------------------------
    With c("chkT" & TimerNr & "OE")
      bDisabled = (IsModuleDisabled(r, sVarPre) Or IsAlternateOutputPinFree(r, "T" & TimerNr & "OUT") = 0)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "OE") = 1)
    End With

    With e("chkT" & TimerNr & "OE")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, vIndex)
        End If
        If (IsAlternateOutputPinFree(r, "T" & TimerNr & "OUT") = 0) Then
          .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T" & TimerNr & "OUT")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkT" & TimerNr & "OTL (show)
    '-------------------------------------------------------------------------
    With c("chkT" & TimerNr & "OTL")
       bDisabled = (IsModuleDisabled(r, sVarPre))
       .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "OTL") = 1)
    End With

    With e("chkT" & TimerNr & "OTL")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, vIndex)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblT" & TimerNr & "I (show)
    '-------------------------------------------------------------------------
    With c("lblT" & TimerNr & "I")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
        .Caption = "Edge selection (T" & TimerNr & "I)"
      Else
        .Caption = "Prescaler     (T" & TimerNr & "I)"
      End If
    End With

    With e("lblT" & TimerNr & "I")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optT" & TimerNr & "UD_0 (show)
    '-------------------------------------------------------------------------
    With c("optT" & TimerNr & "UD_0")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UD") = 0)
    End With

    With e("optT" & TimerNr & "UD_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optT" & TimerNr & "UD_1 (show)
    '-------------------------------------------------------------------------
    With c("optT" & TimerNr & "UD_1")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UD") = 1)
    End With

    With e("optT" & TimerNr & "UD_1")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    'ahe 02.08.00 start
    If (r.Regs.BitFind(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = True) Then

        '-------------------------------------------------------------------------
        ' control: chkT" & TimerNr & "UDE (show)
        '-------------------------------------------------------------------------
        With c("chkT" & TimerNr & "UDE")
          bDisabled = (IsModuleDisabled(r, sVarPre) Or IsAlternateOutputPinFree(r, "T" & TimerNr & "EUD") = 0)
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = 1)
        End With

        With e("chkT" & TimerNr & "UDE")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleDisabled(r, sVarPre)) Then
              .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, vIndex)
            End If
            If (IsAlternateOutputPinFree(r, "T" & TimerNr & "EUD") = 0) Then
              .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T" & TimerNr & "EUD")
            End If
          End If
        End With

    End If
    'ahe end

    '-------------------------------------------------------------------------
    ' control: chkT" & TimerNr & "IE (show)
    '-------------------------------------------------------------------------
    With c("chkT" & TimerNr & "IE")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T" & TimerNr & "IC_IE") = 1)
    End With

     With e("chkT" & TimerNr & "IE")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

   '-------------------------------------------------------------------------
    ' control: chkT" & TimerNr & "R (show)
    '-------------------------------------------------------------------------
    With c("chkT" & TimerNr & "R")
      bDisabled = (IsModuleDisabled(r, sVarPre))
      .Enabled = Not (bDisabled)
      .Value = r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "R")
    End With

    With e("chkT" & TimerNr & "R")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With
 
    '-------------------------------------------------------------------------
    ' control: txtTimRegT" & TimerNr & " (show)
    '-------------------------------------------------------------------------
    With c("txtTimRegT" & TimerNr & "")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Text = FormatTextOutput(r.sfr(GPT12_ & "T" & TimerNr), "H4")
    End With

    With e("txtTimRegT" & TimerNr & "")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With
 
    '-------------------------------------------------------------------------
    ' control: lblTimRegT" & TimerNr & " (show)
    '-------------------------------------------------------------------------
    With c("lblTimRegT" & TimerNr & "")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
    End With

    With e("lblTimRegT" & TimerNr & "")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With
 
    '-------------------------------------------------------------------------
    ' control: lblOvFlT" & TimerNr & " (show)
    '-------------------------------------------------------------------------
    With c("lblOvFlT" & TimerNr & "")
      bDisabled = (IsModuleDisabled(r, sVarPre) Or r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1)
      .Enabled = Not (bDisabled)
    End With

    With e("lblOvFlT" & TimerNr & "")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
        If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("no timer mode is selected")
        End If
      End If
    End With
 
    '-------------------------------------------------------------------------
    ' control: lblUnFlT" & TimerNr & " (show)
    '-------------------------------------------------------------------------
    With c("lblUnFlT" & TimerNr & "")
      bDisabled = (IsModuleDisabled(r, sVarPre) Or r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1)
      .Enabled = Not (bDisabled)
    End With

    With e("lblUnFlT" & TimerNr & "")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
        If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("no timer mode is selected")
        End If
      End If
    End With
 
    '-------------------------------------------------------------------------
    ' control: txtOvFlT" & TimerNr & " (show)
    '-------------------------------------------------------------------------
    With c("txtOvFlT" & TimerNr & "")
      bDisabled = (IsModuleDisabled(r, sVarPre) Or r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1)
      .Enabled = Not (bDisabled)
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
        .Text = CALCULATION_NOT_POSSIBLE
      Else
        uTime = ConvertTime(GetOverflow(r, TimerNr))
        .Text = Format(uTime.dValue, "0.000")
        c("lblOvFlT" & TimerNr & "").Caption = "Overflow [" & uTime.sUnit & "]"
      End If
    End With

    With e("txtOvFlT" & TimerNr & "")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
        If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("no timer mode is selected")
        End If
      End If
    End With
 
    '-------------------------------------------------------------------------
    ' control: txtUnFlT" & TimerNr & " (show)
    '-------------------------------------------------------------------------
    With c("txtUnFlT" & TimerNr & "")
      bDisabled = (IsModuleDisabled(r, sVarPre) Or r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1)
      .Enabled = Not (bDisabled)
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
        .Text = CALCULATION_NOT_POSSIBLE
      Else
        uTime = ConvertTime(GetUnderflow(r, TimerNr))
        .Text = Format(uTime.dValue, "0.000")
        c("lblUnFlT" & TimerNr & "").Caption = "Underflow [" & uTime.sUnit & "]"
      End If
    End With

    With e("txtUnFlT" & TimerNr & "")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
        If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("no timer mode is selected")
        End If
      End If
    End With
 
        
  End If

  OnShowPageCoreTimer6 = True
  Exit Function

OnShowPageCoreTimer6Error:
  Errorbox "Can not show page", Err.Description
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add the page 'CaptureReload'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageCaptureReload(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageCaptureReload = False

  If (Not ps.AddPage("Capture/Reload")) Then Exit Function

  OnLoadPageCaptureReload = True
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPageCaptureReload(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageCaptureReload = False
  
  If (Not ps.ExtenderCollection("Capture/Reload").Loaded) And (Pagename = "Capture/Reload") Then
    ps.ExtenderCollection("Capture/Reload").Loaded = True
  

    '-------------------------------
    ' frame: frmT5SC
    '-------------------------------
    If (Not ps.AddFrame("frmT5SC", 100, 100, 4100, 1200, "Capture Enable")) Then Exit Function
        If (Not ps.AddCheck("chkT5SC", 200, 250, 3800, 300, "Capture timer 5 into CAPREL (T5SC)")) Then Exit Function
        If (Not ps.AddCheck("chkT5CC", 200, 650, 3800, 400, "Decrement timer 5 by 1 before being captured (T5CC)")) Then Exit Function

    '-------------------------------
    ' frame: frmCAPREL
    '-------------------------------
    If (Not ps.AddFrame("frmCAPREL", 4350, 100, 4200, 1200, "CAPREL Register (CAPREL)")) Then Exit Function
        If (Not ps.AddText("txtCAPREL", 1325, 500, 975, 315)) Then Exit Function
        If (Not ps.AddLabel("lblCAPREL", 0, 200, 550, 1025, 305, "CAPREL")) Then Exit Function

    '-------------------------------
    ' frame: frmCT3
    '-------------------------------
    If (Not ps.AddFrame("frmCT3", 100, 1400, 4100, 1550, "Timer 3 Capture Trigger Enable (CT3)")) Then Exit Function
        If (Not ps.AddOption("optCT3_0", 200, 400, 3100, 300, "Capture trigger from pin CAPIN")) Then Exit Function
        If (Not ps.AddOption("optCT3_1", 200, 900, 3100, 300, "Capture trigger from T3 input pins")) Then Exit Function

    '-------------------------------
    ' frame: frmCI
    '-------------------------------
    If (Not ps.AddFrame("frmCI", 4350, 1400, 4200, 1550, "CAPREL Input Selection (CI)")) Then Exit Function
        If (Not ps.AddOption("optCI_0", 200, 250, 3800, 300, "0000")) Then Exit Function
        If (Not ps.AddOption("optCI_1", 200, 550, 3800, 300, "1111")) Then Exit Function
        If (Not ps.AddOption("optCI_2", 200, 850, 3800, 300, "2222")) Then Exit Function
        If (Not ps.AddOption("optCI_3", 200, 1150, 3800, 300, "3333")) Then Exit Function

    '-------------------------------
    ' frame: frmCLR
    '-------------------------------
    If (Not ps.AddFrame("frmCLR", 100, 3025, 4100, 1000, "Timer Clear Bit")) Then Exit Function
        If (Not ps.AddCheck("chkT5CLR", 200, 250, 3400, 300, "Timer 5 is cleared on a capture  (T5CLR)")) Then Exit Function
        If (Not ps.AddCheck("chkT6CLR", 200, 600, 3400, 300, "Timer 6 is cleared on a capture  (T6CLR)")) Then Exit Function

    '-------------------------------
    ' frame: frmCRIE
    '-------------------------------
    If (Not ps.AddFrame("frmCRIE", 4350, 3025, 4200, 1000, "Interrupt Control")) Then Exit Function
        If (Not ps.AddCheck("chkCRIE", 200, 400, 2725, 300, "Enable CAPREL interrupt (CRIE)")) Then Exit Function

  End If
  OnChangingPageCaptureReload = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageCaptureReload(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageCaptureReloadError

  OnShowPageCaptureReload = False

  Dim r         As ProjectData
  Dim c         As Object
  Dim e         As Object
  Dim bDisabled As Boolean
  Dim i         As Integer
  Dim sVarPre   As String

  sVarPre = "GPT2"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (Pagename = "Capture/Reload") Then
    '-------------------------------------------------------------------------
    ' page: CaptureReload (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: chkT5SC (action)
        '---------------------------------------------------------------------
        Case "chkT5SC"
             r.v(GPT12_ & "T5CON_T5SC") = v(1)
             If (v(1) = 0) Then
                r.v(GPT12_ & "T5CON_T5CC") = 0
             End If

        '---------------------------------------------------------------------
        ' control: chkT5CC (action)
        '---------------------------------------------------------------------
        Case "chkT5CC"
             r.v(GPT12_ & "T5CON_T5CC") = v(1)

        '---------------------------------------------------------------------
        ' control: chkT5CLR (action)
        '---------------------------------------------------------------------
        Case "chkT5CLR"
             r.v(GPT12_ & "T5CON_T5CLR") = v(1)

        '---------------------------------------------------------------------
        ' control: chkT6CLR (action)
        '---------------------------------------------------------------------
        Case "chkT6CLR"
             r.v(GPT12_ & "T6CON_T6CLR") = v(1)

        '---------------------------------------------------------------------
        ' control: txtCAPREL (action)
        '---------------------------------------------------------------------
        Case "txtCAPREL"
             If (IsInputFormatOK(v(1), "H4", c("lblCAPREL").Caption, 0, 65535)) Then
               r.v(GPT12_ & "CAPREL_CAPREL") = v(1)
             Else
                 Exit Function
             End If

        '---------------------------------------------------------------------
        ' control: chkCRIE (action)
        '---------------------------------------------------------------------
        Case "chkCRIE"
             If v(1) = 1 Then
               Call EnableSRN(r, "GPT2", GPT12_ & "CRIC", "CAPREL")
             Else
               Call DisableSRN(r, "GPT2", GPT12_ & "CRIC", "CAPREL")
             End If

        '---------------------------------------------------------------------
        ' control: optCT3_0 (action)
        '---------------------------------------------------------------------
        Case "optCT3_0"
             r.v(GPT12_ & "T5CON_CT3") = 0
             If (r.v(GPT12_ & "T5CON_CI") = 1) Then
               Call ReleaseAlternateInputPin(r, "T3IN")
             End If
             If (r.v(GPT12_ & "T5CON_CI") = 2) Then
               Call ReleaseAlternateInputPin(r, "T3EUD")
             End If
             If (r.v(GPT12_ & "T5CON_CI") = 3) Then
               Call ReleaseAlternateInputPin(r, "T3IN")
               Call ReleaseAlternateInputPin(r, "T3EUD")
             End If
             r.v(GPT12_ & "T5CON_CI") = 0
             Call DisableSRN(r, "GPT2", GPT12_ & "CRIC", "CAPREL")

        '---------------------------------------------------------------------
        ' control: optCT3_1 (action)
        '---------------------------------------------------------------------
        Case "optCT3_1"
             r.v(GPT12_ & "T5CON_CT3") = 1
             If (r.v(GPT12_ & "T5CON_CI") > 0) Then
               Call ReleaseAlternateInputPin(r, "CAPIN")
             End If
             r.v(GPT12_ & "T5CON_CI") = 0
             Call DisableSRN(r, "GPT2", GPT12_ & "CRIC", "CAPREL")

        '---------------------------------------------------------------------
        ' control: optCI_0 (action)
        '---------------------------------------------------------------------
        Case "optCI_0"
             If (r.v(GPT12_ & "T5CON_CT3") = 1) Then
               If (r.v(GPT12_ & "T5CON_CI") = 1) Then
                 Call ReleaseAlternateInputPin(r, "T3IN")
               ElseIf (r.v(GPT12_ & "T5CON_CI") = 2) Then
                 Call ReleaseAlternateInputPin(r, "T3EUD")
               ElseIf (r.v(GPT12_ & "T5CON_CI") = 3) Then
                 Call ReleaseAlternateInputPin(r, "T3EUD")
                 Call ReleaseAlternateInputPin(r, "T3IN")
               End If
             Else
               If (r.v(GPT12_ & "T5CON_CI") > 0) Then
                 Call ReleaseAlternateInputPin(r, "CAPIN")
               End If
             End If

             r.v(GPT12_ & "T5CON_CI") = 0
             Call DisableSRN(r, "GPT2", GPT12_ & "CRIC", "CAPREL")

        '---------------------------------------------------------------------
        ' control: optCI_0 (action)
        '---------------------------------------------------------------------
        Case "optCI_1"
             If (r.v(GPT12_ & "T5CON_CT3") = 1) Then
               If (r.v(GPT12_ & "T5CON_CI") = 2 Or r.v(GPT12_ & "T5CON_CI") = 3) Then
                 Call ReleaseAlternateInputPin(r, "T3EUD")
               End If
               If (r.v(GPT12_ & "T5CON_CI") = 0 Or r.v(GPT12_ & "T5CON_CI") = 2) Then
                 Call RequestAlternateInputPin(r, "T3IN")
               End If
             Else
               If (r.v(GPT12_ & "T5CON_CI") = 0) Then
                 Call RequestAlternateInputPin(r, "CAPIN")
               End If
             End If

             r.v(GPT12_ & "T5CON_CI") = 1

        '---------------------------------------------------------------------
        ' control: optCI_0 (action)
        '---------------------------------------------------------------------
        Case "optCI_2"
             If (r.v(GPT12_ & "T5CON_CT3") = 1) Then
               If (r.v(GPT12_ & "T5CON_CI") = 1 Or r.v(GPT12_ & "T5CON_CI") = 3) Then
                 Call ReleaseAlternateInputPin(r, "T3IN")
               End If
               If (r.v(GPT12_ & "T5CON_CI") = 0 Or r.v(GPT12_ & "T5CON_CI") = 1) Then
                 Call RequestAlternateInputPin(r, "T3EUD")
               End If
             Else
               If (r.v(GPT12_ & "T5CON_CI") = 0) Then
                 Call RequestAlternateInputPin(r, "CAPIN")
               End If
             End If

             r.v(GPT12_ & "T5CON_CI") = 2

        '---------------------------------------------------------------------
        ' control: optCI_0 (action)
        '---------------------------------------------------------------------
        Case "optCI_3"
             If (r.v(GPT12_ & "T5CON_CT3") = 1) Then
               If (r.v(GPT12_ & "T5CON_CI") = 1) Then
                 Call RequestAlternateInputPin(r, "T3EUD")
               ElseIf (r.v(GPT12_ & "T5CON_CI") = 2) Then
                 Call RequestAlternateInputPin(r, "T3IN")
               Else
                 Call RequestAlternateInputPin(r, "T3EUD")
                 Call RequestAlternateInputPin(r, "T3IN")
               End If
             Else
               If (r.v(GPT12_ & "T5CON_CI") = 0) Then
                 Call RequestAlternateInputPin(r, "CAPIN")
               End If
             End If

             r.v(GPT12_ & "T5CON_CI") = 3


      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: CaptureReload (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: chkT5SC (show)
    '-------------------------------------------------------------------------
    With c("chkT5SC")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T5CON_T5SC") = 1)
    End With

    With e("chkT5SC")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkT5CC (show)
    '-------------------------------------------------------------------------
    With c("chkT5CC")
      bDisabled = (IsModuleDisabled(r, sVarPre) Or r.v(GPT12_ & "T5CON_T5SC") = 0)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T5CON_T5CC") = 1)
    End With

    With e("chkT5CC")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
        If (r.v(GPT12_ & "T5CON_T5SC") = 0) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("capture timer 5 into CAPREL is disabled")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkT5CLR (show)
    '-------------------------------------------------------------------------
    With c("chkT5CLR")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T5CON_T5CLR") = 1)
    End With

    With e("chkT5CLR")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkT6CLR (show)
    '-------------------------------------------------------------------------
    With c("chkT6CLR")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T6CON_T6CLR") = 1)
    End With

    With e("chkT6CLR")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: txtCAPREL (show)
    '-------------------------------------------------------------------------
    With c("txtCAPREL")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
      .Text = FormatTextOutput(r.v(GPT12_ & "CAPREL_CAPREL"), "H4")
    End With

    With e("txtCAPREL")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: CAPREL_Label (show)
    '-------------------------------------------------------------------------
    With c("lblCAPREL")
      bDisabled = IsModuleDisabled(r, sVarPre)
      .Enabled = Not (bDisabled)
    End With

    With e("lblCAPREL")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkCRIE (show)
    '-------------------------------------------------------------------------
    With c("chkCRIE")
      If (r.v(GPT12_ & "T5CON_CT3") = 0) Then
        bDisabled = (IsModuleDisabled(r, sVarPre) Or r.v(GPT12_ & "T5CON_CI") = 0)
      Else
        bDisabled = (IsModuleDisabled(r, sVarPre) Or r.v(GPT12_ & "T5CON_CI") = 0)
      End If
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "CRIC_IE") = 1)
    End With

    With e("chkCRIE")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
        If (r.v(GPT12_ & "T5CON_CI") = 0) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("CAPREL input selection is disabled (CI = 0)")
        End If
      End If
    End With


    '-------------------------------------------------------------------------
    ' control: optCT3_0 (show)
    '-------------------------------------------------------------------------
    With c("optCT3_0")
      bDisabled = (IsModuleDisabled(r, sVarPre))
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T5CON_CT3") = 0)
    End With

    With e("optCT3_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optCT3_1 (show)
    '-------------------------------------------------------------------------
    With c("optCT3_1")
      bDisabled = (IsModuleDisabled(r, sVarPre))
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T5CON_CT3") = 1)
    End With

    With e("optCT3_1")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optCI_0 (show)
    '-------------------------------------------------------------------------
    With c("optCI_0")
      bDisabled = (IsModuleDisabled(r, sVarPre))
      .Enabled = Not (bDisabled)
      .Caption = "Capture disabled"
      .Value = -CInt(r.v(GPT12_ & "T5CON_CI") = 0)
    End With

    With e("optCI_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optCI_1 (show)
    '-------------------------------------------------------------------------
    With c("optCI_1")
      If (r.v(GPT12_ & "T5CON_CT3") = 0) Then
        bDisabled = (IsModuleDisabled(r, sVarPre) Or Not (IsAlternateInputPinFree(r, "CAPIN")))
        .Caption = "Positive transition on CAPIN (" & GetPinName("CAPIN") & ")"
      Else
        bDisabled = (IsModuleDisabled(r, sVarPre) Or Not (IsAlternateInputPinFree(r, "T3IN")))
        .Caption = "Any transition on T3IN (" & GetPinName("T3IN") & ")"
      End If
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T5CON_CI") = 1)
    End With

    With e("optCI_1")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
        If (r.v(GPT12_ & "T5CON_CT3") = 0) Then
          If (Not (IsAlternateInputPinFree(r, "CAPIN"))) Then
            .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CAPIN")
          End If
        Else
          If (Not (IsAlternateInputPinFree(r, "T3IN"))) Then
            .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T3IN")
          End If
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optCI_2 (show)
    '-------------------------------------------------------------------------
    With c("optCI_2")
      If (r.v(GPT12_ & "T5CON_CT3") = 0) Then
        bDisabled = (IsModuleDisabled(r, sVarPre) Or Not (IsAlternateInputPinFree(r, "CAPIN")))
        .Caption = "Negative transition on CAPIN (" & GetPinName("CAPIN") & ")"
      Else
        bDisabled = (IsModuleDisabled(r, sVarPre) Or Not (IsAlternateInputPinFree(r, "T3EUD")))
        .Caption = "Any transition on T3EUD (" & GetPinName("T3EUD") & ")"
      End If
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T5CON_CI") = 2)
    End With

    With e("optCI_2")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
        If (r.v(GPT12_ & "T5CON_CT3") = 0) Then
          If (Not (IsAlternateInputPinFree(r, "CAPIN"))) Then
            .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CAPIN")
          End If
        Else
          If (Not (IsAlternateInputPinFree(r, "T3EUD"))) Then
            .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T3EUD")
          End If
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optCI_3 (show)
    '-------------------------------------------------------------------------
    With c("optCI_3")
      If (r.v(GPT12_ & "T5CON_CT3") = 0) Then
        bDisabled = (IsModuleDisabled(r, sVarPre) Or Not (IsAlternateInputPinFree(r, "CAPIN")))
        .Caption = "Any transition on CAPIN (" & GetPinName("CAPIN") & ")"
      Else
        bDisabled = (IsModuleDisabled(r, sVarPre) Or (Not (IsAlternateInputPinFree(r, "T3IN")) Or _
                    Not (IsAlternateInputPinFree(r, "T3EUD"))))
        .Caption = "Any transition on T3IN (" & GetPinName("T3IN") & ") or T3EUD (" & GetPinName("T3EUD") & ")"
      End If
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v(GPT12_ & "T5CON_CI") = 3)
    End With

    With e("optCI_3")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleDisabled(r, sVarPre)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleDisabled(r, sVarPre)
        End If
        If (r.v(GPT12_ & "T5CON_CT3") = 0) Then
          If (Not (IsAlternateInputPinFree(r, "CAPIN"))) Then
            .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CAPIN")
          End If
        Else
          If (Not (IsAlternateInputPinFree(r, "T3EUD"))) Then
            .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T3EUD")
          End If
          If (Not (IsAlternateInputPinFree(r, "T3IN"))) Then
            .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T3IN")
          End If
        End If
      End If
    End With


  End If

  OnShowPageCaptureReload = True
  Exit Function

OnShowPageCaptureReloadError:
  Errorbox "Can not show page", Err.Description
  Exit Function
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageFunctions(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageFunctions = False

  If (Not ps.AddPage("Functions")) Then Exit Function

  OnLoadPageFunctions = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnChangingPageFunctions(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  Dim i As Integer
  Dim aFunctions(1 To 16) As String


  OnChangingPageFunctions = False

  If (Not ps.ExtenderCollection("Functions").Loaded) And (Pagename = "Functions") Then
    ps.ExtenderCollection("Functions").Loaded = True

    '-------------------------------
    ' frame: fra_Init
    '-------------------------------
    If (Not ps.AddFrame("fra_Init", 100, 100, 4150, 700, CAPTION_FRA_USE_INIT)) Then Exit Function
      If (Not ps.AddCheck("chk_Init", 150, 275, 200, 275, "")) Then Exit Function
      If (Not ps.AddText("txt_Init", 400, 250, 3600, 325)) Then Exit Function

    '-------------------------------
    ' frame: fra_CFile
    '-------------------------------
    If (Not ps.AddFrame("fra_CFile", 4400, 100, 4150, 700, CAPTION_FRA_CFILE)) Then Exit Function
      If (Not ps.AddText("txt_CFile", 1475, 250, 2500, 325)) Then Exit Function
      If (Not ps.AddLabel("lbl_CFile", 0, 200, 300, 1250, 275, CAPTION_LBL_CFILE)) Then Exit Function


    '-------------------------------
    ' frame: fraLibrary1
    '-------------------------------
    ' initialize the array
    For i = LBound(aFunctions) To UBound(aFunctions)
      aFunctions(i) = ""
    Next i

    ' Functions and Macros
    i = LBound(aFunctions)

    aFunctions(i) = "StartTmr"
    i = i + 1
    aFunctions(i) = "StopTmr"
    i = i + 1
    aFunctions(i) = "ClearTmr"
    i = i + 1
    aFunctions(i) = "ReadTmr"
    i = i + 1
    aFunctions(i) = "LoadTmr"
    i = i + 1
    aFunctions(i) = "ReadCAPREL"
    i = i + 1
    aFunctions(i) = "LoadCAPREL"
    i = i + 1
    aFunctions(i) = "Tmr5"
    i = i + 1
    aFunctions(i) = "Tmr6"
    i = i + 1
    aFunctions(i) = "CAPREL"
    i = i + 1
    aFunctions(i) = "SetToggLatch"
    i = i + 1
    aFunctions(i) = "ClrToggLatch"
    i = i + 1


    If (Not ps.AddFrame("fraLibrary1", 100, 900, 4150, 4400, CAPTION_FRA_LIBRARY1)) Then Exit Function
      For i = LBound(aFunctions) To UBound(aFunctions)
        If Not (aFunctions(i) = "") Then
          If (Not ps.AddCheck("chk_" & aFunctions(i), 150, 325 + (300 * (i - 1)), 200, 275, "")) Then Exit Function
          If (Not ps.AddText("txt_" & aFunctions(i), 400, 300 + (300 * (i - 1)), 3600, 325)) Then Exit Function
        End If
      Next i

    '-------------------------------
    ' frame: fraLibrary2
    '-------------------------------
    ' initialize the array
    For i = LBound(aFunctions) To UBound(aFunctions)
      aFunctions(i) = ""
    Next i

    ' Functions and Macros
    i = LBound(aFunctions)

    aFunctions(i) = "CountUp"
    i = i + 1
    aFunctions(i) = "CountDown"
    i = i + 1
    aFunctions(i) = "SetTmrRemoteControl"
    i = i + 1
 
    If (Not ps.AddFrame("fraLibrary2", 4400, 900, 4150, 4400, CAPTION_FRA_LIBRARY2)) Then Exit Function
      For i = LBound(aFunctions) To UBound(aFunctions)
        If Not (aFunctions(i) = "") Then
          If (Not ps.AddCheck("chk_" & aFunctions(i), 150, 325 + (300 * (i - 1)), 200, 275, "")) Then Exit Function
          If (Not ps.AddText("txt_" & aFunctions(i), 400, 300 + (300 * (i - 1)), 3600, 325)) Then Exit Function
        End If
      Next i

    ' Functions and Macros
  End If

  OnChangingPageFunctions = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageFunctions(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageFunctionsError

  OnShowPageFunctions = False
    
  Dim r         As ProjectData
  Dim c         As Collection
  Dim e         As Collection
  Dim bDisabled As Boolean
  Dim func      As FunctionClass

  Dim sVarPre   As String
  Dim sPrefix   As String
  Dim vIndex    As Variant
  Dim sName     As String
  Dim d         As String

  vIndex = ""
  sVarPre = "GPT2"
  sPrefix = sVarPre & "_"


  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set func = New FunctionClass

  If (Pagename = "Functions") Then
    '-------------------------------------------------------------------------
    ' page: Functions (action)
    '-------------------------------------------------------------------------
    RefreshFunctionDescriptions(vIndex, func, r)

    If (Not UpdateFunction(sVarPre, ps, func, Controlname, v)) Then Exit Function
                                                                                          
    '-------------------------------------------------------------------------
    ' page: Functions (show)
    '-------------------------------------------------------------------------
    Set func = New FunctionClass
    RefreshFunctionDescriptions(vIndex, func, r)
                                                                                          
    sName = sVarPre & "_NAME_Init"
    ' disable condition
    func.Disabled(sName) = (IsModuleDisabled(r, sVarPre))
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (IsModuleDisabled(r, sVarPre)) Then
      d = d & GetTooltipModuleDisabled(r, sVarPre)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_StartTmr"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_StopTmr"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_ClearTmr"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_ReadTmr"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_LoadTmr"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_ReadCAPREL"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_LoadCAPREL"
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_Tmr5"
    ' disable condition
    func.Disabled(sName) = True
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_ISR32
    func.DisabledToolTip(sName) = d
    ' value for the control
    func.Value(sName) = IsISRSelected(r, sVarPre, GPT12_ & "T5IC", "Tmr5")

    sName = sVarPre & "_NAME_Tmr6"
    ' disable condition
    func.Disabled(sName) = True
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_ISR32
    func.DisabledToolTip(sName) = d
    ' value for the control
    func.Value(sName) = IsISRSelected(r, sVarPre, GPT12_ & "T6IC", "Tmr6")

    sName = sVarPre & "_NAME_CAPREL"
    ' disable condition
    func.Disabled(sName) = True
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_ISR32
    func.DisabledToolTip(sName) = d
    ' value for the control
    func.Value(sName) = IsISRSelected(r, sVarPre, GPT12_ & "CRIC", "CAPREL")

    sName = sVarPre & "_NAME_SetToggLatch"
    ' disable condition
    func.Disabled(sName) = (r.v(sPrefix & "USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_ClrToggLatch"
    ' disable condition
    func.Disabled(sName) = (r.v(sPrefix & "USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_CountUp"
    ' disable condition
    func.Disabled(sName) = (r.v(sPrefix & "USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_CountDown"
    ' disable condition
    func.Disabled(sName) = (r.v(sPrefix & "USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_SetTmrRemoteControl"
    ' disable condition
    func.Disabled(sName) = (r.v(sPrefix & "USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    If (Not ShowFunction(sVarPre, ps, func, v)) Then Exit Function


  End If         ' if Pagename

  OnShowPageFunctions = True
  Exit Function

OnShowPageFunctionsError:
  Errorbox "Can not show page", Err.Description
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageParameters(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageParameters = False

  If (Not ps.AddPage("Parameters")) Then Exit Function

  OnLoadPageParameters = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnChangingPageParameters(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageParameters = False

  Dim i As Integer
  Dim aParameters(1 To 16) As String

  If (Not ps.ExtenderCollection("Parameters").Loaded) And (Pagename = "Parameters") Then
    ps.ExtenderCollection("Parameters").Loaded = True

    '-------------------------------------------------------------------------
    ' frame: frmCAPCOMx_HFile
    '-------------------------------------------------------------------------
    If (Not ps.AddFrame("fra_HFile", 100, 100, 4150, 700, CAPTION_FRA_HFILE)) Then Exit Function
      If (Not ps.AddText("txt_HFile", 1475, 250, 2500, 325)) Then Exit Function
      If (Not ps.AddLabel("lbl_HFile", 0, 200, 300, 1250, 300, CAPTION_LBL_HFILE)) Then Exit Function

    
    '-------------------------------
    ' frame: fraParameters1
    '-------------------------------
    ' initialize the array
    For i = LBound(aParameters) To UBound(aParameters)
      aParameters(i) = ""
    Next i

    i = LBound(aParameters)
    aParameters(i) = "TIMER_5"
    i = i + 1
    aParameters(i) = "TIMER_6"
    i = i + 1

    If (Not ps.AddFrame("fraParameters1", 100, 900, 4150, 4400, CAPTION_FRA_PARAMETERS1)) Then Exit Function
      For i = LBound(aParameters) To UBound(aParameters)
        If Not (aParameters(i) = "") Then
          If (Not ps.AddText("txt_" & aParameters(i), 200, 300 * i, 3800, 325)) Then Exit Function
        End If
      Next i

  End If

  OnChangingPageParameters = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageParameters(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageParametersError
  OnShowPageParameters = False
    
  Dim r         As ProjectData
  Dim c         As Collection
  Dim e         As Collection
  Dim para      As ParameterClass
  Dim vIndex    As Variant
  Dim sVarPre   As String
  Dim sRegPre   As String
  Dim sName     As String
  Dim d         As String
  Dim i         As Integer

  vIndex = ps.Parameters.v("x")
  sVarPre = "GPT2" & vIndex
  sRegPre = sVarPre & "_"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set para = New ParameterClass


  If (Pagename = "Parameters") Then

    '-------------------------------------------------------------------------
    ' page: Parameters (action)
    '-------------------------------------------------------------------------
    RefreshParameterDescriptions(vIndex, para, r)

    If (Not UpdateParameter(sVarPre, ps, para, Controlname, v)) Then Exit Function


    '-------------------------------------------------------------------------
    ' page: Parameters (show)
    '-------------------------------------------------------------------------

    Set para = New ParameterClass
    RefreshParameterDescriptions(vIndex, para, r)

'    sName = sIndex & "_PARA_T2"
'    ' disable condition
'    para.Disabled(sName) = True
'    ' tooltip if control is disabled
'    d = FormatDisabledTooltip("Fred ...")
'    para.DisabledToolTip(sName) = d

    If (Not ShowParameter(sVarPre, ps, para, v)) Then Exit Function

  End If         ' if Pagename

  OnShowPageParameters = True
  Exit Function

OnShowPageParametersError:
    Errorbox "Can not show page", Err.Description
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnShowPageGPT2 function
'        und ist notwendig fuer die Anzeige von cboT6I.
'-----------------------------------------------------------------------------
'Parameters:
'        r               Typ von ProjektData
'        iExp            der Index aus der For - Next - Schleife
'-----------------------------------------------------------------------------
'Returns:
'        Text           vom Typ String
'*****************************************************************************
Function GetPrescalerResolution(r As ProjectData, iExp As Integer) As String
  On Error Resume Next
  Dim Exponent  As Integer
  Dim vIndex    As Variant
  
  GetPrescalerResolution = ""
  Exponent = iExp
  GetPrescalerResolution = "Fpd / " & 2 ^ Exponent * GetBPS2Factor(r.v(GPT12_ & "T6CON_BPS2"))
  GetPrescalerResolution = GetPrescalerResolution & " (Resolution: " & _
                           Format$(2 ^ Exponent * GetBPS2Factor(r.v(GPT12_ & "T6CON_BPS2")) / _
                           GetGPT2ModuleClock(r, vIndex), "0.000") & " s)"

  
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnShowPageCoreTimer3 function
'        and calculate underflow time.
'-----------------------------------------------------------------------------
'Parameters:
'        r               Typ von ProjektData
'        TimerNr
'-----------------------------------------------------------------------------
'Returns:
'        underflow time [s]
'
'*****************************************************************************
Function GetUnderflow(r As ProjectData, TimerNr As Variant) As Double
  On Error Resume Next
  Dim i       As Integer
  Dim vIndex  As Variant

  i = r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I")
  
  GetUnderflow = (r.v(GPT12_ & "T" & TimerNr & "_T" & TimerNr) + 1) * _
                 ((GetBPS2Factor(r.v(GPT12_ & "T6CON_BPS2")) * 2 ^ (i)) / _
                 GetGPT2ModuleClock(r, vIndex))

End Function


'*****************************************************************************
'Description:
'        This function is called from the GPT2 module
'        and calculate overflow time [ms].
'-----------------------------------------------------------------------------
'Parameters:
'        r               Typ von ProjektData
'        TimerNr
'-----------------------------------------------------------------------------
'Returns:
'        overflow time [s]
'
'*****************************************************************************
Function GetOverflow(r As ProjectData, TimerNr As Variant) As Double
  On Error Resume Next
  Dim i       As Integer
  Dim vIndex  As Variant

  i = r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I")
  
  GetOverflow = (65536 - r.v(GPT12_ & "T" & TimerNr & "_T" & TimerNr)) * _
                ((GetBPS2Factor(r.v(GPT12_ & "T6CON_BPS2")) * 2 ^ (i)) / _
                GetGPT2ModuleClock(r, vIndex))

End Function



'*****************************************************************************
'Description:
'        This function is called from the OnShowPageGPT1 function
'        and calculate the data of the timer gegister Tx.
'-----------------------------------------------------------------------------
'Parameters:
'        r               Typ von ProjektData
'        t               entered time [s]
'        rIndex
'             True       for overflow time
'             False      for underflow time
'        TimerNr
'-----------------------------------------------------------------------------
'Returns:
'        Value of Tx
'
'*****************************************************************************
Function GetTimerNrValue(r As ProjectData, t As Variant, rIndex As Boolean, TimerNr As Variant) As Long
  On Error Resume Next
  Dim i       As Integer
  Dim vIndex  As Variant
  
  If (t > GetMaxResolution(r, TimerNr)) Then
    t = GetMaxResolution(r, TimerNr)
  End If
  If (t < GetMinResolution(r, TimerNr)) Then
    t = GetMinResolution(r, TimerNr)
  End If

  
  i = r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I")
  
  If (rIndex) Then
    GetTimerNrValue = 65536 - t / ((GetBPS2Factor(r.v(GPT12_ & "T6CON_BPS2")) * 2 ^ (i)) / _
                      GetGPT2ModuleClock(r, vIndex))
    'Exit Function
  Else
    GetTimerNrValue = t / ((GetBPS2Factor(r.v(GPT12_ & "T6CON_BPS2")) * 2 ^ (i)) / _
                      GetGPT2ModuleClock(r, vIndex)) - 1
    'Exit Function
  End If

End Function



'*****************************************************************************
'Description:
'        This function is called from the GPT1 module
'        and calculate the maximum resolution [ms] for timer clock.
'-----------------------------------------------------------------------------
'Parameters:
'        r               Typ von ProjektData
'        TimerNr
'-----------------------------------------------------------------------------
'Returns:
'        Value of the max. resolution [s]
'
'*****************************************************************************
Function GetMaxResolution(r As ProjectData, TimerNr As Variant) As Double
  On Error Resume Next
  Dim vIndex  As Variant
  Dim i       As Integer
  
  i = r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I")
  
  GetMaxResolution = 65536 * GetBPS2Factor(r.v(GPT12_ & "T6CON_BPS2")) * 2 ^ (i) / _
                     GetGPT2ModuleClock(r, vIndex)

End Function

'*****************************************************************************
'Description:
'        This function is called from the GPT1 module
'        and calculate the maximum resolution [ms] for timer clock.
'-----------------------------------------------------------------------------
'Parameters:
'        r               Typ von ProjektData
'        TimerNr
'-----------------------------------------------------------------------------
'Returns:
'        Value of the max. resolution [s]
'
'*****************************************************************************
Function GetMinResolution(r As ProjectData, TimerNr As Variant) As Double
  On Error Resume Next
  Dim vIndex  As Variant
  Dim i       As Integer
  
  i = r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I")
  
  GetMinResolution = GetBPS2Factor(r.v(GPT12_ & "T6CON_BPS2")) * 2 ^ (i) / _
                     GetGPT2ModuleClock(r, vIndex)

End Function




