'#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:
'        CAPCOMx
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'CAPCOMx'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'                 
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        1.0   ahe         18.05.01     final version for XC164CS
'
'        1.1   ahe         05.06.02     no changes
'
'              ahe         06.08.02     - some changes on multi channel page
'                                       - neu interrupt pages
'        1.2   ste         18.12.02     final version for XC167CI
'        1.3   ste         24.02.03     caption for module clock changed
'
'
'*****************************************************************************
Dim CHANNELx As Peripherals


'*****************************************************************************
'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: OnLoadPagePinControl
    '-------------------------------------------------------------------------
    If (Not OnLoadPagePinControl(ps)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: Timer_x_y
    '-------------------------------------------------------------------------
    If (Not OnLoadPageTimer_x_y(ps, 12)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: Timer_x_y
    '-------------------------------------------------------------------------
    If (Not OnLoadPageTimer_x_y(ps, 13)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: OnLoadPageMultiChMode
    '-------------------------------------------------------------------------
    If (Not OnLoadPageMultiChMode(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Channels
    '-------------------------------------------------------------------------
    If (Not OnLoadPageChannels(ps)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: TrapControl
    '-------------------------------------------------------------------------
    If (Not OnLoadPageTrapControl(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, "CC6\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

    OnChangingPage = False
    Dim sVarPre As String
    Dim vIndex as Variant

    vIndex = ps.Parameters.v("x")
    sVarPre = "CCU" & vIndex

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

    '-------------------------------------------------------------------------
    'page: OnChangingPagePinControl
    '-------------------------------------------------------------------------
    If (Not OnChangingPagePinControl (ps, Pagename)) Then Exit Function
    
    '-------------------------------------------------------------------------
    'page: Timer_x_y
    '-------------------------------------------------------------------------
    If (Not OnChangingPageTimer_x_y (ps, Pagename, 12)) Then Exit Function
    
    '-------------------------------------------------------------------------
    'page: Timer_x_y
    '-------------------------------------------------------------------------
    If (Not OnChangingPageTimer_x_y (ps, Pagename, 13)) Then Exit Function
    
    '-------------------------------------------------------------------------
    'page: OnChangingPageMultiChMode
    '-------------------------------------------------------------------------
    If (Not OnChangingPageMultiChMode (ps, Pagename)) Then Exit Function
    
    '-------------------------------------------------------------------------
    'page: Channels
    '-------------------------------------------------------------------------
    If (Not OnChangingPageChannels (ps, Pagename)) Then Exit Function
    
    '-------------------------------------------------------------------------
    'page: TrapControl
    '-------------------------------------------------------------------------
    If (Not OnChangingPageTrapControl (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

    OnShow = False
    
    Dim sVarPre As String
    Dim vIndex as Variant

    vIndex = ps.Parameters.v("x")
    sVarPre = "CCU" & vIndex


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

    '-------------------------------------------------------------------------
    ' page: OnShowPagePinControl
    '-------------------------------------------------------------------------
    If (Not OnShowPagePinControl(ps, Controlname, Pagename, v)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: Timer_x_y
    '-------------------------------------------------------------------------
    If (Not OnShowPageTimer_x_y(ps, Controlname, Pagename, v, 12)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: Timer_x_y
    '-------------------------------------------------------------------------
    If (Not OnShowPageTimer_x_y(ps, Controlname, Pagename, v, 13)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: OnShowPageMultiChMode
    '-------------------------------------------------------------------------
    If (Not OnShowPageMultiChMode(ps, Controlname, Pagename, v)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: Channels
    '-------------------------------------------------------------------------
    If (Not OnShowPageChannels(ps, Controlname, Pagename, v)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: TrapControl
    '-------------------------------------------------------------------------
    If (Not OnShowPageTrapControl(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

    '-------------------------------------------------------------------------
    ' buttons: Channel
    '-------------------------------------------------------------------------
    If (Not OnButtonClickOnPageChannels(ps, Controlname)) Then Exit Function

    '-------------------------------------------------------------------------
    ' buttons: TrapControl
    '-------------------------------------------------------------------------
    If (Not OnButtonClickOnPageTrapControl(ps, Controlname)) Then Exit Function

  

    OnClick = True
    Exit Function

OnClickError:
    Errorbox "Can not Text in OnClick.", 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, "CC6\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

  If (Not ps.AddPage("Module Clock")) Then Exit Function

  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 sVarPre As String
  Dim vIndex As Variant
  Dim r As ProjectData

  vIndex = ps.Parameters.v("x")
  sVarPre = "CCU" & vIndex
  
  Set r = ps.ProjectData

  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, sVarPre & " Disabled Flag (CC" & vIndex & "DIS)")) Then Exit Function
        If (Not ps.AddOption("optDISx_0", 200, 350, 4800, 300, "Enable module; the peripheral is supplied with the clock signal")) Then Exit Function
        If (Not ps.AddOption("optDISx_1", 200, 825, 4800, 300, "Disable module; the clock input of peripheral 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 " & sVarPre & " module [MHz]")) Then Exit Function
        If (Not ps.AddLabel("lbl_box_InputClock", 1, 3550, 400, 1000, 300, "")) Then Exit Function

  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 bDisabled As Boolean
  Dim sVarPre As String
  Dim vIndex As Variant
  Dim sRegPre As String
  Dim i As Integer
  Dim iTmr_12 As Integer
  Dim iTmr_13 As Integer
  Dim iTmr As Integer
  Dim iCh_low As Integer
  Dim iCh_high As Integer
  Dim iChannel As Integer

  vIndex = ps.Parameters.v("x")
  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"
 
  iCh_low = 0
  iCh_high = 3
  iTmr_12 = 12
  iTmr_13 = 13

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

  If (Pagename = "Module Clock") Then
    '-------------------------------------------------------------------------
    ' page: ModuleClock (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: optDISx_0 (action)
        '---------------------------------------------------------------------
        Case "optDISx_0"
            r.v("SYSCON3_CC" & vIndex & "DIS") = 0

        '---------------------------------------------------------------------
        ' control: optDISx_1 (action)
        '---------------------------------------------------------------------
        Case "optDISx_1"
            r.v("SYSCON3_CC" & vIndex & "DIS") = 1
            
            Call DisableCC6Module(r, vIndex)

      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_CC" & vIndex & "DIS") = 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_CC" & vIndex & "DIS") = 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 = (IsModuleClockDisabled(r, vIndex))
      .Enabled = Not(bDisabled)
    End With

    With e("lbl_txt_InputClock")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleClockDisabled(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
        End If
      End If
    End With

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

    End With

    With e("lbl_box_InputClock")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleClockDisabled(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
        End If
      End If
    End With


  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 'PinControl'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPagePinControl(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPagePinControl = False

  If (Not ps.AddPage("Pin Control")) Then Exit Function

  OnLoadPagePinControl = 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 OnChangingPagePinControl(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPagePinControl = False
  
  Dim vIndex As Variant
  Dim sVarPre As String

  vIndex = ps.Parameters.v("x")
  sVarPre = "CCU" & vIndex

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

    '-------------------------------
    ' frame: frmCC60
    '-------------------------------
    If (Not ps.AddFrame("frmCC60",100,100, 4150, 1350, _
      "Control of Pin CC60 (" & GetPinName(sVarPre & "_CC60_I") & ")")) Then Exit Function
        If (Not ps.AddOption("optCC60_0", 200, 250, 3900, 380, "Pin CC60 is not used")) Then Exit Function
        If (Not ps.AddOption("optCC60_1", 200, 600, 3900, 380, "Use pin CC60 as input")) Then Exit Function
        If (Not ps.AddOption("optCC60_2", 200, 950, 3900, 380, "Use pin CC60 as output")) Then Exit Function

    '-------------------------------
    ' frame: frmCC61
    '-------------------------------
    If (Not ps.AddFrame("frmCC61",100,1500, 4150, 1350, _
      "Control of Pin CC61 (" & GetPinName(sVarPre & "_CC61_I") & ")")) Then Exit Function
        If (Not ps.AddOption("optCC61_0", 200, 250, 3900, 380, "Pin CC61 is not used")) Then Exit Function
        If (Not ps.AddOption("optCC61_1", 200, 600, 3900, 380, "Use pin CC61 as input")) Then Exit Function
        If (Not ps.AddOption("optCC61_2", 200, 950, 3900, 380, "Use pin CC61 as output")) Then Exit Function

    '-------------------------------
    ' frame: frmCC62
    '-------------------------------
    If (Not ps.AddFrame("frmCC62",100,2900, 4150, 1400, _
      "Control of Pin CC62 (" & GetPinName(sVarPre & "_CC62_I") & ")")) Then Exit Function
        If (Not ps.AddOption("optCC62_0", 200, 250, 3900, 380, "Pin CC62 is not used")) Then Exit Function
        If (Not ps.AddOption("optCC62_1", 200, 600, 3900, 380, "Use pin CC62 as input")) Then Exit Function
        If (Not ps.AddOption("optCC62_2", 200, 950, 3900, 380, "Use pin CC62 as output")) Then Exit Function

    '-------------------------------
    ' frame: frmCOUT60
    '-------------------------------
    If (Not ps.AddFrame("frmCOUT60",4400,100, 4150, 800, _
      "Control of Pin COUT60 (" & GetPinName(sVarPre & "_COUT60_O") & ")")) Then Exit Function
        If (Not ps.AddCheck("chkCOUT60", 200, 250, 2525, 400, _
            "Use pin COUT60 as output")) Then Exit Function

    '-------------------------------
    ' frame: frmCOUT62
    '-------------------------------
    If (Not ps.AddFrame("frmCOUT61",4400,950, 4150, 800, _
      "Control of Pin COUT61  (" & GetPinName(sVarPre & "_COUT61_O") & ")")) Then Exit Function
        If (Not ps.AddCheck("chkCOUT61", 200, 250, 2525, 400, _
            "Use pin COUT61 as output")) Then Exit Function

    '-------------------------------
    ' frame: frmCOUT61
    '-------------------------------
    If (Not ps.AddFrame("frmCOUT62",4400,1800, 4150, 800, _
      "Control of Pin COUT62 (" & GetPinName(sVarPre & "_COUT62_O") & ")")) Then Exit Function
        If (Not ps.AddCheck("chkCOUT62", 200, 250, 2525, 400, _
            "Use pin COUT62 as output")) Then Exit Function

    '-------------------------------
    ' frame: frm6
    '-------------------------------
    If (Not ps.AddFrame("frmCC6POS0",4400,2650, 4150, 800, _
      "Control of Pin #CC6POS0 (" & GetPinName(sVarPre & "_CC6POS0_I") & ")")) Then Exit Function
        If (Not ps.AddCheck("chkCC6POS0", 200, 250, 2525, 400, _
            "Use pin #CC6POS0 as input")) Then Exit Function

    '-------------------------------
    ' frame: frm7
    '-------------------------------
    If (Not ps.AddFrame("frmCC6POS1",4400,3500, 4150, 800, _
      "Control of Pin #CC6POS1 (" & GetPinName(sVarPre & "_CC6POS1_I") & ")")) Then Exit Function
        If (Not ps.AddCheck("chkCC6POS1", 200, 250, 2525, 400, _
            "Use pin #CC6POS1 as input")) Then Exit Function

    '-------------------------------
    ' frame: frm8
    '-------------------------------
    If (Not ps.AddFrame("frmCC6POS2",4400,4350, 4150, 800, _
      "Control of Pin #CC6POS2 (" & GetPinName(sVarPre & "_CC6POS2_I") & ")")) Then Exit Function
        If (Not ps.AddCheck("chkCC6POS2", 200, 250, 2525, 400, _
            "Use pin #CC6POS2 as input")) Then Exit Function

    '-------------------------------
    ' frame: frmCOUT63
    '-------------------------------
    If (Not ps.AddFrame("frmCOUT63",100,4350, 4150, 800, _
      "Control of Pin COUT63  (" & GetPinName(sVarPre & "_COUT63_O") & ")")) Then Exit Function
        If (Not ps.AddCheck("chkCOUT63", 200, 250, 2525, 400, _
            "Use pin COUT63 as output")) Then Exit Function

  End If
  OnChangingPagePinControl = 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 OnShowPagePinControl(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPagePinControlError

  OnShowPagePinControl = False

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

  vIndex = ps.Parameters.v("x")

  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"


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

  If (Pagename = "Pin Control") Then
    '-------------------------------------------------------------------------
    ' page: PinControl (action)
    '-------------------------------------------------------------------------
    For i = 0 To 2
        If (Controlname = "optCC6" & i & "_0") Then
            If     (GetPinFunction(r, sVarPre & "_CC6" & i & "_I") = 1) Then
                Call ReleaseAlternateInputPin(r, sVarPre & "_CC6" & i & "_I")
                If (r.v(sRegPre & "T12MSEL_MSEL6" & i) = 4 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 5 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 6 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 7 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 10 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 11 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 12 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 13 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 14) Then
                    
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)

                End If
            ElseIf (GetPinFunction(r, sVarPre & "_CC6" & i & "_O") = 2) Then
                Call ReleaseAlternateOutputPin(r, sVarPre & "_CC6" & i & "_O")
                If (r.v(sRegPre & "T12MSEL_MSEL6" & i) = 1 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 3) Then
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)
                End If
                Call SetModulationControlPagesToDefault(r, vIndex, "CC", i)
            End If
        End If

        If (Controlname = "optCC6" & i & "_1") Then
            If (GetPinFunction(r, sVarPre & "_CC6" & i & "_O") = 2) Then
                Call ReleaseAlternateOutputPin(r, sVarPre & "_CC6" & i & "_O")
                If (r.v(sRegPre & "T12MSEL_MSEL6" & i) = 1 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 3) Then
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)
                End If
                Call SetModulationControlPagesToDefault(r, vIndex, "CC", i)
            End If
            Call RequestAlternateInputPin(r, sVarPre & "_CC6" & i & "_I")
        End If

        If (Controlname = "optCC6" & i & "_2") Then
            If (GetPinFunction(r, sVarPre & "_CC6" & i & "_I") = 1) Then
                Call ReleaseAlternateInputPin(r, sVarPre & "_CC6" & i & "_I")
                If (r.v(sRegPre & "T12MSEL_MSEL6" & i) = 4 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 5 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 6 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 7 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 10 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 11 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 12 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 13 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 14) Then
                    
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)

                End If
            End If
            Call RequestAlternateOutputPin(r, sVarPre & "_CC6" & i & "_O")
        End If

        If (Controlname = "chkCOUT6" & i) Then
            If (v(1) = 0) Then
                Call ReleaseAlternateOutputPin(r, sVarPre & "_COUT6" & i & "_O")
                If (r.v(sRegPre & "T12MSEL_MSEL6" & i) = 2 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 3) Then
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)
                End If
                Call SetModulationControlPagesToDefault(r, vIndex, "COUT", i)
            Else
                Call RequestAlternateOutputPin(r, sVarPre & "_COUT6" & i & "_O")
            End If
        End If

        If (Controlname = "chkCC6POS" & i) Then
            If (v(1) = 0) Then
                Call ReleaseAlternateInputPin(r, sVarPre & "_CC6POS" & i & "_I")
                
                If (IsHallSensorModeEnable(r, vIndex)) Then
                    Call DisableHallSensorMode(r, vIndex)
                End If
                
                If (r.v(sRegPre & "T12MSEL_MSEL6" & i) = 9 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 10 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 11 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 12 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 13 Or _
                    r.v(sRegPre & "T12MSEL_MSEL6" & i) = 14) Then
                    
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)

                End If

                r.v(sRegPre & "IEN_ENIDLE") = 0
                r.v(sRegPre & "IEN_ENCHE") = 0
                r.v(sRegPre & "IEN_ENWHE") = 0
                r.v(sRegPre & "MCMCTR_SWSEL") = 0

            Else
                Call RequestAlternateInputPin(r, sVarPre & "_CC6POS" & i & "_I")
            End If
        End If

    Next i
    
    i = 3
    If (Controlname = "chkCOUT6" & i) Then
        If (v(1) = 0) Then
            Call ReleaseAlternateOutputPin(r, sVarPre & "_COUT6" & i & "_O")
            Call SelectModeForCC6Channelx(r, vIndex, i, 0)
        Else
            Call RequestAlternateOutputPin(r, sVarPre & "_COUT6" & i & "_O")
        End If
    End If

    '-------------------------------------------------------------------------
    ' page: PinControl (show)
    '-------------------------------------------------------------------------

    For i = 0 To 2

        '-------------------------------------------------------------------------
        ' control: optCC60_0 (show)
        '-------------------------------------------------------------------------
        With c("optCC6" & i & "_0")
            bDisabled = (IsModuleClockDisabled(r, vIndex))
            .Enabled = Not(bDisabled)
            .Value = -CInt(GetPinFunction(r, sVarPre & "_CC6" & i & "_I") = 0 And _
                           GetPinFunction(r, sVarPre & "_CC6" & i & "_O") = 0)
        End With

        With e("optCC6" & i & "_0")
            If (bDisabled) Then
                .DisabledTooltipText = TOOLTIP_DISABLED_IF
                If (IsModuleClockDisabled(r, vIndex)) Then
                    .DisabledTooltipText = .DisabledTooltipText & _
                      GetTooltipModuleClockDisabled(r, vIndex)
                End If
            Else
                'enabled tooltip
            End If
        End With

        '-------------------------------------------------------------------------
        ' control: optCC60_1 (show)
        '-------------------------------------------------------------------------
        With c("optCC6" & i & "_1")
            bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                         (IsAlternateInputPinFree(r, sVarPre & "_CC6" & i & "_I") = False And _
                         Not(GetPinFunction(r, sVarPre & "_CC6" & i & "_O") = 2) ))
            .Enabled = Not(bDisabled)
            .Value = -CInt(GetPinFunction(r, sVarPre & "_CC6" & i & "_I") = 1)
        End With

        With e("optCC6" & i & "_1")
            If (bDisabled) Then
                .DisabledTooltipText = TOOLTIP_DISABLED_IF
                If (IsModuleClockDisabled(r, vIndex)) Then
                    .DisabledTooltipText = .DisabledTooltipText & _
                      GetTooltipModuleClockDisabled(r, vIndex)
                End If
                If (IsAlternateInputPinFree(r, sVarPre & "_CC6" & i & "_I") = False And _
                         Not(GetPinFunction(r, sVarPre & "_CC6" & i & "_O") = 2)) Then
                    .DisabledTooltipText = .DisabledTooltipText & _
                      GetDisabledAlternatePinTooltip(r, sVarPre & "_CC6" & i & "_I")
                End If
            Else
                'enabled tooltip
            End If
        End With

        '-------------------------------------------------------------------------
        ' control: optCC60_2 (show)
        '-------------------------------------------------------------------------
        With c("optCC6" & i & "_2")
            bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                         (IsAlternateOutputPinFree(r, sVarPre & "_CC6" & i & "_O") = False And _
                         Not(GetPinFunction(r, sVarPre & "_CC6" & i & "_I") = 1) ))
            .Enabled = Not(bDisabled)
            .Value = -CInt(GetPinFunction(r, sVarPre & "_CC6" & i & "_O") = 2)
        End With

        With e("optCC6" & i & "_2")
            If (bDisabled) Then
                .DisabledTooltipText = TOOLTIP_DISABLED_IF
                If (IsModuleClockDisabled(r, vIndex)) Then
                    .DisabledTooltipText = .DisabledTooltipText & _
                      GetTooltipModuleClockDisabled(r, vIndex)
                End If
                If (IsAlternateOutputPinFree(r, sVarPre & "_CC6" & i & "_O") = False And _
                         Not(GetPinFunction(r, sVarPre & "_CC6" & i & "_I") = 1)) Then
                    .DisabledTooltipText = .DisabledTooltipText & _
                      GetDisabledAlternatePinTooltip(r, sVarPre & "_CC6" & i & "_O")
                End If
            Else
                'enabled tooltip
            End If
        End With

        '-------------------------------------------------------------------------
        ' control: chkCOUT60_2 (show)
        '-------------------------------------------------------------------------
        With c("chkCOUT6" & i)
            bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                         IsAlternateOutputPinFree(r, sVarPre & "_COUT6" & i & "_O") = False)
            .Enabled = Not(bDisabled)
            .Value = -CInt(GetPinFunction(r, sVarPre & "_COUT6" & i & "_O") = 2)
        End With

        With e("chkCOUT6" & i)
            If (bDisabled) Then
                .DisabledTooltipText = TOOLTIP_DISABLED_IF
                If (IsModuleClockDisabled(r, vIndex)) Then
                    .DisabledTooltipText = .DisabledTooltipText & _
                      GetTooltipModuleClockDisabled(r, vIndex)
                End If
                If (IsAlternateOutputPinFree(r, sVarPre & "_COUT6" & i & "_O") = False) Then
                    .DisabledTooltipText = .DisabledTooltipText & _
                      GetDisabledAlternatePinTooltip(r, sVarPre & "_COUT6" & i & "_O")
                End If
            Else
                'enabled tooltip
            End If
        End With

        '-------------------------------------------------------------------------
        ' control: chkCOUT60_2 (show)
        '-------------------------------------------------------------------------
        With c("chkCC6POS" & i)
            bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                         IsAlternateInputPinFree(r, sVarPre & "_CC6POS" & i & "_I") = False)
            .Enabled = Not(bDisabled)
            .Value = -CInt(GetPinFunction(r, sVarPre & "_CC6POS" & i & "_I") = 1)
        End With

        With e("chkCC6POS" & i)
            If (bDisabled) Then
                .DisabledTooltipText = TOOLTIP_DISABLED_IF
                If (IsModuleClockDisabled(r, vIndex)) Then
                    .DisabledTooltipText = .DisabledTooltipText & _
                      GetTooltipModuleClockDisabled(r, vIndex)
                End If
                If (IsAlternateInputPinFree(r, sVarPre & "_CC6POS" & i & "_I") = False) Then
                    .DisabledTooltipText = .DisabledTooltipText & _
                      GetDisabledAlternatePinTooltip(r, sVarPre & "_CC6POS" & i & "_I")
                End If
            Else
                'enabled tooltip
            End If
        End With

    Next i

    i = 3
    '-------------------------------------------------------------------------
    ' control: chkCOUT60_2 (show)
    '-------------------------------------------------------------------------
    With c("chkCOUT6" & i)
        bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                     IsAlternateOutputPinFree(r, sVarPre & "_COUT6" & i & "_O") = False)
        .Enabled = Not(bDisabled)
        .Value = -CInt(GetPinFunction(r, sVarPre & "_COUT6" & i & "_O") = 2)
    End With

    With e("chkCOUT6" & i)
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  GetTooltipModuleClockDisabled(r, vIndex)
            End If
            If (IsAlternateOutputPinFree(r, sVarPre & "_COUT6" & i & "_O") = False) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  GetDisabledAlternatePinTooltip(r, sVarPre & "_COUT6" & i & "_O")
            End If
        Else
            'enabled tooltip
        End If
    End With

  End If

  OnShowPagePinControl = True
  Exit Function

OnShowPagePinControlError:
  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 'Timer_x_y'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageTimer_x_y(ps As Object, iTmr As Integer) As Boolean
  On Error Resume Next

  OnLoadPageTimer_x_y = False

  If (Not ps.AddPage("T" & iTmr)) Then Exit Function

  OnLoadPageTimer_x_y = 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 OnChangingPageTimer_x_y(ps As Object, Pagename As String, iTmr As Integer) As Boolean
  On Error Resume Next

  OnChangingPageTimer_x_y = False
  Dim vIndex As Variant
  Dim sCCx As String

  vIndex = ps.Parameters.v("x")

  sCCx = "CC" & vIndex
  
  
  If (Not ps.ExtenderCollection("T" & iTmr).Loaded) And _
       (Pagename = "T" & iTmr) Then
    ps.ExtenderCollection("T" & iTmr).Loaded = True
  

    '-------------------------------
    ' frame: frmTxCLK
    '-------------------------------
    If (Not ps.AddFrame("frmT" & iTmr & "CLK",100,100, 5550, 1000, _
        "Input Selection (T" & iTmr & "CLK)")) Then Exit Function
        If (Not ps.AddCombo("cboT" & iTmr & "CLK", 1525, 400, 3875, 315)) Then Exit Function
        If (Not ps.AddLabel("lblT" & iTmr & "CLK", 0, 200, 450, 1225, 330, _
            "Input selection")) Then Exit Function

    '-------------------------------
    ' frame: frmTxR
    '-------------------------------
    If (Not ps.AddFrame("frmT" & iTmr & "RR",5800,100, 2800, 1000, _
        "Timer " & iTmr & " Start Control")) Then Exit Function
        If (Not ps.AddCheck("chkT" & iTmr & "RS", 200, 350, 2525, 400, _
            "Start T" & iTmr & " after initialization (T" & iTmr & "RS)")) Then Exit Function

    If (iTmr = 12) Then
        '-------------------------------
        ' frame: frmTxSSC
        '-------------------------------
        If (Not ps.AddFrame("frmT" & iTmr & "SSC",100,1150, 4350, 1000, _
            "Timer " & iTmr & " Single Shot Control")) Then Exit Function
            If (Not ps.AddCheck("chkT" & iTmr & "SSC", 200, 400, 3900, 300, _
                "Enable single shot mode (T" & iTmr & "SSC)")) Then Exit Function

        '-------------------------------
        ' frame: frmCTM
        '-------------------------------
        If (Not ps.AddFrame("frmCTM",100,2200, 4350, 1200, _
            "T" & iTmr & " Operating Mode (CTM)")) Then Exit Function
            If (Not ps.AddOption("optCTM_0", 200, 300, 4100, 300, _
                "Edge aligned mode: count up")) Then Exit Function
            If (Not ps.AddOption("optCTM_1", 200, 700, 4100, 300, _
                "Center aligned mode: count up/down")) Then Exit Function

        '-------------------------------
        ' frame: frmTxIE
        '-------------------------------
        If (Not ps.AddFrame("frmT" & iTmr & "IC",100,3450, 4350, 1200, _
            "Interrupt Control")) Then Exit Function
            If (Not ps.AddCheck("chkENT" & iTmr & "PM", 200, 250, 4000, 300, _
                "Enable interrupt for T" & iTmr & " period match (ENT" & iTmr & "PM)")) Then Exit Function
            If (Not ps.AddCheck("chkENT" & iTmr & "OM", 200, 700, 4000, 300, _
                "Enable interrupt for T12 one match (ENT" & iTmr & "OM)")) Then Exit Function

        '-------------------------------
        ' frame: frmIxPR
        '-------------------------------
        If (Not ps.AddFrame("frmT" & iTmr & "PR",4600,1150, 4000, 1700, _
            "Timer " & iTmr & " Period (T" & iTmr & "PR)")) Then Exit Function
            If (Not ps.AddLabel("lblT" & iTmr & "PR_time", 0, 200, 550, 2000, 300, _
                "Required period [xxs]")) Then Exit Function
            If (Not ps.AddText("txtT" & iTmr & "PR_time", 2200, 500, 1200, 300)) Then Exit Function
        
            If (Not ps.AddLabel("lblT" & iTmr & "PR", 0, 200, 1100, 2000, 300, _
                "Period register (T" & iTmr & "PR)")) Then Exit Function
            If (Not ps.AddText("txtT" & iTmr & "PR", 2200, 1050, 1200, 300)) Then Exit Function

        '-------------------------------
        ' frame: frmDTM
        '-------------------------------
        If (Not ps.AddFrame("frmDTM",4600,2900, 4000, 1750, _
            "Dead Time Control")) Then Exit Function
            If (Not ps.AddLabel("lblDTM_time", 0, 200, 550, 2000, 300, _
                "Dead time [xxs]")) Then Exit Function
            If (Not ps.AddText("txtDTM_time", 2200, 500, 1200, 300)) Then Exit Function
        
            If (Not ps.AddLabel("lblDTM", 0, 200, 1100, 2000, 300, _
                "Dead time register (DTM)")) Then Exit Function
            If (Not ps.AddText("txtDTM", 2200, 1050, 1200, 300)) Then Exit Function


    Else

        '-------------------------------
        ' frame: frmT13TEC
        '-------------------------------
        If (Not ps.AddFrame("frmT13TEC",100,1150, 8500, 1000, _
            "Timer T13 Trigger Event Control (T13TEC)")) Then Exit Function
            If (Not ps.AddCombo("cboT13TEC", 1500, 400, 6000, 315)) Then Exit Function
            If (Not ps.AddLabel("lblT13TEC", 0, 200, 450, 1200, 330, _
                "Trigger control")) Then Exit Function

        '-------------------------------
        ' frame: frmT13TED
        '-------------------------------
        If (Not ps.AddFrame("frmT13TED",100,2200, 8500, 1000, _
            "Timer T13 Trigger Event Direction (T13TED)")) Then Exit Function
            If (Not ps.AddCombo("cboT13TED", 1500, 400, 6000, 315)) Then Exit Function
            If (Not ps.AddLabel("lblT13TED", 0, 200, 450, 1200, 330, _
                "Direction control")) Then Exit Function

        '-------------------------------
        ' frame: frmTxSSC
        '-------------------------------
        If (Not ps.AddFrame("frmT" & iTmr & "SSC",100,3250, 4350, 800, _
            "Timer " & iTmr & " Single Shot Control")) Then Exit Function
            If (Not ps.AddCheck("chkT" & iTmr & "SSC", 200, 300, 3900, 300, _
                "Enable single shot mode (T" & iTmr & "SSC)")) Then Exit Function

        '-------------------------------
        ' frame: frmTxIE
        '-------------------------------
        If (Not ps.AddFrame("frmT" & iTmr & "IC",100,4100, 4350, 1200, _
            "Interrupt Control")) Then Exit Function
            If (Not ps.AddCheck("chkENT" & iTmr & "PM", 200, 250, 4000, 300, _
                "Enable interrupt for T" & iTmr & " period match (ENT" & iTmr & "PM)")) Then Exit Function
            If (Not ps.AddCheck("chkENT" & iTmr & "CM", 200, 700, 4000, 300, _
                "Enable interrupt for T13 compare match (ENT" & iTmr & "CM)")) Then Exit Function
        

        '-------------------------------
        ' frame: frmIxPR
        '-------------------------------
        If (Not ps.AddFrame("frmT" & iTmr & "PR",4600,3250, 4000, 2050, _
            "Timer " & iTmr & " Period (T" & iTmr & "PR)")) Then Exit Function
            If (Not ps.AddLabel("lblT" & iTmr & "PR_time", 0, 200, 550, 2000, 300, _
                "Required period [xxs]")) Then Exit Function
            If (Not ps.AddText("txtT" & iTmr & "PR_time", 2200, 500, 1200, 300)) Then Exit Function
        
            If (Not ps.AddLabel("lblT" & iTmr & "PR", 0, 200, 1500, 2000, 300, _
                "Period register (T" & iTmr & "PR)")) Then Exit Function
            If (Not ps.AddText("txtT" & iTmr & "PR", 2200, 1450, 1200, 300)) Then Exit Function

    End If

  End If
  OnChangingPageTimer_x_y = 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 OnShowPageTimer_x_y(ps As Object, Controlname As String, Pagename As String, v() As Variant, iTmr As Integer) As Boolean
  On Error GoTo OnShowPageTimer_x_yError

  OnShowPageTimer_x_y = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim iTmr_12 As Integer
  Dim iTmr_13 As Integer
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim s As String
  Dim sDisabledTooltip As String
  Dim bDisabled As Boolean
  Dim i As Integer
  Dim uTime As UnitType
  Dim dDivider As Double

  vIndex = ps.Parameters.v("x")

  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"

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

  If (Pagename = "T" & iTmr) Then
    '-------------------------------------------------------------------------
    ' page: Timer_x_y (action)
    '-------------------------------------------------------------------------
  
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: cboT" & iTmr & "CLK (action)
        '---------------------------------------------------------------------
        Case "cboT" & iTmr & "CLK"
            For i = 0 To 7
                If (v(1) = GetTextForCLKcbo(r, vIndex, iTmr, i)) Then
                    r.v(sRegPre & "TCTR0_T" & iTmr & "CLK") = i
                End If
            Next i                    

        '---------------------------------------------------------------------
        ' control: chkT..RR (action)
        '---------------------------------------------------------------------
        Case "chkT" & iTmr & "RS"
            r.v(sRegPre & "TCTR4_T" & iTmr & "RS") = v(1)
            If (v(1) = 1) Then
                If (iTmr = 13) Then
                    r.v(sRegPre & "TCTR2_T13TEC") = 0
                End If
            End If
        
        '---------------------------------------------------------------------
        ' control: chkT..SSC (action)
        '---------------------------------------------------------------------
        Case "chkT" & iTmr & "SSC"
            r.v(sRegPre & "TCTR2_T" & iTmr & "SSC") = v(1)
        
        '---------------------------------------------------------------------
        ' control: chkENT" & iTmr & "PM (action)
        '---------------------------------------------------------------------
        Case "chkENT" & iTmr & "PM"
            r.v(sRegPre & "IEN_ENT" & iTmr & "PM") = v(1)
  
        '---------------------------------------------------------------------
        ' control: txtT.. (action)
        '---------------------------------------------------------------------
        Case "txtT" & iTmr & "PR"
            If (IsInputFormatOK(v(1), "H4", c("lblT" & iTmr & "PR").Caption, 1, 65535)) Then
              r.sfr(sRegPre & "T" & iTmr & "PR") = v(1)
              If (iTmr = 12) Then
                  For i = 0 To 2
                      Call UpdateDutyCycle(r, vIndex, i)
                  Next i
              Else
                  Call UpdateDutyCycle(r, vIndex, 3)
              End If
            Else
                Exit Function
            End If
        
        '---------------------------------------------------------------------
        ' control: txtT" & iTmr & "PR_time (action)
        '---------------------------------------------------------------------
        Case "txtT" & iTmr & "PR_time"
            uTime = ConvertTime(GetOverflow(r, vIndex, iTmr))
            dDivider = uTime.dDivider
            If (IsInputFormatOK(v(1), "F", c("lblT" & iTmr & "PR_time").Caption, _
                Format(GetMinResolution(r, vIndex, iTmr) / dDivider, "0.0000000"), _
                Format(GetMaxResolution(r, vIndex, iTmr) / dDivider, "0.0000000"))) Then
        
              r.sfr(sRegPre & "T" & iTmr & "PR") = _
                GetTimerNrValue(r, vIndex, v(1) * dDivider, True, iTmr)
            Else
                Exit Function
            End If
        


      Case Else
    End Select
  
    If (iTmr = 12) Then
        Select Case (Controlname)
            '---------------------------------------------------------------------
            ' control: optCTM_0 (action)
            '---------------------------------------------------------------------
            Case ("optCTM_0")
                r.v(sRegPre & "TCTR0_CTM") = 0
                r.v(sRegPre & "TCTR2_T13TED") = 1

            '---------------------------------------------------------------------
            ' control: optCTM_1 (action)
            '---------------------------------------------------------------------
            Case ("optCTM_1")
                r.v(sRegPre & "TCTR0_CTM") = 1

            '---------------------------------------------------------------------
            ' control: txtT.. (action)
            '---------------------------------------------------------------------
            Case "txtDTM"
                If (IsInputFormatOK(v(1), "H2", c("lblDTM").Caption, 1, 63)) Then
                  r.l(sRegPre & "T12DTC_DTM") = v(1)
                Else
                    Exit Function
                End If
        
            '---------------------------------------------------------------------
            ' control: txtT" & iTmr & "PR_time (action)
            '---------------------------------------------------------------------
            Case "txtDTM_time"
                uTime = ConvertTime(GetOverflowDTM(r, vIndex, iTmr))
                dDivider = uTime.dDivider
                If (IsInputFormatOK(v(1), "F", c("lblDTM_time").Caption, _
                    Format(GetMinResolutionDTM(r, vIndex, iTmr) / dDivider, "0.000"), _
                    Format(GetMaxResolutionDTM(r, vIndex, iTmr) / dDivider, "0.000"))) Then
        
                  r.l(sRegPre & "T12DTC_DTM") = _
                    GetTimerNrValueDTM(r, vIndex, v(1) * dDivider, True, iTmr)
                Else
                    Exit Function
                End If

            '---------------------------------------------------------------------
            ' control: chkENT" & iTmr & "PM (action)
            '---------------------------------------------------------------------
            Case "chkENT" & iTmr & "OM"
                r.v(sRegPre & "IEN_ENT" & iTmr & "OM") = v(1)
  
            Case Else
        End Select
        
    Else
        Select Case (Controlname)
            '---------------------------------------------------------------------
            ' control: chkENT" & iTmr & "PM (action)
            '---------------------------------------------------------------------
            Case "chkENT" & iTmr & "CM"
                r.v(sRegPre & "IEN_ENT" & iTmr & "CM") = v(1)

            '---------------------------------------------------------------------
            ' control: cboT13TEC (action)
            '---------------------------------------------------------------------
            Case "cboT13TEC"
                Select Case (v(1))
                    Case ("Disable trigger control")
                        r.v(sRegPre & "TCTR2_T13TEC") = 0

                    Case ("Start T13 on a T12 compare event on channel 0")
                        r.v(sRegPre & "TCTR2_T13TEC") = 1

                    Case ("Start T13 on a T12 compare event on channel 1")
                        r.v(sRegPre & "TCTR2_T13TEC") = 2

                    Case ("Start T13 on a T12 compare event on channel 2")
                        r.v(sRegPre & "TCTR2_T13TEC") = 3

                    Case ("Start T13 on any T12 compare event (ch. 0, 1, 2)")
                        r.v(sRegPre & "TCTR2_T13TEC") = 4

                    Case ("Start T13 upon a period-match of T12")
                        r.v(sRegPre & "TCTR2_T13TEC") = 5

                    Case ("Start T13 upon a zero-match of T12 (while counting up)")
                        r.v(sRegPre & "TCTR2_T13TEC") = 6
                        r.v(sRegPre & "TCTR2_T13TED") = 1

                    Case ("Start T13 on any hall state change")
                        r.v(sRegPre & "TCTR2_T13TEC") = 7
                    
                    Case Else
                End Select

            '---------------------------------------------------------------------
            ' control: cboT13TED (action)
            '---------------------------------------------------------------------
            Case "cboT13TED"
                Select Case (v(1))
                    Case ("")
                        r.v(sRegPre & "TCTR2_T13TED") = 0

                    Case ("Start T13 while T12 is counting up")
                        r.v(sRegPre & "TCTR2_T13TED") = 1

                    Case ("Start T13 while T12 is counting down")
                        r.v(sRegPre & "TCTR2_T13TED") = 2

                    Case ("Start T13 independent on the count direction of T12")
                        r.v(sRegPre & "TCTR2_T13TED") = 3

                    Case Else
                End Select

            Case Else
        End Select
  
    End If
  
    '-------------------------------------------------------------------------
    ' page: Timer_x_y (show)
    '-------------------------------------------------------------------------
  
    bDisabled = (IsModuleClockDisabled(r, vIndex))
    
    sDisabledTooltip = ""
    sDisabledTooltip = TOOLTIP_DISABLED_IF
    
    If (IsModuleClockDisabled(r, vIndex)) Then
        sDisabledTooltip = sDisabledTooltip & GetTooltipModuleClockDisabled(r, vIndex)
    End If
    
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmT" & iTmr & "CLK").Caption, c, e, bDisabled, sDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmT" & iTmr & "RR").Caption, c, e, bDisabled, sDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmT" & iTmr & "SSC").Caption, c, e, bDisabled, sDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmT" & iTmr & "IC").Caption, c, e, bDisabled, sDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmT" & iTmr & "PR").Caption, c, e, bDisabled, sDisabledTooltip, "")

    If (iTmr = 12) Then
        Call SetDefaultPropertiesForAllControlsOnFrame(c("frmCTM").Caption, c, e, bDisabled, sDisabledTooltip, "")
        Call SetDefaultPropertiesForAllControlsOnFrame(c("frmDTM").Caption, c, e, bDisabled, sDisabledTooltip, "")
    End If
  
    bDisabled = (bDisabled Or r.v(sRegPre & "TCTR4_T" & iTmr & "RS") = 1)
    
    If (r.v(sRegPre & "TCTR4_T" & iTmr & "RS") = 1) Then
        sDisabledTooltip = sDisabledTooltip & FormatDisabledTooltip("start control is enabled")
    End If

    If (iTmr = 13) Then
        Call SetDefaultPropertiesForAllControlsOnFrame(c("frmT13TEC").Caption, c, e, bDisabled, sDisabledTooltip, "")
    End If

    bDisabled = (bDisabled Or r.v(sRegPre & "TCTR2_T13TEC") = 0)

    If (r.v(sRegPre & "TCTR2_T13TEC") = 0) Then
        sDisabledTooltip = sDisabledTooltip & FormatDisabledTooltip("the trigger control is disabled")
    End If

    If (iTmr = 13) Then
        Call SetDefaultPropertiesForAllControlsOnFrame(c("frmT13TED").Caption, c, e, bDisabled, sDisabledTooltip, "")
    End If
    '-------------------------------------------------------------------------
    ' control: cboTxCLK (show)
    '-------------------------------------------------------------------------
    With c("cboT" & iTmr & "CLK")
        .Clear
        For i = 0 To 7
          .AddItem GetTextForCLKcbo(r, vIndex, iTmr, i)
        Next i
        .ListIndex = r.v(sRegPre & "TCTR0_T" & iTmr & "CLK")
    
        
    End With

    '-------------------------------------------------------------------------
    ' control: chkTxRR (show)
    '-------------------------------------------------------------------------
    With c("chkT" & iTmr & "RS")
        .Value = -CInt(r.v(sRegPre & "TCTR4_T" & iTmr & "RS") = 1)
    End With
    
    '-------------------------------------------------------------------------
    ' control: chkTxSSC (show)
    '-------------------------------------------------------------------------
    With c("chkT" & iTmr & "SSC")
        .Value = -CInt(r.v(sRegPre & "TCTR2_T" & iTmr & "SSC") = 1)
    End With
    
    '-------------------------------------------------------------------------
    ' control: chkENT" & iTmr & "PM (show)
    '-------------------------------------------------------------------------
    With c("chkENT" & iTmr & "PM")
        .Value = -CInt(r.v(sRegPre & "IEN_ENT" & iTmr & "PM") = 1)
    End With
    
    '-------------------------------------------------------------------------
    ' control: txtTxPR (show)
    '-------------------------------------------------------------------------
    With c("txtT" & iTmr & "PR")
        If (IsModuleClockDisabled(r, vIndex)) Then
            .Text = CALCULATION_NOT_POSSIBLE
        Else
            .Text = FormatTextOutput(r.sfr(sRegPre & "T" & iTmr & "PR"), "H4")
        End If

    End With
    
    '-------------------------------------------------------------------------
    ' control: txtT" & iTmr & "PR_time (show)
    '-------------------------------------------------------------------------
    With c("txtT" & iTmr & "PR_time")
        If (IsModuleClockDisabled(r, vIndex)) Then
            .Text = CALCULATION_NOT_POSSIBLE
            c("lblT" & iTmr & "PR_time").Caption = "Period [s]"
        Else
            uTime = ConvertTime(GetOverflow(r, vIndex, iTmr))
            .Text = Format(uTime.dValue, "0.000000")
            c("lblT" & iTmr & "PR_time").Caption = "Period [" & uTime.sUnit & "]"
        End If
    
    End With
    

    If (iTmr = 12) Then
        '-------------------------------------------------------------------------
        ' control: optCTM_0 (show)
        '-------------------------------------------------------------------------
        With c("optCTM_0")
            .Value = -CInt(r.v(sRegPre & "TCTR0_CTM") = 0)
        End With

        '-------------------------------------------------------------------------
        ' control: optCTM_1 (show)
        '-------------------------------------------------------------------------
        With c("optCTM_1")
            .Value = -CInt(r.v(sRegPre & "TCTR0_CTM") = 1)
        End With

        '-------------------------------------------------------------------------
        ' control: txtTxPR (show)
        '-------------------------------------------------------------------------
        With c("txtDTM")
            If (IsModuleClockDisabled(r, vIndex)) Then
                .Text = CALCULATION_NOT_POSSIBLE
            Else
                .Text = FormatTextOutput(r.l(sRegPre & "T12DTC_DTM"), "H2")
            End If
        End With
    
        '-------------------------------------------------------------------------
        ' control: txtT" & iTmr & "PR_time (show)
        '-------------------------------------------------------------------------
        With c("txtDTM_time")
            If (IsModuleClockDisabled(r, vIndex)) Then
                .Text = CALCULATION_NOT_POSSIBLE
                c("lblDTM_time").Caption = "Dead time [s]"
            Else
                uTime = ConvertTime(GetOverflowDTM(r, vIndex, iTmr))
                .Text = Format(uTime.dValue, "0.000")
                c("lblDTM_time").Caption = "Dead time [" & uTime.sUnit & "]"
            End If
    
        End With

        '-------------------------------------------------------------------------
        ' control: chkENT" & iTmr & "OM (show)
        '-------------------------------------------------------------------------
        With c("chkENT" & iTmr & "OM")
            .Value = -CInt(r.v(sRegPre & "IEN_ENT" & iTmr & "OM") = 1)
        End With
    
    Else
        '-------------------------------------------------------------------------
        ' control: cboT13TEC (show)
        '-------------------------------------------------------------------------
        With c("cboT13TEC")
            .Clear
            .AddItem "Disable trigger control"
            .AddItem "Start T13 on a T12 compare event on channel 0"
            .AddItem "Start T13 on a T12 compare event on channel 1"
            .AddItem "Start T13 on a T12 compare event on channel 2"
            .AddItem "Start T13 on any T12 compare event (ch. 0, 1, 2)"
            .AddItem "Start T13 upon a period-match of T12"
            .AddItem "Start T13 upon a zero-match of T12 (while counting up)"
            .AddItem "Start T13 on any hall state change"
            .ListIndex = r.v(sRegPre & "TCTR2_T13TEC")
        End With

        '-------------------------------------------------------------------------
        ' control: cboT13TED (show)
        '-------------------------------------------------------------------------
        With c("cboT13TED")
            .Clear
            .AddItem "Start T13 while T12 is counting up"
            If (r.v(sRegPre & "TCTR0_CTM") = 1 And Not(r.v(sRegPre & "TCTR2_T13TEC") = 6)) Then
                .AddItem "Start T13 while T12 is counting down"
                .AddItem "Start T13 independent on the count direction of T12"
            End If
            
            .ListIndex = r.v(sRegPre & "TCTR2_T13TED") - 1

        End With
        '-------------------------------------------------------------------------
        ' control: chkENT" & iTmr & "CM (show)
        '-------------------------------------------------------------------------
        With c("chkENT" & iTmr & "CM")
            .Value = -CInt(r.v(sRegPre & "IEN_ENT" & iTmr & "CM") = 1)
        End With
    
    End If
  

  
  End If

  OnShowPageTimer_x_y = True
  Exit Function

OnShowPageTimer_x_yError:
  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 'MultiChMode'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageMultiChMode(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageMultiChMode = False

  If (Not ps.AddPage("Multi Ch.")) Then Exit Function

  OnLoadPageMultiChMode = 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 OnChangingPageMultiChMode(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageMultiChMode = False
  
  If (Not ps.ExtenderCollection("Multi Ch.").Loaded) And (Pagename = "Multi Ch.") Then
    ps.ExtenderCollection("Multi Ch.").Loaded = True
  

    '-------------------------------
    ' frame: frmMCMEN
    '-------------------------------
    If (Not ps.AddFrame("frmMCMEN",100,100, 4150, 1000, "Multi Channel Mode Control")) Then Exit Function
        If (Not ps.AddCheck("chkMCMEN", 200, 350, 3150, 380, "Enable multi channel mode (MCMEN)")) Then Exit Function

    '-------------------------------
    ' frame: frmEnHallMode
    '-------------------------------
    If (Not ps.AddFrame("frmEnHallMode",4400,100, 4150, 1000, "Hall Sensor Control")) Then Exit Function
        If (Not ps.AddCheck("chkEnHallMode", 200, 350, 3900, 380, "Enable hall sensor mode (CCU6_T12MSEL)")) Then Exit Function

    '-------------------------------
    ' frame: frmSWSEL
    '-------------------------------
    If (Not ps.AddFrame("frmSWSEL",100,1150, 4150, 2500, "Switching Selection (SWSEL)")) Then Exit Function
        If (Not ps.AddOption("optSWSEL_0", 200, 250, 3700, 400, "No trigger request will be generated")) Then Exit Function
        If (Not ps.AddOption("optSWSEL_1", 200, 600, 3700, 400, "Transfer on correct hall event")) Then Exit Function
        If (Not ps.AddOption("optSWSEL_2", 200, 950, 3800, 400, "Transfer on T13 period match (while counting up)")) Then Exit Function
        If (Not ps.AddOption("optSWSEL_3", 200, 1300, 3900, 400, "Transfer on T12 one match (while counting down)")) Then Exit Function
        If (Not ps.AddOption("optSWSEL_4", 200, 1650, 3700, 400, "Transfer on T12 channel 1 compare match")) Then Exit Function
        If (Not ps.AddOption("optSWSEL_5", 200, 2000, 3700, 400, "Transfer on T12 period match")) Then Exit Function

    '-------------------------------
    ' frame: frmSWSYN
    '-------------------------------
    If (Not ps.AddFrame("frmSWSYN",4400,1150, 4150, 2500, "Switching Synchronization (SWSYN)")) Then Exit Function
        If (Not ps.AddOption("optSWSYN_0", 200, 300, 3900, 400, "Direct transfer")) Then Exit Function
        If (Not ps.AddOption("optSWSYN_1", 200, 800, 3900, 400, "Synchronization on T13 zero match")) Then Exit Function
        If (Not ps.AddOption("optSWSYN_2", 200, 1350, 3325, 400, "Synchronization on T12 period match (while counting up)")) Then Exit Function
        If (Not ps.AddOption("optSWSYN_3", 200, 1900, 3075, 400, "Synchronization on T12 one match (while counting down)")) Then Exit Function

    '-------------------------------
    ' frame: frmHall_IC
    '-------------------------------
    If (Not ps.AddFrame("frmHall_IC",100,3700, 4150, 1200, "Interrupt Control")) Then Exit Function
        If (Not ps.AddCheck("chkENCHE", 200, 250, 3900, 380, "Enable interrupt for correct hall event (ENCHE)")) Then Exit Function
        If (Not ps.AddCheck("chkENWHE", 200, 700, 3900, 380, "Enable interrupt for wrong hall event (ENWHE)")) Then Exit Function

    '-------------------------------
    ' frame: frmENIDLE
    '-------------------------------
    If (Not ps.AddFrame("frmENIDLE",4400,3700, 4150, 1200, "IDLE Control")) Then Exit Function
        If (Not ps.AddCheck("chkENIDLE", 200, 450, 3600, 400, "Enable the automatic entering of the idle state (ENIDLE)")) Then Exit Function

  End If
  OnChangingPageMultiChMode = 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 OnShowPageMultiChMode(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageMultiChModeError

  OnShowPageMultiChMode = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim sVarPre As String
  Dim sRegPre As String
  Dim vIndex As Variant
  Dim sDisabledTooltip As String
  Dim bDisabled As Boolean
  Dim s As String

  vIndex = ps.Parameters.v("x")

  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"
  

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

  If (Pagename = "Multi Ch.") Then
    '-------------------------------------------------------------------------
    ' page: MultiChMode (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: chkMCMEN (action)
        '---------------------------------------------------------------------
        Case "chkMCMEN"
            r.v(sRegPre & "MODCTR_MCMEN") = v(1)
            If (v(1) = 0) Then
                
                If (IsHallSensorModeEnable(r, vIndex)) Then
                    Call DisableHallSensorMode(r, vIndex)
                End If
                
                r.v(sRegPre & "MCMCTR_SWSEL") = 0
                r.v(sRegPre & "MCMCTR_SWSYN") = 0
                
                r.v(sRegPre & "IEN_ENIDLE") = 0
                r.v(sRegPre & "IEN_ENCHE") = 0
                r.v(sRegPre & "IEN_ENWHE") = 0
                
                r.v(sRegPre & "MCMPS_CC60") = 0
                r.v(sRegPre & "MCMPS_CC61") = 0
                r.v(sRegPre & "MCMPS_CC62") = 0
                r.v(sRegPre & "MCMPS_COUT60") = 0
                r.v(sRegPre & "MCMPS_COUT61") = 0
                r.v(sRegPre & "MCMPS_COUT62") = 0
                Call LoadMCMPSValue(r, vIndex)

            End If

        '---------------------------------------------------------------------
        ' control: chkEnHallMode (action)
        '---------------------------------------------------------------------
        Case "chkEnHallMode"
            If (v(1) = 1) Then
                If (r.sfr(sRegPre & "T12MSEL") = 0) Then
                    Call EnableHallSensorMode(r, vIndex)
                Else
                    s = "Channels 0, 1 and 2 will be switched to hall sensor mode. Do you really want to continue?"
                    If (Ask(s)) Then
                        Call EnableHallSensorMode(r, vIndex)
                    Else
                        Exit Function
                    End If
                End If
            Else
                s = "Channels 0, 1 and 2 will be disabled. Do you really want to continue?"
                If (Ask(s)) Then
                    Call DisableHallSensorMode(r, vIndex)
                Else
                    Exit Function
                End If
            End If

        '---------------------------------------------------------------------
        ' control: optSWSEL_0 (action)
        '---------------------------------------------------------------------
        Case "optSWSEL_0"
            r.v(sRegPre & "MCMCTR_SWSEL") = 0
            r.v(sRegPre & "IEN_ENIDLE") = 0
            r.v(sRegPre & "IEN_ENCHE") = 0
            r.v(sRegPre & "IEN_ENWHE") = 0

        '---------------------------------------------------------------------
        ' control: optSWSEL_1 (action)
        '---------------------------------------------------------------------
        Case "optSWSEL_1"
            r.v(sRegPre & "MCMCTR_SWSEL") = 1

        '---------------------------------------------------------------------
        ' control: optSWSEL_2 (action)
        '---------------------------------------------------------------------
        Case "optSWSEL_2"
            r.v(sRegPre & "MCMCTR_SWSEL") = 2
            r.v(sRegPre & "IEN_ENIDLE") = 0
            r.v(sRegPre & "IEN_ENCHE") = 0
            r.v(sRegPre & "IEN_ENWHE") = 0

        '---------------------------------------------------------------------
        ' control: optSWSEL_3 (action)
        '---------------------------------------------------------------------
        Case "optSWSEL_3"
            r.v(sRegPre & "MCMCTR_SWSEL") = 3
            r.v(sRegPre & "IEN_ENIDLE") = 0
            r.v(sRegPre & "IEN_ENCHE") = 0
            r.v(sRegPre & "IEN_ENWHE") = 0

        '---------------------------------------------------------------------
        ' control: optSWSEL_4 (action)
        '---------------------------------------------------------------------
        Case "optSWSEL_4"
            r.v(sRegPre & "MCMCTR_SWSEL") = 4
            r.v(sRegPre & "IEN_ENIDLE") = 0
            r.v(sRegPre & "IEN_ENCHE") = 0
            r.v(sRegPre & "IEN_ENWHE") = 0

        '---------------------------------------------------------------------
        ' control: optSWSEL_5 (action)
        '---------------------------------------------------------------------
        Case "optSWSEL_5"
            r.v(sRegPre & "MCMCTR_SWSEL") = 5
            r.v(sRegPre & "IEN_ENIDLE") = 0
            'ahe 06.08.2002
            'Anforderung von Infineon (s. Anhang in der mail von Timo vom 30.07.2002)
            'r.v(sRegPre & "IEN_ENCHE") = 0
            'r.v(sRegPre & "IEN_ENWHE") = 0

        '---------------------------------------------------------------------
        ' control: optSWSYN_0 (action)
        '---------------------------------------------------------------------
        Case "optSWSYN_0"
            r.v(sRegPre & "MCMCTR_SWSYN") = 0

        '---------------------------------------------------------------------
        ' control: optSWSYN_1 (action)
        '---------------------------------------------------------------------
        Case "optSWSYN_1"
            r.v(sRegPre & "MCMCTR_SWSYN") = 1

        '---------------------------------------------------------------------
        ' control: optSWSYN_2 (action)
        '---------------------------------------------------------------------
        Case "optSWSYN_2"
            r.v(sRegPre & "MCMCTR_SWSYN") = 2

        '---------------------------------------------------------------------
        ' control: optSWSYN_3 (action)
        '---------------------------------------------------------------------
        Case "optSWSYN_3"
            r.v(sRegPre & "MCMCTR_SWSYN") = 3

        '---------------------------------------------------------------------
        ' control: chkENIDLE (action)
        '---------------------------------------------------------------------
        Case "chkENIDLE"
            r.v(sRegPre & "IEN_ENIDLE") = v(1)

        '---------------------------------------------------------------------
        ' control: chkCHEEN (action)
        '---------------------------------------------------------------------
        Case "chkENCHE"
            r.v(sRegPre & "IEN_ENCHE") = v(1)

        '---------------------------------------------------------------------
        ' control: chkWHEEN (action)
        '---------------------------------------------------------------------
        Case "chkENWHE"
            r.v(sRegPre & "IEN_ENWHE") = v(1)

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: MultiChMode (show)
    '-------------------------------------------------------------------------
    bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                 r.v(sRegPre & "MODCTR_MCMEN") = 0)
    
    sDisabledTooltip = ""
    sDisabledTooltip = TOOLTIP_DISABLED_IF
    
    If (IsModuleClockDisabled(r, vIndex)) Then
        sDisabledTooltip = sDisabledTooltip & GetTooltipModuleClockDisabled(r, vIndex)
    End If
    If (r.v(sRegPre & "MODCTR_MCMEN") = 0) Then
        sDisabledTooltip = sDisabledTooltip & FormatDisabledTooltip("multi channel mode is not enabled")
    End If
    
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmSWSYN").Caption, c, e, bDisabled, sDisabledTooltip, "")


    '~~~~~ for frmENIDLE
    bDisabled = bDisabled Or _
                r.v(sRegPre & "MCMCTR_SWSEL") <> 1

    If (r.v(sRegPre & "MCMCTR_SWSEL") <> 1) Then
        sDisabledTooltip = sDisabledTooltip & FormatDisabledTooltip("transfer on correct hall event is not selected")
    End If

    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmENIDLE").Caption, c, e, bDisabled, sDisabledTooltip, "")

    ' for frmHall_IC
    'ahe 06.08.2002
    'Anforderung von Infineon (s. Anhang in der mail von Timo vom 30.07.2002)
    bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                 r.v(sRegPre & "MODCTR_MCMEN") = 0 OR _
                 (r.v(sRegPre & "MCMCTR_SWSEL") <> 1 AND r.v(sRegPre & "MCMCTR_SWSEL") < 5))
    
    sDisabledTooltip = ""
    sDisabledTooltip = TOOLTIP_DISABLED_IF
    
    If (IsModuleClockDisabled(r, vIndex)) Then
        sDisabledTooltip = sDisabledTooltip & GetTooltipModuleClockDisabled(r, vIndex)
    End If
    If (r.v(sRegPre & "MODCTR_MCMEN") = 0) Then
        sDisabledTooltip = sDisabledTooltip & FormatDisabledTooltip("multi channel mode is not enabled")
    End If
    If (r.v(sRegPre & "MCMCTR_SWSEL") <> 1 AND r.v(sRegPre & "MCMCTR_SWSEL") < 5) Then
        sDisabledTooltip = sDisabledTooltip & FormatDisabledTooltip("transfer on correct hall event or transfer on T12 period match is not selected")
    End If

    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmHall_IC").Caption, c, e, bDisabled, sDisabledTooltip, "")

    '-------------------------------------------------------------------------
    ' control: chkMCMEN (show)
    '-------------------------------------------------------------------------
    With c("chkMCMEN")
        bDisabled = (IsModuleClockDisabled(r, vIndex))
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "MODCTR_MCMEN") = 1)
    End With

    With e("chkMCMEN")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  GetTooltipModuleClockDisabled(r, vIndex)
            End If
        Else
            'enabled tooltip
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkEnHallMode (show)
    '-------------------------------------------------------------------------
    With c("chkEnHallMode")
        bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                    r.v(sRegPre & "MODCTR_MCMEN") = 0 Or _
                    Not(GetPinFunction(r, sVarPre & "_CC6POS0_I") = 1) Or _
                    Not(GetPinFunction(r, sVarPre & "_CC6POS1_I") = 1) Or _
                    Not(GetPinFunction(r, sVarPre & "_CC6POS2_I") = 1) )

        .Enabled = Not(bDisabled)
        .Value = -CInt(r.sfr(sRegPre & "T12MSEL") = 2184)
    End With

    With e("chkEnHallMode")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  GetTooltipModuleClockDisabled(r, vIndex)
            End If
            If (r.v(sRegPre & "MODCTR_MCMEN") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledTooltip("multi channel mode is not enabled")
            End If
            If (Not(GetPinFunction(r, sVarPre & "_CC6POS0_I") = 1)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledTooltip("pin CC6POS0 is not used as input")
            End If
            If (Not(GetPinFunction(r, sVarPre & "_CC6POS1_I") = 1)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledTooltip("pin CC6POS1 is not used as input")
            End If
            If (Not(GetPinFunction(r, sVarPre & "_CC6POS2_I") = 1)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledTooltip("pin CC6POS2 is not used as input")
            End If
        Else
            'enabled tooltip
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSWSEL_0 (show)
    '-------------------------------------------------------------------------
    With c("optSWSEL_0")
        bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                    r.v(sRegPre & "MODCTR_MCMEN") = 0)
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "MCMCTR_SWSEL") = 0)
    End With

    With e("optSWSEL_0")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  GetTooltipModuleClockDisabled(r, vIndex)
            End If
            If (r.v(sRegPre & "MODCTR_MCMEN") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledTooltip("multi channel mode is not enabled")
            End If
        Else
            'enabled tooltip
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSWSEL_2 (show)
    '-------------------------------------------------------------------------
    With c("optSWSEL_2")
        'bDisabled s. optSWSEL_0
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "MCMCTR_SWSEL") = 2)
    End With

    With e("optSWSEL_2")
        If (bDisabled) Then
            .DisabledTooltipText = e("optSWSEL_0").DisabledTooltipText
        Else
            'enabled tooltip
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSWSEL_3 (show)
    '-------------------------------------------------------------------------
    With c("optSWSEL_3")
        'bDisabled s. optSWSEL_0
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "MCMCTR_SWSEL") = 3)
    End With

    With e("optSWSEL_3")
        If (bDisabled) Then
            .DisabledTooltipText = e("optSWSEL_0").DisabledTooltipText
        Else
            'enabled tooltip
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSWSEL_4 (show)
    '-------------------------------------------------------------------------
    With c("optSWSEL_4")
        'bDisabled s. optSWSEL_0
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "MCMCTR_SWSEL") = 4)
    End With

    With e("optSWSEL_4")
        If (bDisabled) Then
            .DisabledTooltipText = e("optSWSEL_0").DisabledTooltipText
        Else
            'enabled tooltip
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSWSEL_5 (show)
    '-------------------------------------------------------------------------
    With c("optSWSEL_5")
        'bDisabled s. optSWSEL_0
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "MCMCTR_SWSEL") = 5)
    End With

    With e("optSWSEL_5")
        If (bDisabled) Then
            .DisabledTooltipText = e("optSWSEL_0").DisabledTooltipText
        Else
            'enabled tooltip
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSWSEL_1 (show)
    '-------------------------------------------------------------------------
    With c("optSWSEL_1")
        bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                    r.v(sRegPre & "MODCTR_MCMEN") = 0 Or _
                    Not(GetPinFunction(r, sVarPre & "_CC6POS0_I") = 1) Or _
                    Not(GetPinFunction(r, sVarPre & "_CC6POS1_I") = 1) Or _
                    Not(GetPinFunction(r, sVarPre & "_CC6POS2_I") = 1) )
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "MCMCTR_SWSEL") = 1)
    End With

    With e("optSWSEL_1")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  GetTooltipModuleClockDisabled(r, vIndex)
            End If
            If (r.v(sRegPre & "MODCTR_MCMEN") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledTooltip("multi channel mode is not enabled")
            End If
            If (Not(GetPinFunction(r, sVarPre & "_CC6POS0_I") = 1)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledTooltip("pin CC6POS0 is not used as input")
            End If
            If (Not(GetPinFunction(r, sVarPre & "_CC6POS1_I") = 1)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledTooltip("pin CC6POS1 is not used as input")
            End If
            If (Not(GetPinFunction(r, sVarPre & "_CC6POS2_I") = 1)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledTooltip("pin CC6POS2 is not used as input")
            End If
        Else
            'enabled tooltip
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSWSYN_0 (show)
    '-------------------------------------------------------------------------
    With c("optSWSYN_0")
        .Value = -CInt(r.v(sRegPre & "MCMCTR_SWSYN") = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: optSWSYN_1 (show)
    '-------------------------------------------------------------------------
    With c("optSWSYN_1")
        .Value = -CInt(r.v(sRegPre & "MCMCTR_SWSYN") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: optSWSYN_2 (show)
    '-------------------------------------------------------------------------
    With c("optSWSYN_2")
        .Value = -CInt(r.v(sRegPre & "MCMCTR_SWSYN") = 2)
    End With

    '-------------------------------------------------------------------------
    ' control: optSWSYN_3 (show)
    '-------------------------------------------------------------------------
    With c("optSWSYN_3")
        .Visible = False
        .Value = -CInt(r.v(sRegPre & "MCMCTR_SWSYN") = 3)
    End With

    '-------------------------------------------------------------------------
    ' control: chkENIDLE (show)
    '-------------------------------------------------------------------------
    With c("chkENIDLE")
        .Value = -CInt(r.v(sRegPre & "IEN_ENIDLE") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkCHEEN (show)
    '-------------------------------------------------------------------------
    With c("chkENCHE")
        .Value = -CInt(r.v(sRegPre & "IEN_ENCHE") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkWHEEN (show)
    '-------------------------------------------------------------------------
    With c("chkENWHE")
        .Value = -CInt(r.v(sRegPre & "IEN_ENWHE") = 1)
    End With

  End If

  OnShowPageMultiChMode = True
  Exit Function

OnShowPageMultiChModeError:
  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 'Channels'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageChannels(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageChannels = False

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

  OnLoadPageChannels = 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 OnChangingPageChannels(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageChannels = False
  Dim vIndex As Variant
  Dim i As Integer
  Dim iChannel As Integer
  Dim iCh_low As Integer
  Dim iCh_high As Integer

  vIndex = ps.Parameters.v("x")

  iCh_low = 0
  iCh_high = 3
  
  If (Not ps.ExtenderCollection("Channels").Loaded) And (Pagename = "Channels") Then
    ps.ExtenderCollection("Channels").Loaded = True
  

    '-------------------------------
    ' frame: frmChannels
    '-------------------------------
    If (Not ps.AddFrame("frmChannels",100,100, 8475, 3100, "Channels")) Then Exit Function
        If (Not ps.AddButton("btnCh_0", 1700, 400, 5000, 380, "Configure Channel 0")) Then Exit Function
        If (Not ps.AddButton("btnCh_1", 1700, 1100, 5000, 380, "Configure Channel 1")) Then Exit Function
        If (Not ps.AddButton("btnCh_2", 1700, 1800, 5000, 375, "Configure Channel 2")) Then Exit Function
        If (Not ps.AddButton("btnCh_3", 1700, 2500, 5000, 380, "Configure Channel 3")) Then Exit Function
        'If (Not ps.AddCheck("chk_CH_0", 2500, 400, 1900, 375, "Channel 0 is enabled")) Then Exit Function
        'If (Not ps.AddCheck("chk_CH_1", 2500, 1100, 1900, 380, "Channel 1 is enabled")) Then Exit Function
        'If (Not ps.AddCheck("chk_CH_2", 2500, 1800, 1900, 380, "Channel 2 is enabled")) Then Exit Function
        'If (Not ps.AddCheck("chk_CH_3", 2500, 2500, 1900, 380, "Channel 3 is enabled")) Then Exit Function

  End If
  OnChangingPageChannels = 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 OnShowPageChannels(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageChannelsError

  OnShowPageChannels = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim vIndex As Variant
  Dim i As Integer
  Dim iChannel As Integer
  Dim iCh_low As Integer
  Dim iCh_high As Integer
  Dim bDisabled As Boolean
  Dim sVarPre As String

  vIndex = ps.Parameters.v("x")

  iCh_low = 0
  iCh_high = 3

  sVarPre = "CCU" & vIndex

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

  If (Pagename = "Channels") Then
    '-------------------------------------------------------------------------
    ' page: Channels (action)
    '-------------------------------------------------------------------------
    For iChannel = iCh_low To iCh_high
        Select Case (Controlname)
            '---------------------------------------------------------------------
            ' control: btnCh_x (action)
            '---------------------------------------------------------------------
            Case "btnCh_" & iChannel

            ''---------------------------------------------------------------------
            '' control: chkCh_x (action)
            ''---------------------------------------------------------------------
            'Case "chk_CH_" & iChannel


          Case Else
        End Select

    Next iChannel

    '-------------------------------------------------------------------------
    ' page: Channels (show)
    '-------------------------------------------------------------------------

    For iChannel = iCh_low To iCh_high
        '-------------------------------------------------------------------------
        ' control: btnCh_x (show)
        '-------------------------------------------------------------------------
        With c("btnCh_" & iChannel)
            bDisabled = False
            .Enabled = Not(bDisabled)
        End With

        With e("btnCh_" & iChannel)
            If(bDisabled) Then
                .DisabledTooltipText = TOOLTIP_DISABLED_IF
                If (IsModuleClockDisabled(r, vIndex)) Then
                    .DisabledTooltipText = .DisabledTooltipText & _
                      GetTooltipModuleClockDisabled(r, vIndex)
                End If
            End If
        End With
    
    Next iChannel


  End If

  OnShowPageChannels = True
  Exit Function

OnShowPageChannelsError:
  Exit Function
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnClick function of the associated
'        module if a button on the page 'Control' will be clicked.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnButtonClickOnPageChannels(ps As Object, Controlname As String) As Boolean
  On Error GoTo OnButtonClickOnPageChannelsError

  OnButtonClickOnPageChannels = False
  Dim vIndex As Variant
  Dim iChannel As Integer

  vIndex = ps.Parameters.v("x")
  

  For iChannel = 0 To 2
    If (Controlname = "btnCh_" & iChannel) Then
      '---------------------------------------------------------------------
      ' control: btnCh_i (action)
      '---------------------------------------------------------------------
      Set CHANNELx = New Peripherals
      CHANNELx.Parameters.Add ("x")
      CHANNELx.Parameters.v("x") = vIndex
      CHANNELx.Parameters.Add ("Channel")
      CHANNELx.Parameters.v("Channel") = iChannel
      Set CHANNELx.ProjectData = ps.ProjectData
      CHANNELx.Caption = "Configure CCU" & vIndex & " Channel " & iChannel
      CHANNELx.Scriptfile = DefGetPath("Scripts") & "CC6\CC6_CHANNEL_012.DAVE"
      CHANNELx.Show
    End If
  Next iChannel

  iChannel = 3
  If (Controlname = "btnCh_" & iChannel) Then
    '---------------------------------------------------------------------
    ' control: btnCh_i (action)
    '---------------------------------------------------------------------
    Set CHANNELx = New Peripherals
    CHANNELx.Parameters.Add ("x")
    CHANNELx.Parameters.v("x") = vIndex
    CHANNELx.Parameters.Add ("Channel")
    CHANNELx.Parameters.v("Channel") = iChannel
    Set CHANNELx.ProjectData = ps.ProjectData
    CHANNELx.Caption = "Configure CCU" & vIndex & " Channel " & iChannel
    CHANNELx.Scriptfile = DefGetPath("Scripts") & "CC6\CC6_CHANNEL_3.DAVE"
    CHANNELx.Show
  End If


  OnButtonClickOnPageChannels = True
  Exit Function

OnButtonClickOnPageChannelsError:
  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 'TrapControl'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageTrapControl(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageTrapControl = False

  If (Not ps.AddPage("Trap/INT")) Then Exit Function

  OnLoadPageTrapControl = 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 OnChangingPageTrapControl(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageTrapControl = False
  
  Dim vIndex As Variant
  Dim sVarPre As String

  vIndex = ps.Parameters.v("x")
  sVarPre = "CCU" & vIndex

  If (Not ps.ExtenderCollection("Trap/INT").Loaded) And (Pagename = "Trap/INT") Then
    ps.ExtenderCollection("Trap/INT").Loaded = True
  

    '-------------------------------
    ' frame: frmCTRAP
    '-------------------------------
    If (Not ps.AddFrame("frmCTRAP",100,100, 3325, 1200, _
      "Control of pin #CTRAP (" & GetPinName(sVarPre & "_CTRAP_I") & ")")) Then Exit Function
        If (Not ps.AddCheck("chkCTRAP", 200, 450, 2875, 380, "Use pin #CTRAP as input")) Then Exit Function

    '-------------------------------
    ' frame: frmTRPPEN
    '-------------------------------
    If (Not ps.AddFrame("frmTRPPEN",3575,100, 5000, 1200, "Trap Pin Control (TRPPEN)")) Then Exit Function
        If (Not ps.AddOption("optTRPPEN_0", 200, 250, 4675, 380, "A trap can only be generated by SW by setting bit TRPF")) Then Exit Function
        If (Not ps.AddOption("optTRPPEN_1", 200, 700, 4725, 380, "A trap can be generated by SW or by #CTRAP = '0'")) Then Exit Function

    '-------------------------------
    ' frame: frmTRPM01
    '-------------------------------
    If (Not ps.AddFrame("frmTRPM01",100,1350, 8475, 1500, "Trap Mode Control (TRPM0/TRPM1)")) Then Exit Function
        If (Not ps.AddOption("optTRPM01_0", 200, 250, 8050, 380, "The trap state is left when a zero-match of T12 (while counting up) is detected (synchronization to T12)")) Then Exit Function
        If (Not ps.AddOption("optTRPM01_1", 200, 650, 8050, 380, "The trap state is left when a zero-match of T13 is detected (synchronization to T13)")) Then Exit Function
        If (Not ps.AddOption("optTRPM01_3", 200, 1050, 8050, 380, "The trap state is left immediately without any synchronization to T12 or T13")) Then Exit Function

    '-------------------------------
    ' frame: frmTRPM2
    '-------------------------------
    If (Not ps.AddFrame("frmTRPM2",100,2900, 8475, 1200, "Trap Mode Control (TRPM2)")) Then Exit Function
        If (Not ps.AddOption("optTRPM2_0", 200, 250, 8050, 400, "Bit TRPF is automatically cleared by HW (according to TRPPEN, TRPM0 and TRPM1)")) Then Exit Function
        If (Not ps.AddOption("optTRPM2_1", 200, 650, 8050, 400, "The trap state can be left as soon as bit TRPF is reset by SW (according to TRPPEN, TRPM0 and TRPM1)")) Then Exit Function

    '-------------------------------
    ' frame: frmENTRPF
    '-------------------------------
    If (Not ps.AddFrame("frmENTRPF",100,4150, 3325, 1000, "Trap Interrupt Control")) Then Exit Function
        If (Not ps.AddCheck("chkENTRPF", 200, 350, 2875, 380, "Enable trap interrupt (ENTRPF)")) Then Exit Function

    '-------------------------------
    ' frame: frmINT
    '-------------------------------
    If (Not ps.AddFrame("frmINT",3575,4150, 5000, 1000, "Inerrupt Control and Inerrupt Node Pointer Configuration")) Then Exit Function
        If (Not ps.AddButton("btnINT", 1000, 350, 3000, 400, "Interrupt Configuration")) Then Exit Function

  End If
  OnChangingPageTrapControl = 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 OnShowPageTrapControl(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageTrapControlError

  OnShowPageTrapControl = False

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

  vIndex = ps.Parameters.v("x")

  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"

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

  If (Pagename = "Trap/INT") Then
    '-------------------------------------------------------------------------
    ' page: TrapControl (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: chkCTRAP (action)
        '---------------------------------------------------------------------
        Case "chkCTRAP"
            If (v(1) = 0) Then
                Call ReleaseAlternateInputPin(r, sVarPre & "_CTRAP_I")
                r.v(sRegPre & "TRPCTR_TRPPEN") = 0
            Else
                Call RequestAlternateInputPin(r, sVarPre & "_CTRAP_I")
            End If

        '---------------------------------------------------------------------
        ' control: optTRPPEN_0 (action)
        '---------------------------------------------------------------------
        Case "optTRPPEN_0"
            r.v(sRegPre & "TRPCTR_TRPPEN") = 0

        '---------------------------------------------------------------------
        ' control: optTRPPEN_1 (action)
        '---------------------------------------------------------------------
        Case "optTRPPEN_1"
            r.v(sRegPre & "TRPCTR_TRPPEN") = 1

        '---------------------------------------------------------------------
        ' control: optTRPM01_0 (action)
        '---------------------------------------------------------------------
        Case "optTRPM01_0"
            r.v(sRegPre & "TRPCTR_TRPM0") = 0
            r.v(sRegPre & "TRPCTR_TRPM1") = 0

        '---------------------------------------------------------------------
        ' control: optTRPM01_1 (action)
        '---------------------------------------------------------------------
        Case "optTRPM01_1"
            r.v(sRegPre & "TRPCTR_TRPM0") = 1
            r.v(sRegPre & "TRPCTR_TRPM1") = 0

        '---------------------------------------------------------------------
        ' control: optTRPM01_3 (action)
        '---------------------------------------------------------------------
        Case "optTRPM01_3"
            r.v(sRegPre & "TRPCTR_TRPM0") = 1
            r.v(sRegPre & "TRPCTR_TRPM1") = 1

        '---------------------------------------------------------------------
        ' control: optTRPM2_0 (action)
        '---------------------------------------------------------------------
        Case "optTRPM2_0"
            r.v(sRegPre & "TRPCTR_TRPM2") = 0

        '---------------------------------------------------------------------
        ' control: optTRPM2_1 (action)
        '---------------------------------------------------------------------
        Case "optTRPM2_1"
            r.v(sRegPre & "TRPCTR_TRPM2") = 1

        '---------------------------------------------------------------------
        ' control: chkENTRPF (action)
        '---------------------------------------------------------------------
        Case "chkENTRPF"
            r.v(sRegPre & "IEN_ENTRPF") = v(1)


      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: TrapControl (show)
    '-------------------------------------------------------------------------
    bDisabled = (IsModuleClockDisabled(r, vIndex))
    
    sDisabledTooltip = ""
    sDisabledTooltip = TOOLTIP_DISABLED_IF
    
    If (IsModuleClockDisabled(r, vIndex)) Then
        sDisabledTooltip = sDisabledTooltip & GetTooltipModuleClockDisabled(r, vIndex)
    End If

    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmTRPM01").Caption, c, e, bDisabled, sDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmTRPM2").Caption, c, e, bDisabled, sDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmENTRPF").Caption, c, e, bDisabled, sDisabledTooltip, "")

    '-------------------------------------------------------------------------
    ' control: chkCTRAP (show)
    '-------------------------------------------------------------------------
    With c("chkCTRAP")
        bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                     IsAlternateInputPinFree(r, sVarPre & "_CTRAP_I") = False)
        .Enabled = Not(bDisabled)
        .Value = -CInt(GetPinFunction(r, sVarPre & "_CTRAP_I") = 1)
    End With

    With e("chkCTRAP")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  GetTooltipModuleClockDisabled(r, vIndex)
            End If
            If (IsAlternateInputPinFree(r, sVarPre & "_CTRAP_I") = False) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  GetDisabledAlternatePinTooltip(r, sVarPre & "_CTRAP_I")
            End If
        Else
            'enabled tooltip
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optTRPPEN_0 (show)
    '-------------------------------------------------------------------------
    With c("optTRPPEN_0")
        bDisabled = (IsModuleClockDisabled(r, vIndex))
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "TRPCTR_TRPPEN") = 0)
    End With

    With e("optTRPPEN_0")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  GetTooltipModuleClockDisabled(r, vIndex)
            End If
        Else
            'enabled tooltip
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optTRPPEN_1 (show)
    '-------------------------------------------------------------------------
    With c("optTRPPEN_1")
        bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                     Not(GetPinFunction(r, sVarPre & "_CTRAP_I") = 1) Or _
                     IsAlternateInputPinFree(r, sVarPre & "_CTRAP_I") = False)
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "TRPCTR_TRPPEN") = 1)
    End With

    With e("optTRPPEN_1")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  GetTooltipModuleClockDisabled(r, vIndex)
            End If
            If (IsAlternateInputPinFree(r, sVarPre & "_CTRAP_I") = False) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  GetDisabledAlternatePinTooltip(r, sVarPre & "_CTRAP_I")
            End If
            If (Not(GetPinFunction(r, sVarPre & "_CTRAP_I") = 1)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledTooltip("pin #CTRAP is not used as input")
            End If
        Else
            'enabled tooltip
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optTRPM01_0 (show)
    '-------------------------------------------------------------------------
    With c("optTRPM01_0")
        .Value = -CInt(r.v(sRegPre & "TRPCTR_TRPM0") = 0 And r.v(sRegPre & "TRPCTR_TRPM1") = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: optTRPM01_1 (show)
    '-------------------------------------------------------------------------
    With c("optTRPM01_1")
        .Value = -CInt(r.v(sRegPre & "TRPCTR_TRPM0") = 1 And r.v(sRegPre & "TRPCTR_TRPM1") = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: optTRPM01_3 (show)
    '-------------------------------------------------------------------------
    With c("optTRPM01_3")
        .Value = -CInt(r.v(sRegPre & "TRPCTR_TRPM0") = 1 And r.v(sRegPre & "TRPCTR_TRPM1") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: optTRPM2_0 (show)
    '-------------------------------------------------------------------------
    With c("optTRPM2_0")
        .Value = -CInt(r.v(sRegPre & "TRPCTR_TRPM2") = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: optTRPM2_1 (show)
    '-------------------------------------------------------------------------
    With c("optTRPM2_1")
        .Value = -CInt(r.v(sRegPre & "TRPCTR_TRPM2") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: optTRPM2_1 (show)
    '-------------------------------------------------------------------------
    With c("chkENTRPF")
        .Value = -CInt(r.v(sRegPre & "IEN_ENTRPF") = 1)
    End With

  End If

  OnShowPageTrapControl = True
  Exit Function

OnShowPageTrapControlError:
  Errorbox "Can not show page", Err.Description
  Exit Function
End Function
'*****************************************************************************
'Description:
'        This function is called from the OnClick function of the associated
'        module if a button on the page 'TrapControl' will be clicked.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnButtonClickOnPageTrapControl(ps As Object, Controlname As String) As Boolean
  On Error GoTo OnButtonClickOnPageTrapControlError

  OnButtonClickOnPageTrapControl = False
  Dim vIndex As Variant
  Dim iChannel As Integer

  vIndex = ps.Parameters.v("x")
  

  If (Controlname = "btnINT") Then
    '---------------------------------------------------------------------
    ' control: btnCh_i (action)
    '---------------------------------------------------------------------
    Set CHANNELx = New Peripherals
    CHANNELx.Parameters.Add ("x")
    CHANNELx.Parameters.v("x") = vIndex
    Set CHANNELx.ProjectData = ps.ProjectData
    CHANNELx.Caption = "Configure CCU" & vIndex & " Channel " & iChannel
    CHANNELx.Scriptfile = DefGetPath("Scripts") & "CC6\CC6_INERRUPT_NODE.DAVE"
    CHANNELx.Show
  End If


  OnButtonClickOnPageTrapControl = True
  Exit Function

OnButtonClickOnPageTrapControlError:
  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 iCh As Integer
  Dim vIndex as Variant
  Dim iCh_low As Integer
  Dim iCh_high As Integer
  Dim iTmr_12 As Integer
  Dim iTmr_13 As Integer
  Dim aFunctions(1 To 16) As String

  vIndex = ps.Parameters.v("x")
  iCh_low = 0
  iCh_high = 3
  iTmr_12 = 12
  iTmr_13 = 12

  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) = "ResetTmr"
    i = i + 1
    aFunctions(i) = "SetTmrPeriod"
    i = i + 1
    aFunctions(i) = "GetTmrCounter"
    i = i + 1
    aFunctions(i) = "SetTmrCounter"
    i = i + 1
    aFunctions(i) = "SetDeadTimePeriod"
    i = i + 1
    aFunctions(i) = "EnableShadowTransfer"
    i = i + 1
    aFunctions(i) = "LoadChannelShadowRegister"
    i = i + 1
    aFunctions(i) = "GetChannelShadowRegister"
    i = i + 1
    aFunctions(i) = "GetChannelRegister"
    i = i + 1
    aFunctions(i) = "SetStatusBit"
    i = i + 1
    aFunctions(i) = "ResetStatusBit"
    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)

    For iCh = 0 To 3
        aFunctions(i) = "NodeI" & iCh
        i = i + 1
    Next iCh

    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

  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 d As String
  Dim sVarPre As String
  Dim sRegPre As String
  Dim sName As String
  Dim vIndex As Variant
  Dim sFctName As String
  Dim iCh_low As Integer
  Dim iCh_high As Integer
  Dim iTmr_12 As Integer
  Dim iTmr_13 As Integer
  Dim i As Integer

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

  iCh_low = 0
  iCh_high = 3
  iTmr_12 = 12
  iTmr_13 = 12

  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) = (IsModuleClockDisabled(r, vIndex))
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (IsModuleClockDisabled(r, vIndex)) Then
      d = d & GetTooltipModuleClockDisabled(r, vIndex)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "StartTmr"
    sName = sVarPre & "_NAME_" & sFctName
    ' 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

    sFctName = "StopTmr"
    sName = sVarPre & "_NAME_" & sFctName
    ' 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

    sFctName = "ResetTmr"
    sName = sVarPre & "_NAME_" & sFctName
    ' 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

    sFctName = "SetTmrPeriod"
    sName = sVarPre & "_NAME_" & sFctName
    ' 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

    sFctName = "GetTmrCounter"
    sName = sVarPre & "_NAME_" & sFctName
    ' 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

    sFctName = "SetTmrCounter"
    sName = sVarPre & "_NAME_" & sFctName
    ' 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

    sFctName = "SetDeadTimePeriod"
    sName = sVarPre & "_NAME_" & sFctName
    ' 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

    sFctName = "EnableShadowTransfer"
    sName = sVarPre & "_NAME_" & sFctName
    ' 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

    sFctName = "LoadChannelShadowRegister"
    sName = sVarPre & "_NAME_" & sFctName
    ' 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

    sFctName = "GetChannelShadowRegister"
    sName = sVarPre & "_NAME_" & sFctName
    ' 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

    sFctName = "GetChannelRegister"
    sName = sVarPre & "_NAME_" & sFctName
    ' 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

    sFctName = "SetStatusBit"
    sName = sVarPre & "_NAME_" & sFctName
    ' 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

    sFctName = "ResetStatusBit"
    sName = sVarPre & "_NAME_" & sFctName
    ' 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

    sFctName = "NodeI0"
    sName = sVarPre & "_NAME_" & sFctName
    ' 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, sRegPre & "IC", sFctName)

    sFctName = "NodeI1"
    sName = sVarPre & "_NAME_" & sFctName
    ' 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, sRegPre & "EIC", sFctName)

    sFctName = "NodeI2"
    sName = sVarPre & "_NAME_" & sFctName
    ' 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, sRegPre & "T12IC", sFctName)

    sFctName = "NodeI3"
    sName = sVarPre & "_NAME_" & sFctName
    ' 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, sRegPre & "T13IC", sFctName)

    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
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection

  Dim bDisabled As Boolean
  Dim sVarPre As String
  Dim vIndex as Variant
  Dim sParaName As String
  Dim i As Integer
  Dim iCh As Integer
  Dim iCh_low As Integer
  Dim iCh_high As Integer
  Dim iTmr_12 As Integer
  Dim iTmr_13 As Integer
  Dim aParameters(1 To 16) As String

  vIndex = ps.Parameters.v("x")
  sVarPre = "CCU" & vIndex
  
  iCh_low = 0
  iCh_high = 3
  iTmr_12 = 12
  iTmr_13 = 13


  OnChangingPageParameters = False

  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_" & iTmr_12
    i = i + 1
    aParameters(i) = "TIMER_" & iTmr_13
    i = i + 1

    For iCh = iCh_low To iCh_high
        aParameters(i) = "CHANNEL_" & iCh
        i = i + 1
    Next iCh


    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 = "CCU" & 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





