Attribute VB_Name = "Module1"
'#Uses "..\classes\CC6FunctionClass.cls"
'#Uses "..\classes\CC6ParameterClass.cls"
'#Uses "..\include\Const.inc"
'#Uses "..\include\CC6Format.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Pages.inc"
'#Uses "..\include\Port.inc"
'#Uses "Include.inc"
'#Uses "8BitAdapter.inc"

Option Explicit

'*****************************************************************************
' Module:
'        CC6
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'CC6'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        0.1  sheshadri     10.11.04     initial version for XC866
'        0.2  sheshadri     05.01.05     changes made in Pinselection 1
'                                         PAGE switching numbers are assigend properly
'        0.3  sheshadri     21.11.05     changes made wrt B-Step
'
'
'*****************************************************************************
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: OnLoadPagePinControl1
    '-------------------------------------------------------------------------
    If (Not OnLoadPagePinControl1(ps)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: OnLoadPagePinControl2
    '-------------------------------------------------------------------------
    If (Not OnLoadPagePinControl2(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(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: OnChangingPagePinControl1
    '-------------------------------------------------------------------------
    If (Not OnChangingPagePinControl1(ps, Pagename)) Then Exit Function
    
    '-------------------------------------------------------------------------
    'page: OnChangingPagePinControl2
    '-------------------------------------------------------------------------
    If (Not OnChangingPagePinControl2(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(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: OnShowPagePinControl1
    '-------------------------------------------------------------------------
    If (Not OnShowPagePinControl1(ps, Controlname, Pagename, v)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: OnShowPagePinControl2
    '-------------------------------------------------------------------------
    If (Not OnShowPagePinControl2(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(ps, Controlname, Pagename, v)) 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: 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
      
      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, " CCU6 Disabled Flag (PMCON1) ")) Then Exit Function
            If (Not ps.AddOption("optCCU_DIS_0", 200, 350, 4800, 300, "Enable module; the peripheral is supplied with the clock signal")) Then Exit Function
            If (Not ps.AddOption("optCCU_DIS_1", 200, 825, 4400, 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 module [MHz]")) Then Exit Function
            If (Not ps.AddLabel("lbl_box_InputClock", 1, 3550, 400, 1000, 300, "")) Then Exit Function

      End If
'  End If
  OnChangingPageModuleClock = True
End Function

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

  OnShowPageModuleClock = False
  
  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean
  Dim vIndex As Variant
  Dim sIndex As String
  Dim sPrefix As String
  Dim i As Integer

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

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
    
If (Pagename = "Module Clock") Then
  
      Select Case (Controlname)
      
         Case "optCCU_DIS_0"
            r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 0
            
         Case "optCCU_DIS_1"
            r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1
            r.v("CCU6_USE_Init") = 0
            Call DisableCC6Module(r, vIndex)
            Call CheckResetCCU6_Pins(r)
      End Select
      

        With c("optCCU_DIS_0")
             bDisabled = False
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 0)
        End With

       With c("optCCU_DIS_1")
          bDisabled = False
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1)
        End With
       
        With c("lbl_box_InputClock")
          bDisabled = (r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1)
          .Enabled = Not (bDisabled)
            If (r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Then
               .Caption = CALCULATION_NOT_POSSIBLE
             Else
               .Caption = Format(GetPeriClock(r), "00.000")
            End If
        End With
            
        With c("lbl_txt_InputClock")
          bDisabled = (r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1)
          .Enabled = Not (bDisabled)
        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 OnLoadPagePinControl1(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPagePinControl1 = False

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

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

  OnChangingPagePinControl1 = False
  
  Dim vIndex As Variant
  Dim sVarPre As String

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

  If (Not ps.ExtenderCollection("Pin Control 1").Loaded) And (Pagename = "Pin Control 1") Then
    ps.ExtenderCollection("Pin Control 1").Loaded = True
  
    '-------------------------------
    ' frame: frmCCPOS0
    '-------------------------------
    If (Not ps.AddFrame("frmCCPOS0", 0, 100, 2880, 1800, "Control of Pin CCPOS0")) Then Exit Function
        If (Not ps.AddOption("optCCPOS0_0", 120, 240, 2100, 380, "Pin CCPOS0 is not used")) Then Exit Function
        If (Not ps.AddOption("optCCPOS0_1", 120, 600, 2640, 380, "Use pin CCPOS0(P2.0) as input")) Then Exit Function
        If (Not ps.AddOption("optCCPOS0_2", 120, 960, 2640, 380, "Use pin CCPOS0(P1.5) as input")) Then Exit Function
        If (Not ps.AddOption("optCCPOS0_3", 120, 1320, 2640, 380, "Use pin CCPOS0(P3.1) as input")) Then Exit Function

    '-------------------------------
    ' frame: frmCCPOS1
    '-------------------------------
    If (Not ps.AddFrame("frmCCPOS1", 2880, 100, 2880, 1800, "Control of Pin CCPOS1")) Then Exit Function
        If (Not ps.AddOption("optCCPOS1_0", 120, 240, 2100, 380, "Pin CCPOS1 is not used")) Then Exit Function
        If (Not ps.AddOption("optCCPOS1_1", 120, 600, 2640, 380, "Use pin CCPOS1(P2.1) as input")) Then Exit Function
        If (Not ps.AddOption("optCCPOS1_2", 120, 960, 2640, 380, "Use pin CCPOS1(P1.6) as input")) Then Exit Function
        If (Not ps.AddOption("optCCPOS1_3", 120, 1320, 2640, 380, "Use pin CCPOS1(P3.0) as input")) Then Exit Function

    '-------------------------------
    ' frame: frmCCPOS2
    '-------------------------------
    If (Not ps.AddFrame("frmCCPOS2", 5760, 100, 2880, 1800, "Control of Pin CCPOS2")) Then Exit Function
        If (Not ps.AddOption("optCCPOS2_0", 120, 240, 2100, 380, "Pin CCPOS2 is not used")) Then Exit Function
        If (Not ps.AddOption("optCCPOS2_1", 120, 600, 2640, 380, "Use pin CCPOS2(P2.2) as input")) Then Exit Function
        If (Not ps.AddOption("optCCPOS2_2", 120, 960, 2640, 380, "Use pin CCPOS2(P1.7) as input")) Then Exit Function
        If (Not ps.AddOption("optCCPOS2_3", 120, 1320, 2640, 380, "Use pin CCPOS2(P3.2) as input")) Then Exit Function

    '-------------------------------
    ' frame: frmCCTRAP
    '-------------------------------
    If (Not ps.AddFrame("frmCCTRAP", 0, 2000, 2880, 2000, "Control of Pin /CTRAP")) Then Exit Function
        If (Not ps.AddOption("optCTRAP_0", 120, 240, 2000, 380, "Pin CTRAP is not used")) Then Exit Function
        If (Not ps.AddOption("optCTRAP_1", 120, 600, 2520, 380, "Use pin /CTRAP(P3.6) as input")) Then Exit Function
        If (Not ps.AddOption("optCTRAP_2", 120, 960, 2520, 380, "Use pin /CTRAP(P2.2) as input")) Then Exit Function
        If (Not ps.AddOption("optCTRAP_3", 120, 1320, 2520, 380, "Use pin /CTRAP(P0.2) as input")) Then Exit Function

    '-------------------------------
    ' frame: frmT12HR
    '-------------------------------
    If (Not ps.AddFrame("frmT12HR", 2880, 2000, 2880, 2000, "Control of Pin T12HR")) Then Exit Function
        If (Not ps.AddOption("optT12HR_0", 120, 240, 2000, 380, "Pin T12HR is not used")) Then Exit Function
        If (Not ps.AddOption("optT12HR_1", 120, 600, 2520, 380, "Use pin T12HR(P1.6) as input")) Then Exit Function
        If (Not ps.AddOption("optT12HR_2", 120, 960, 2520, 380, "Use pin T12HR(P0.0) as input")) Then Exit Function
        If (Not ps.AddOption("optT12HR_3", 120, 1320, 2520, 380, "Use pin T12HR(P2.0) as input")) Then Exit Function

    '-------------------------------
    ' frame: frmT13HR
    '-------------------------------
    If (Not ps.AddFrame("frmT13HR", 5760, 2000, 2880, 2000, "Control of Pin T13HR")) Then Exit Function
        If (Not ps.AddOption("optT13HR_0", 120, 240, 2000, 380, "Pin T13HR is not used")) Then Exit Function
        If (Not ps.AddOption("optT13HR_1", 120, 600, 2520, 380, "Use pin T13HR(P1.7) as input")) Then Exit Function
        If (Not ps.AddOption("optT13HR_2", 120, 960, 2520, 380, "Use pin T13HR(P0.1) as input")) Then Exit Function
        If (Not ps.AddOption("optT13HR_3", 120, 1320, 2520, 380, "Use pin T13HR(P2.1) as input")) Then Exit Function

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

  OnShowPagePinControl1 = 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 = 6
  sVarPre = "CCU" & vIndex
  sRegPre = sVarPre & "_"

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

  If (Pagename = "Pin Control 1") Then
    '-------------------------------------------------------------------------
    ' page: PinControl1 (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
    
        Case "optCCPOS0_0"
            sVarPre = "CCPOS0"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_CCPOS0_PIN") = 0
            r.v(sRegPre & "PISEL0H_ISPOS0") = 0
            
                If (IsHallSensorModeEnable(r, vIndex)) Then
                    Call DisableHallSensorMode(r, vIndex)
                End If
                
                If (r.v(sRegPre & "T12MSELL_MSEL60") = 9 Or _
                    r.v(sRegPre & "T12MSELL_MSEL60") = 10 Or _
                    r.v(sRegPre & "T12MSELL_MSEL60") = 11 Or _
                    r.v(sRegPre & "T12MSELL_MSEL60") = 12 Or _
                    r.v(sRegPre & "T12MSELL_MSEL60") = 13 Or _
                    r.v(sRegPre & "T12MSELL_MSEL60") = 14) Then
                    
                    Call SelectModeForCC6Channelx(r, vIndex, 0, 0)

                End If

                r.v(sRegPre & "IENH_ENIDLE") = 0
                r.v(sRegPre & "IENH_ENCHE") = 0
                r.v(sRegPre & "IENH_ENWHE") = 0
                r.v(sRegPre & "MCMCTR_SWSEL") = 0

        Case "optCCPOS0_1"
            sVarPre = "CCPOS0"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_CCPOS0_PIN") = 1
            r.v(sRegPre & "PISEL0H_ISPOS0") = 0
                Call RequestAlternateInputPin(r, "CCPOS0_0")
        
        Case "optCCPOS0_2"
            sVarPre = "CCPOS0"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_CCPOS0_PIN") = 2
            r.v(sRegPre & "PISEL0H_ISPOS0") = 1
                Call RequestAlternateInputPin(r, "CCPOS0_1")
        
        Case "optCCPOS0_3"
            sVarPre = "CCPOS0"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_CCPOS0_PIN") = 3
            r.v(sRegPre & "PISEL0H_ISPOS0") = 2
                Call RequestAlternateInputPin(r, "CCPOS0_2")
            
        
        Case "optCCPOS1_0"
            sVarPre = "CCPOS1"
            Call ReleaseInputPins(r, sVarPre)
            r.v(sRegPre & "PISEL0H_ISPOS1") = 0
            r.v("CCU6_USE_CCPOS1_PIN") = 0
        
                If (IsHallSensorModeEnable(r, vIndex)) Then
                    Call DisableHallSensorMode(r, vIndex)
                End If
                
                If (r.v(sRegPre & "T12MSELL_MSEL61") = 9 Or _
                    r.v(sRegPre & "T12MSELL_MSEL61") = 10 Or _
                    r.v(sRegPre & "T12MSELL_MSEL61") = 11 Or _
                    r.v(sRegPre & "T12MSELL_MSEL61") = 12 Or _
                    r.v(sRegPre & "T12MSELL_MSEL61") = 13 Or _
                    r.v(sRegPre & "T12MSELL_MSEL61") = 14) Then
                    
                    Call SelectModeForCC6Channelx(r, vIndex, 1, 0)

                End If

                r.v(sRegPre & "IENH_ENIDLE") = 0
                r.v(sRegPre & "IENH_ENCHE") = 0
                r.v(sRegPre & "IENH_ENWHE") = 0
                r.v(sRegPre & "MCMCTR_SWSEL") = 0
        
        Case "optCCPOS1_1"
            sVarPre = "CCPOS1"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_CCPOS1_PIN") = 1
            r.v(sRegPre & "PISEL0H_ISPOS1") = 0
                Call RequestAlternateInputPin(r, "CCPOS1_0")
        
        Case "optCCPOS1_2"
            sVarPre = "CCPOS1"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_CCPOS1_PIN") = 2
            r.v(sRegPre & "PISEL0H_ISPOS1") = 1
                Call RequestAlternateInputPin(r, "CCPOS1_1")
        
        Case "optCCPOS1_3"
            sVarPre = "CCPOS1"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_CCPOS1_PIN") = 3
            r.v(sRegPre & "PISEL0H_ISPOS1") = 2
                Call RequestAlternateInputPin(r, "CCPOS1_2")
        
        Case "optCCPOS2_0"
            sVarPre = "CCPOS2"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_CCPOS2_PIN") = 0
            r.v(sRegPre & "PISEL0H_ISPOS2") = 0
        
                If (IsHallSensorModeEnable(r, vIndex)) Then
                    Call DisableHallSensorMode(r, vIndex)
                End If
                
                If (r.v(sRegPre & "T12MSELH_MSEL62") = 9 Or _
                    r.v(sRegPre & "T12MSELH_MSEL62") = 10 Or _
                    r.v(sRegPre & "T12MSELH_MSEL62") = 11 Or _
                    r.v(sRegPre & "T12MSELH_MSEL62") = 12 Or _
                    r.v(sRegPre & "T12MSELH_MSEL62") = 13 Or _
                    r.v(sRegPre & "T12MSELH_MSEL62") = 14) Then
                    
                    Call SelectModeForCC6Channelx(r, vIndex, 2, 0)

                End If

                r.v(sRegPre & "IENH_ENIDLE") = 0
                r.v(sRegPre & "IENH_ENCHE") = 0
                r.v(sRegPre & "IENH_ENWHE") = 0
                r.v(sRegPre & "MCMCTR_SWSEL") = 0
        
        Case "optCCPOS2_1"
            sVarPre = "CCPOS2"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_CCPOS2_PIN") = 1
            r.v(sRegPre & "PISEL0H_ISPOS2") = 0
                Call RequestAlternateInputPin(r, "CCPOS2_0")
        
        Case "optCCPOS2_2"
            sVarPre = "CCPOS2"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_CCPOS2_PIN") = 2
            r.v(sRegPre & "PISEL0H_ISPOS2") = 1
                Call RequestAlternateInputPin(r, "CCPOS2_1")
        
        Case "optCCPOS2_3"
            sVarPre = "CCPOS2"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_CCPOS2_PIN") = 3
            r.v(sRegPre & "PISEL0H_ISPOS2") = 2
                Call RequestAlternateInputPin(r, "CCPOS2_2")
            
        Case "optCTRAP_0"
            sVarPre = "#CTRAP"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_#CTRAP_PIN") = 0
            r.v(sRegPre & "PISEL0L_ISTRP") = 0
        
        Case "optCTRAP_1"
            sVarPre = "#CTRAP"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_#CTRAP_PIN") = 1
            r.v(sRegPre & "PISEL0L_ISTRP") = 0
                Call RequestAlternateInputPin(r, "#CTRAP_0")
        
        Case "optCTRAP_2"
            sVarPre = "#CTRAP"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_#CTRAP_PIN") = 2
            r.v(sRegPre & "PISEL0L_ISTRP") = 1
                Call RequestAlternateInputPin(r, "#CTRAP_1")
        
        Case "optCTRAP_3"
            sVarPre = "#CTRAP"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_#CTRAP_PIN") = 3
            r.v(sRegPre & "PISEL0L_ISTRP") = 2
                Call RequestAlternateInputPin(r, "#CTRAP_2")

        Case "optT12HR_0"
            sVarPre = "T12HR"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_T12HR_PIN") = 0
            r.v(sRegPre & "PISEL0H_IST12HR") = 0
        
        Case "optT12HR_1"
            sVarPre = "T12HR"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_T12HR_PIN") = 1
            r.v(sRegPre & "PISEL0H_IST12HR") = 0
                Call RequestAlternateInputPin(r, "T12HR_0")
        
        Case "optT12HR_2"
            sVarPre = "T12HR"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_T12HR_PIN") = 2
            r.v(sRegPre & "PISEL0H_IST12HR") = 1
                Call RequestAlternateInputPin(r, "T12HR_1")
        
        Case "optT12HR_3"
            sVarPre = "T12HR"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_T12HR_PIN") = 3
            r.v(sRegPre & "PISEL0H_IST12HR") = 2
                Call RequestAlternateInputPin(r, "T12HR_2")
            
        Case "optT13HR_0"
            sVarPre = "T13HR"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_T13HR_PIN") = 0
            r.v(sRegPre & "PISEL2_IST13HR") = 0
        
        Case "optT13HR_1"
            sVarPre = "T13HR"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_T13HR_PIN") = 1
            r.v(sRegPre & "PISEL2_IST13HR") = 0
                Call RequestAlternateInputPin(r, "T13HR_0")
        
        Case "optT13HR_2"
            sVarPre = "T13HR"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_T13HR_PIN") = 2
            r.v(sRegPre & "PISEL2_IST13HR") = 1
                Call RequestAlternateInputPin(r, "T13HR_1")
        
        Case "optT13HR_3"
            sVarPre = "T13HR"
            Call ReleaseInputPins(r, sVarPre)
            r.v("CCU6_USE_T13HR_PIN") = 3
            r.v(sRegPre & "PISEL2_IST13HR") = 2
                Call RequestAlternateInputPin(r, "T13HR_2")
            
    End Select

    '-------------------------------------------------------------------------
    ' page: PinControl (show)
    '-------------------------------------------------------------------------
    '-------------------------------------------------------------------------
    ' page: PinControl (CCPOS0)
    '-------------------------------------------------------------------------
        With c("optCCPOS0_0")
           bDisabled = IsModuleClockDisabled(r, vIndex)
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_CCPOS0_PIN") = 0)
        End With

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

        With c("optCCPOS0_1")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CCPOS0_0")))
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_CCPOS0_PIN") = 1)
        End With
        
        With e("optCCPOS0_1")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CCPOS0_0")
            End If
        End If
        End With

        With c("optCCPOS0_2")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CCPOS0_1")))
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_CCPOS0_PIN") = 2)
        End With

        With e("optCCPOS0_2")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CCPOS0_1")
            End If
          End If
        End With

        With c("optCCPOS0_3")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CCPOS0_2")))
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_CCPOS0_PIN") = 3)
        End With

        With e("optCCPOS0_3")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CCPOS0_2")
            End If
          End If
        End With

    '-------------------------------------------------------------------------
    ' page: PinControl (CCPOS1)
    '-------------------------------------------------------------------------
        With c("optCCPOS1_0")
           bDisabled = (r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1)
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_CCPOS1_PIN") = 0)
        End With

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

        With c("optCCPOS1_1")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CCPOS1_0")))
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_CCPOS1_PIN") = 1)
        End With
        
        With e("optCCPOS1_1")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
           If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CCPOS1_0")
            End If
          End If
        End With

        With c("optCCPOS1_2")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CCPOS1_1")))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CCPOS1_PIN") = 2)
        End With

        With e("optCCPOS1_2")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
           If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CCPOS1_1")
            End If
          End If
        End With

        With c("optCCPOS1_3")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CCPOS1_2")))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CCPOS1_PIN") = 3)
        End With

        With e("optCCPOS1_3")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CCPOS1_2")
            End If
          End If
        End With
        
    '-------------------------------------------------------------------------
    ' page: PinControl (CCPOS2)
    '-------------------------------------------------------------------------
        With c("optCCPOS2_0")
          bDisabled = (r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1)
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_CCPOS2_PIN") = 0)
        End With

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

        With c("optCCPOS2_1")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CCPOS2_0")))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CCPOS2_PIN") = 1)
        End With
        
        With e("optCCPOS2_1")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CCPOS2_0")
            End If
          End If
        End With

        With c("optCCPOS2_2")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CCPOS2_1")))
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_CCPOS2_PIN") = 2)
        End With

        With e("optCCPOS2_2")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CCPOS2_1")
            End If
          End If
        End With

        With c("optCCPOS2_3")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CCPOS2_2")))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CCPOS2_PIN") = 3)
        End With

        With e("optCCPOS2_3")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CCPOS2_2")
            End If
          End If
        End With

    '-------------------------------------------------------------------------
    ' page: PinControl (#CTRAP)
    '-------------------------------------------------------------------------
        
        With c("optCTRAP_0")
          bDisabled = (r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1)
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_#CTRAP_PIN") = 0)
        End With

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

        With c("optCTRAP_1")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "#CTRAP_0")))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_#CTRAP_PIN") = 1)
        End With

        With e("optCTRAP_1")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "#CTRAP_0")
            End If
          End If
        End With

        With c("optCTRAP_2")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "#CTRAP_1")))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_#CTRAP_PIN") = 2)
        End With

        With e("optCTRAP_2")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "#CTRAP_1")
            End If
          End If
        End With

        With c("optCTRAP_3")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "#CTRAP_2")))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_#CTRAP_PIN") = 3)
        End With

        With e("optCTRAP_3")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "#CTRAP_2")
            End If
          End If
        End With

    '-------------------------------------------------------------------------
    ' page: PinControl (T12HR)
    '-------------------------------------------------------------------------
        With c("optT12HR_0")
          bDisabled = (r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1)
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_T12HR_PIN") = 0)
        End With

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

        With c("optT12HR_1")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "T12HR_0")))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_T12HR_PIN") = 1)
        End With
        
        With e("optT12HR_1")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T12HR_0")
            End If
          End If
        End With

        With c("optT12HR_2")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "T12HR_1")))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_T12HR_PIN") = 2)
        End With

        With e("optT12HR_2")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T12HR_1")
            End If
          End If
        End With

        With c("optT12HR_3")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "T12HR_2")))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_T12HR_PIN") = 3)
        End With
        
        With e("optT12HR_3")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T12HR_2")
            End If
          End If
        End With


    '-------------------------------------------------------------------------
    ' page: PinControl (T13HR)
    '-------------------------------------------------------------------------
        With c("optT13HR_0")
          bDisabled = (r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1)
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_T13HR_PIN") = 0)
        End With

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

        With c("optT13HR_1")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "T13HR_0")))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_T13HR_PIN") = 1)
        End With
        
        With e("optT13HR_1")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T13HR_0")
            End If
          End If
        End With

        With c("optT13HR_2")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "T13HR_1")))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_T13HR_PIN") = 2)
        End With

        With e("optT13HR_2")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T13HR_1")
            End If
          End If
        End With

        With c("optT13HR_3")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "T13HR_2")))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_T13HR_PIN") = 3)
        End With
        
        With e("optT13HR_3")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "T13HR_2")
            End If
          End If
        End With


  End If

  OnShowPagePinControl1 = True
  Exit Function

OnShowPagePinControl1Error:
  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 OnLoadPagePinControl2(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPagePinControl2 = False

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

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

  OnChangingPagePinControl2 = False
  
  Dim vIndex As Variant
  Dim sVarPre As String

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

  If (Not ps.ExtenderCollection("Pin Control 2").Loaded) And (Pagename = "Pin Control 2") Then
    ps.ExtenderCollection("Pin Control 2").Loaded = True
  
    '-------------------------------
    ' frame: frmCC60
    '-------------------------------
    If (Not ps.AddFrame("frmCC60", 0, 120, 2880, 2020, "Control of Pin CC60")) Then Exit Function
        If (Not ps.AddOption("optCC60_0", 120, 250, 2100, 350, "Pin CC60 is not used")) Then Exit Function
        If (Not ps.AddOption("optCC60_1", 120, 600, 2640, 350, "Use pin CC60(P3.0) as Input")) Then Exit Function
        If (Not ps.AddOption("optCC60_2", 120, 950, 2640, 350, "Use pin CC60(P3.0) as Output")) Then Exit Function
        If (Not ps.AddOption("optCC60_3", 120, 1300, 2640, 350, "Use pin CC60(P2.2) as Input")) Then Exit Function
        If (Not ps.AddOption("optCC60_4", 120, 1650, 2640, 350, "Use pin CC60(P4.0) as Output")) Then Exit Function

    '-------------------------------
    ' frame: frmCOUT60
    '-------------------------------
    If (Not ps.AddFrame("frmCOUT60", 0, 2220, 2880, 1400, "Control of Pin COUT60")) Then Exit Function
        If (Not ps.AddOption("optCOUT60_0", 120, 250, 2100, 350, "Pin COUT60 is not used")) Then Exit Function
        If (Not ps.AddOption("optCOUT60_1", 120, 600, 2730, 350, "Use pin COUT60(P3.1) as Output")) Then Exit Function
        If (Not ps.AddOption("optCOUT60_2", 120, 950, 2730, 350, "Use pin COUT60(P4.1) as Output")) Then Exit Function

    '-------------------------------
    ' frame: frmCOUT63
    '-------------------------------
    If (Not ps.AddFrame("frmCOUT63", 0, 3700, 2880, 1700, "Control of Pin COUT63")) Then Exit Function
        If (Not ps.AddOption("optCOUT63_0", 120, 250, 2640, 350, "Pin COUT63 is not used")) Then Exit Function
        If (Not ps.AddOption("optCOUT63_1", 120, 600, 2710, 350, "Use pin COUT63(P3.7) as Output")) Then Exit Function
        If (Not ps.AddOption("optCOUT63_2", 120, 950, 2710, 350, "Use pin COUT63(P0.3) as Output")) Then Exit Function
        If (Not ps.AddOption("optCOUT63_3", 120, 1300, 2710, 350, "Use pin COUT63(P4.3) as Output")) Then Exit Function
    
    '-------------------------------
    ' frame: frmCC61
    '-------------------------------
    If (Not ps.AddFrame("frmCC61", 2880, 120, 2880, 3250, "Control of Pin CC61")) Then Exit Function
        If (Not ps.AddOption("optCC61_0", 120, 250, 2000, 350, "Pin CC61 is not used")) Then Exit Function
        If (Not ps.AddOption("optCC61_1", 120, 600, 2640, 350, "Use pin CC61(P3.2) as Input")) Then Exit Function
        If (Not ps.AddOption("optCC61_2", 120, 950, 2640, 350, "Use pin CC61(P0.0) as Input")) Then Exit Function
        If (Not ps.AddOption("optCC61_3", 120, 1300, 2640, 350, "Use pin CC61(P3.2) as Output")) Then Exit Function
        If (Not ps.AddOption("optCC61_4", 120, 1650, 2640, 350, "Use pin CC61(P0.0) as Output")) Then Exit Function
        If (Not ps.AddOption("optCC61_5", 120, 2000, 2640, 350, "Use pin CC61(P3.1) as Input")) Then Exit Function
        If (Not ps.AddOption("optCC61_6", 120, 2350, 2640, 350, "Use pin CC61(P3.1) as Output")) Then Exit Function
        If (Not ps.AddOption("optCC61_7", 120, 2700, 2640, 350, "Use pin CC61(P2.0) as Input")) Then Exit Function

    '-------------------------------
    ' frame: frmCOUT61
    '-------------------------------
    If (Not ps.AddFrame("frmCOUT61", 2880, 3450, 2880, 1400, "Control of Pin COUT61")) Then Exit Function
        If (Not ps.AddOption("optCOUT61_0", 120, 250, 2100, 350, "Pin COUT61 is not used")) Then Exit Function
        If (Not ps.AddOption("optCOUT61_1", 120, 600, 2730, 350, "Use pin COUT61(P3.3) as Output")) Then Exit Function
        If (Not ps.AddOption("optCOUT61_2", 120, 950, 2730, 350, "Use pin COUT61(P0.1) as Output")) Then Exit Function

    '-------------------------------
    ' frame: frmCC62
    '-------------------------------
    If (Not ps.AddFrame("frmCC62", 5760, 120, 2880, 2450, "Control of Pin CC62")) Then Exit Function
        If (Not ps.AddOption("optCC62_0", 120, 250, 2000, 350, "Pin CC62 is not used")) Then Exit Function
        If (Not ps.AddOption("optCC62_1", 120, 600, 2640, 350, "Use pin CC62(P3.4) as Input")) Then Exit Function
        If (Not ps.AddOption("optCC62_2", 120, 950, 2640, 350, "Use pin CC62(P0.4) as Input")) Then Exit Function
        If (Not ps.AddOption("optCC62_3", 120, 1300, 2640, 350, "Use pin CC62(P3.4) as Output")) Then Exit Function
        If (Not ps.AddOption("optCC62_4", 120, 1650, 2640, 350, "Use pin CC62(P0.4) as Output")) Then Exit Function
''        If (Not ps.AddOption("optCC62_5", 120, 2000, 2640, 350, "Use pin CC62(P2.1) as Input")) Then Exit Function
''        If (Not ps.AddOption("optCC62_6", 120, 2000, 2640, 350, "Use pin CC62(P2.1) as Input")) Then Exit Function
        If (Not ps.AddOption("optCC62_7", 120, 2000, 2640, 350, "Use pin CC62(P2.1) as Input")) Then Exit Function

    '-------------------------------
    ' frame: frmCOUT62
    '-------------------------------
    If (Not ps.AddFrame("frmCOUT62", 5760, 2650, 2880, 1400, "Control of Pin COUT62")) Then Exit Function
        If (Not ps.AddOption("optCOUT62_0", 120, 250, 2100, 350, "Pin COUT62 is not used")) Then Exit Function
        If (Not ps.AddOption("optCOUT62_1", 120, 600, 2730, 350, "Use pin COUT62(P3.5) as Output")) Then Exit Function
        If (Not ps.AddOption("optCOUT62_2", 120, 950, 2730, 350, "Use pin COUT62(P0.5) as Output")) Then Exit Function

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

  OnShowPagePinControl2 = 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 sTempVar As String
  Dim i As Integer
  Dim bDisabled As Boolean
  Dim sHelp As String

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

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

  If (Pagename = "Pin Control 2") Then
    '-------------------------------------------------------------------------
    ' page: PinControl2 (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
   
        Case "optCC60_0"
    '-------------------------------------------------------------------------
            Call Release_CC60_Pins(r)
               
        Case "optCC60_1"

                '-------------------------------------------------------------------------
            i = 0
            sHelp = "L"
                '-------------------------------------------------------------------------
    
          If (r.v("CCU6_USE_CC60_PIN") = 2) Then
                Call ReleaseAlternateOutputPin(r, "CC60_0(Output)")
                If (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 1 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 3) Then
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)
                End If
                Call SetModulationControlPagesToDefault(r, vIndex, "CC", i)
                
            ElseIf (r.v("CCU6_USE_CC60_PIN") = 3) Then
                Call ReleaseAlternateInputPin(r, "CC60_3(Input)")
            ElseIf (r.v("CCU6_USE_CC60_PIN") = 4) Then
                Call ReleaseAlternateInputPin(r, "CC60_1")
            End If
            
                r.v("CCU6_USE_CC60_PIN") = 1
                r.v(sRegPre & "PISEL0L_ISCC60") = 0
                Call RequestAlternateInputPin(r, "CC60_0(Input)")
                    
        Case "optCC60_2"
     
                '-------------------------------------------------------------------------
            i = 0
            sHelp = "L"
                '-------------------------------------------------------------------------
            If (r.v("CCU6_USE_CC60_PIN") = 1) Then
                Call ReleaseAlternateInputPin(r, "CC60_0(Input)")
            ElseIf (r.v("CCU6_USE_CC60_PIN") = 3) Then
                Call ReleaseAlternateInputPin(r, "CC60_3(Input)")
            ElseIf (r.v("CCU6_USE_CC60_PIN") = 4) Then
                Call ReleaseAlternateInputPin(r, "CC60_1")
            End If
            
            If ((r.v("CCU6_USE_CC60_PIN") = 1) Or (r.v("CCU6_USE_CC60_PIN") = 3)) Then
                If (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 4 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 5 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 6 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 7 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 10 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 11 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 12 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 13 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 14) Then
                    
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)

                End If
            End If
                Call RequestAlternateOutputPin(r, "CC60_0(Output)", ALT_FUN1)
                
                r.v("CCU6_USE_CC60_PIN") = 2
                
                r.v(sRegPre & "PISEL0L_ISCC60") = 0


        Case "optCC60_3"
    '-------------------------------------------------------------------------
            i = 0
            sHelp = "L"
    '-------------------------------------------------------------------------
        
            If (r.v("CCU6_USE_CC60_PIN") = 1) Then
                Call ReleaseAlternateInputPin(r, "CC60_0(Input)")
            ElseIf (r.v("CCU6_USE_CC60_PIN") = 2) Then
                Call ReleaseAlternateOutputPin(r, "CC60_0(Output)")
                If (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 1 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 3) Then
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)
                End If
                Call SetModulationControlPagesToDefault(r, vIndex, "CC", i)
            ElseIf (r.v("CCU6_USE_CC60_PIN") = 4) Then
                Call ReleaseAlternateInputPin(r, "CC60_1")
            End If
            
                r.v("CCU6_USE_CC60_PIN") = 3
                
                r.v(sRegPre & "PISEL0L_ISCC60") = 3
                Call RequestAlternateInputPin(r, "CC60_3(Input)")


         Case "optCC60_4"
         
    '-------------------------------------------------------------------------
            i = 0
            sHelp = "L"
    '-------------------------------------------------------------------------
            If (r.v("CCU6_USE_CC60_PIN") = 1) Then
                Call ReleaseAlternateInputPin(r, "CC60_0(Input)")
            ElseIf (r.v("CCU6_USE_CC60_PIN") = 2) Then
                Call ReleaseAlternateInputPin(r, "CC60_0(Output)")
            ElseIf (r.v("CCU6_USE_CC60_PIN") = 3) Then
                Call ReleaseAlternateInputPin(r, "CC60_3(Input)")
            End If
            
            If ((r.v("CCU6_USE_CC60_PIN") = 1) Or (r.v("CCU6_USE_CC60_PIN") = 3)) Then
                If (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 4 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 5 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 6 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 7 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 10 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 11 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 12 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 13 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 14) Then
                    
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)

                End If
            End If
                Call RequestAlternateOutputPin(r, "CC60_1", ALT_FUN1)
                
                r.v("CCU6_USE_CC60_PIN") = 4
                
                r.v(sRegPre & "PISEL0L_ISCC60") = 0

    '-------------------------------------------------------------------------
    '-------------------------------------------------------------------------

         Case "optCOUT60_0"
    '-------------------------------------------------------------------------
          Call Release_COUT60_Pins(r)
            
         Case "optCOUT60_1"
           
            If (r.v("CCU6_USE_COUT60_PIN") = 2) Then
                Call ReleaseAlternateOutputPin(r, "COUT60_1")
            End If
         
            r.v("CCU6_USE_COUT60_PIN") = 1
                Call RequestAlternateOutputPin(r, "COUT60_0", ALT_FUN1)

         Case "optCOUT60_2"
            If (r.v("CCU6_USE_COUT60_PIN") = 1) Then
                Call ReleaseAlternateOutputPin(r, "COUT60_0")
            End If
            r.v("CCU6_USE_COUT60_PIN") = 2
                Call RequestAlternateOutputPin(r, "COUT60_1", ALT_FUN1)

    
    '-------------------------------------------------------------------------

         Case "optCC61_0"
    '-------------------------------------------------------------------------
        
            Call Release_CC61_Pins(r)
                
                         
         Case "optCC61_1"
    '-------------------------------------------------------------------------
            i = 1
            sHelp = "L"
    '-------------------------------------------------------------------------
            sTempVar = "CC61"
            Call ReleasePins(r, sTempVar)
            r.v("CCU6_USE_CC61_PIN") = 1
            r.v(sRegPre & "PISEL0L_ISCC61") = 0
                Call RequestAlternateInputPin(r, "CC61_0(Input)")
         
                If (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 1 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 3) Then
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)
                End If
                Call SetModulationControlPagesToDefault(r, vIndex, "CC", i)
         
         
         Case "optCC61_2"
    '-------------------------------------------------------------------------
            i = 1
            sHelp = "L"
    '-------------------------------------------------------------------------
            sTempVar = "CC61"
            Call ReleasePins(r, sTempVar)
            r.v("CCU6_USE_CC61_PIN") = 2
            r.v(sRegPre & "PISEL0L_ISCC61") = 1
                Call RequestAlternateInputPin(r, "CC61_1(Input)")
                
                If (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 1 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 3) Then
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)
                End If
                Call SetModulationControlPagesToDefault(r, vIndex, "CC", i)

         Case "optCC61_3"
    '-------------------------------------------------------------------------
            i = 1
            sHelp = "L"
    '-------------------------------------------------------------------------
            sTempVar = "CC61"
            Call ReleasePins(r, sTempVar)
            r.v("CCU6_USE_CC61_PIN") = 3
            r.v(sRegPre & "PISEL0L_ISCC61") = 0
                Call RequestAlternateOutputPin(r, "CC61_0(Output)", ALT_FUN1)
    
                If (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 4 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 5 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 6 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 7 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 10 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 11 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 12 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 13 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 14) Then
                    
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)

                End If
    
         Case "optCC61_4"
    '-------------------------------------------------------------------------
            i = 1
            sHelp = "L"
    '-------------------------------------------------------------------------
            sTempVar = "CC61"
            Call ReleasePins(r, sTempVar)
            r.v("CCU6_USE_CC61_PIN") = 4
            r.v(sRegPre & "PISEL0L_ISCC61") = 0
                Call RequestAlternateOutputPin(r, "CC61_1(Output)", ALT_FUN2)
    
                If (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 4 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 5 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 6 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 7 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 10 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 11 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 12 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 13 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 14) Then
                    
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)

                End If
                
         Case "optCC61_5"
    '-------------------------------------------------------------------------
            i = 1
            sHelp = "L"
    '-------------------------------------------------------------------------
            sTempVar = "CC61"
            Call ReleasePins(r, sTempVar)
            r.v("CCU6_USE_CC61_PIN") = 5
            r.v(sRegPre & "PISEL0L_ISCC61") = 2
                Call RequestAlternateInputPin(r, "CC61_2(Input)")
                
                If (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 1 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 3) Then
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)
                End If
                Call SetModulationControlPagesToDefault(r, vIndex, "CC", i)
                
         Case "optCC61_6"
    '-------------------------------------------------------------------------
            i = 1
            sHelp = "L"
    '-------------------------------------------------------------------------
            sTempVar = "CC61"
            Call ReleasePins(r, sTempVar)
            r.v("CCU6_USE_CC61_PIN") = 6
            r.v(sRegPre & "PISEL0L_ISCC61") = 0
                Call RequestAlternateOutputPin(r, "CC61_2(Output)", ALT_FUN2)
    
                If (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 4 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 5 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 6 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 7 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 10 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 11 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 12 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 13 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 14) Then
                    
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)

                End If
                
         Case "optCC61_7"
    '-------------------------------------------------------------------------
            i = 1
            sHelp = "L"
    '-------------------------------------------------------------------------
            sTempVar = "CC61"
            Call ReleasePins(r, sTempVar)
            r.v("CCU6_USE_CC61_PIN") = 7
            r.v(sRegPre & "PISEL0L_ISCC61") = 3
                Call RequestAlternateInputPin(r, "CC61_3(Input)")
                
                If (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 1 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 3) Then
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)
                End If
                Call SetModulationControlPagesToDefault(r, vIndex, "CC", i)
                
    '-------------------------------------------------------------------------
    '-------------------------------------------------------------------------
    
         Case "optCOUT61_0"
    '-------------------------------------------------------------------------

            Call Release_COUT61_Pins(r)
           
         Case "optCOUT61_1"
            sTempVar = "COUT61"
            Call ReleaseOutputPins(r, sTempVar)
            r.v("CCU6_USE_COUT61_PIN") = 1
                Call RequestAlternateOutputPin(r, "COUT61_0", ALT_FUN1)
    
         Case "optCOUT61_2"
            sTempVar = "COUT61"
            Call ReleaseOutputPins(r, sTempVar)
            r.v("CCU6_USE_COUT61_PIN") = 2
                Call RequestAlternateOutputPin(r, "COUT61_1", ALT_FUN2)
    
    
         Case "optCC62_0"
    '-------------------------------------------------------------------------
          
            Call Release_CC62_Pins(r)
                
         Case "optCC62_1"
    '-------------------------------------------------------------------------
            i = 2
            sHelp = "H"
    '-------------------------------------------------------------------------
            sTempVar = "CC62"
            Call ReleasePins(r, sTempVar)
            r.v("CCU6_USE_CC62_PIN") = 1
            r.v(sRegPre & "PISEL0L_ISCC62") = 0
                Call RequestAlternateInputPin(r, "CC62_0(Input)")
                If (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 1 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 3) Then
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)
                End If
                Call SetModulationControlPagesToDefault(r, vIndex, "CC", i)
         
         Case "optCC62_2"
    '-------------------------------------------------------------------------
            i = 2
            sHelp = "H"
    '-------------------------------------------------------------------------
            sTempVar = "CC62"
            Call ReleasePins(r, sTempVar)
            r.v("CCU6_USE_CC62_PIN") = 2
            r.v(sRegPre & "PISEL0L_ISCC62") = 1
                Call RequestAlternateInputPin(r, "CC62_1(Input)")
                If (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 1 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 3) Then
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)
                End If
                Call SetModulationControlPagesToDefault(r, vIndex, "CC", i)

         Case "optCC62_3"
    '-------------------------------------------------------------------------
            i = 2
            sHelp = "H"
    '-------------------------------------------------------------------------
            sTempVar = "CC62"
            Call ReleasePins(r, sTempVar)
            r.v("CCU6_USE_CC62_PIN") = 3
            r.v(sRegPre & "PISEL0L_ISCC62") = 0
                Call RequestAlternateOutputPin(r, "CC62_0(Output)", ALT_FUN1)
    
                If (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 4 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 5 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 6 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 7 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 10 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 11 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 12 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 13 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 14) Then
                    
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)

                End If
    
         Case "optCC62_4"
    '-------------------------------------------------------------------------
            i = 2
            sHelp = "H"
    '-------------------------------------------------------------------------
            sTempVar = "CC62"
            Call ReleasePins(r, sTempVar)
            r.v("CCU6_USE_CC62_PIN") = 4
            r.v(sRegPre & "PISEL0L_ISCC62") = 0
                Call RequestAlternateOutputPin(r, "CC62_1(Output)", ALT_FUN2)
    
                If (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 4 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 5 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 6 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 7 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 10 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 11 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 12 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 13 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 14) Then
                    
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)

                End If
'         Case "optCC62_5"
'
'         Case "optCC62_6"
    
         Case "optCC62_7"
    '-------------------------------------------------------------------------
            i = 2
            sHelp = "H"
    '-------------------------------------------------------------------------
            sTempVar = "CC62"
            Call ReleasePins(r, sTempVar)
            r.v("CCU6_USE_CC62_PIN") = 7
            r.v(sRegPre & "PISEL0L_ISCC62") = 3
                Call RequestAlternateInputPin(r, "CC62_3(Input)")
                If (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 1 Or _
                    r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & i) = 3) Then
                    Call SelectModeForCC6Channelx(r, vIndex, i, 0)
                End If
                Call SetModulationControlPagesToDefault(r, vIndex, "CC", i)
    
    
    '-------------------------------------------------------------------------
    '-------------------------------------------------------------------------
         Case "optCOUT62_0"
    '-------------------------------------------------------------------------
   
            Call Release_COUT62_Pins(r)
       
         Case "optCOUT62_1"
            sTempVar = "COUT62"
            Call ReleaseOutputPins(r, sTempVar)
            r.v("CCU6_USE_COUT62_PIN") = 1
                Call RequestAlternateOutputPin(r, "COUT62_0", ALT_FUN1)
    
         Case "optCOUT62_2"
            sTempVar = "COUT62"
            Call ReleaseOutputPins(r, sTempVar)
            r.v("CCU6_USE_COUT62_PIN") = 2
                Call RequestAlternateOutputPin(r, "COUT62_1", ALT_FUN2)
    
    
         Case "optCOUT63_0"
           
            Call Release_COUT63_Pins(r)
    
         Case "optCOUT63_1"
            sTempVar = "COUT63"
            Call ReleaseOutputPins(r, sTempVar)
            r.v("CCU6_USE_COUT63_PIN") = 1
                Call RequestAlternateOutputPin(r, "COUT63_0", ALT_FUN1)
    
         Case "optCOUT63_2"
            sTempVar = "COUT63"
            Call ReleaseOutputPins(r, sTempVar)
            r.v("CCU6_USE_COUT63_PIN") = 2
                Call RequestAlternateOutputPin(r, "COUT63_1", ALT_FUN2)
    
         Case "optCOUT63_3"
            sTempVar = "COUT63"
            Call ReleaseOutputPins(r, sTempVar)
            r.v("CCU6_USE_COUT63_PIN") = 3
                Call RequestAlternateOutputPin(r, "COUT63_2", ALT_FUN2)
    
    End Select
               
    '-------------------------------------------------------------------------
    ' page: PinControl2 (CC60)
    '-------------------------------------------------------------------------
        With c("optCC60_0")
          bDisabled = (r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1)
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_CC60_PIN") = 0)
        End With

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

        With c("optCC60_1")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CC60_0(Input)"))) Or (r.v("CCU6_USE_CC60_PIN") = 2))
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_CC60_PIN") = 1)
        End With
        
        With e("optCC60_1")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CC60_0(Input)")
            End If
          End If
        End With

        With c("optCC60_2")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not (IsAlternatePinFree(r, "CC60_0(Output)")))) Or (r.v("CCU6_USE_CC60_PIN") = 1))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CC60_PIN") = 2)
        End With

        With e("optCC60_2")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CC60_0(Output)")
            End If
          End If
        End With

        With c("optCC60_3")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not (IsAlternatePinFree(r, "CC60_3(Input)"))))) ' Or (r.v("CCU6_USE_CC60_PIN") = 1))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CC60_PIN") = 3)
        End With

        With e("optCC60_3")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CC60_3(Input)")
            End If
          End If
        End With

        With c("optCC60_4")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not (IsAlternatePinFree(r, "CC60_1"))))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CC60_PIN") = 4)
        End With

        With e("optCC60_4")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CC60_1")
            End If
          End If
        End With

    '-------------------------------------------------------------------------
    ' page: PinControl2 (COUT60)
    '-------------------------------------------------------------------------
        With c("optCOUT60_0")
          bDisabled = (r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1)
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_COUT60_PIN") = 0)
        End With

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

        With c("optCOUT60_1")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "COUT60_0")))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_COUT60_PIN") = 1)
        End With

        With e("optCOUT60_1")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "COUT60_0")
            End If
          End If
        End With

        With c("optCOUT60_2")
          bDisabled = ((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "COUT60_1")))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_COUT60_PIN") = 2)
        End With

        With e("optCOUT60_2")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "COUT60_1")
            End If
          End If
        End With

    '-------------------------------------------------------------------------
    ' page: PinControl2 (CC61)
    '-------------------------------------------------------------------------
        With c("optCC61_0")
          bDisabled = (r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1)
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_CC61_PIN") = 0)
        End With

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

        With c("optCC61_1")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CC61_0(Input)"))) Or (r.v("CCU6_USE_CC61_PIN") = 3))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CC61_PIN") = 1)
        End With
        
        With e("optCC61_1")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CC61_0(Input)")
            End If
          End If
        End With

        With c("optCC61_2")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CC61_1(Input)"))) Or (r.v("CCU6_USE_CC61_PIN") = 4))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CC61_PIN") = 2)
        End With
        
        With e("optCC61_2")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CC61_1(Input)")
            End If
          End If
        End With
        
        With c("optCC61_3")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CC61_0(Output)"))) Or (r.v("CCU6_USE_CC61_PIN") = 1))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CC61_PIN") = 3)
        End With
        
        With e("optCC61_3")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CC61_0(Output)")
            End If
          End If
        End With
        
        With c("optCC61_4")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CC61_1(Output)"))) Or (r.v("CCU6_USE_CC61_PIN") = 2))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CC61_PIN") = 4)
        End With
        
        With e("optCC61_4")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CC61_1(Output)")
            End If
          End If
        End With
        
        With c("optCC61_5")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CC61_2(Input)"))) Or (r.v("CCU6_USE_CC61_PIN") = 6))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CC61_PIN") = 5)
        End With
        
        With e("optCC61_5")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CC61_2(Input)")
            End If
          End If
        End With
        
        With c("optCC61_6")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CC61_2(Output)"))) Or (r.v("CCU6_USE_CC61_PIN") = 5))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CC61_PIN") = 6)
        End With
        
        With e("optCC61_6")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CC61_2(Output)")
            End If
          End If
        End With
        
        With c("optCC61_7")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CC61_3(Input)"))))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CC61_PIN") = 7)
        End With
        
        With e("optCC61_7")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CC61_3(Input)")
            End If
          End If
        End With
        
    '-------------------------------------------------------------------------
    '-------------------------------------------------------------------------
        With c("optCOUT61_0")
          bDisabled = (r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 0)
          .Enabled = (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_COUT61_PIN") = 0)
        End With
        
        With e("optCOUT61_0")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
          End If
        End With
        
        With c("optCOUT61_1")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "COUT61_0"))))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_COUT61_PIN") = 1)
        End With
        
        With e("optCOUT61_1")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "COUT61_0")
            End If
          End If
        End With
        
        With c("optCOUT61_2")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "COUT61_1"))))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_COUT61_PIN") = 2)
        End With
        
        With e("optCOUT61_2")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "COUT61_1")
            End If
          End If
        End With
        
        
    '-------------------------------------------------------------------------
    ' page: PinControl2 (CC62)
    '-------------------------------------------------------------------------
        With c("optCC62_0")
          bDisabled = (r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1)
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_CC62_PIN") = 0)
        End With

        With e("optCC62_0")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
          End If
        End With
          
        With c("optCC62_1")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CC62_0(Input)"))) Or (r.v("CCU6_USE_CC62_PIN") = 3))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CC62_PIN") = 1)
        End With
        
        With e("optCC62_1")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CC62_0(Input)")
            End If
          End If
        End With

        With c("optCC62_2")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CC62_1(Input)"))) Or (r.v("CCU6_USE_CC62_PIN") = 4))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CC62_PIN") = 2)
        End With
        
        With e("optCC62_2")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CC62_1(Input)")
            End If
          End If
        End With
        
        With c("optCC62_3")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CC62_0(Output)"))) Or (r.v("CCU6_USE_CC62_PIN") = 1))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CC62_PIN") = 3)
        End With
        
        With e("optCC62_3")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CC62_0(Output)")
            End If
          End If
        End With
        
        With c("optCC62_4")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CC62_1(Output)"))) Or (r.v("CCU6_USE_CC62_PIN") = 2))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CC62_PIN") = 4)
        End With
        
        With e("optCC62_4")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CC62_1(Output)")
            End If
          End If
        End With
        
        With c("optCC62_7")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "CC62_3(Input)"))))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_CC62_PIN") = 7)
        End With
        
        With e("optCC62_7")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "CC62_3(Input)")
            End If
          End If
        End With
        
        With c("optCOUT62_0")
          bDisabled = (r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1)
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_COUT62_PIN") = 0)
        End With
        
        With e("optCOUT62_0")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
          End If
        End With
        
        With c("optCOUT62_1")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "COUT62_0"))))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_COUT62_PIN") = 1)
        End With
        
        With e("optCOUT62_1")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "COUT62_0")
            End If
          End If
        End With
        
        With c("optCOUT62_2")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "COUT62_1"))))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_COUT62_PIN") = 2)
        End With
        
        With e("optCOUT62_2")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "COUT62_1")
            End If
          End If
        End With
        
'---------------------------------------
'-------------------

        With c("optCOUT63_0")
          bDisabled = (r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1)
          .Enabled = Not (bDisabled)
          .Value = -CInt(r.v("CCU6_USE_COUT63_PIN") = 0)
        End With
        
        With e("optCOUT63_0")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
          End If
        End With
        
        With c("optCOUT63_1")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "COUT63_0"))))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_COUT63_PIN") = 1)
        End With
        
        With e("optCOUT63_1")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "COUT63_0")
            End If
          End If
        End With
        
        With c("optCOUT63_2")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "COUT63_1"))))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_COUT63_PIN") = 2)
        End With
        
        With e("optCOUT63_2")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "COUT63_1")
            End If
          End If
        End With
        
        With c("optCOUT63_3")
          bDisabled = (((r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or (Not IsAlternatePinFree(r, "COUT63_2"))))
          .Enabled = Not bDisabled
          .Value = -CInt(r.v("CCU6_USE_COUT63_PIN") = 3)
        End With
        
        With e("optCOUT63_3")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            Else
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "COUT63_2")
            End If
          End If
        End With
        
  End If

  OnShowPagePinControl2 = True
  Exit Function

OnShowPagePinControl2Error:
  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("Timer " & 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("Timer " & iTmr).Loaded) And _
       (Pagename = "Timer " & iTmr) Then
    ps.ExtenderCollection("Timer " & 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", 1575, 400, 3350, 315)) Then Exit Function
        If (Not ps.AddLabel("lblT" & iTmr & "CLK", 0, 200, 450, 1200, 330, _
            "Input selection")) Then Exit Function

    '-------------------------------
    ' frame: frmTxR
    '-------------------------------
    If (Not ps.AddFrame("frmT" & iTmr & "RR", 5750, 100, 2850, 1000, _
        "Timer " & iTmr & " Start Control")) Then Exit Function
        If (Not ps.AddCheck("chkT" & iTmr & "RS", 200, 350, 2200, 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, 700, _
            "Timer " & iTmr & " Single Shot Control")) Then Exit Function
            If (Not ps.AddCheck("chkT" & iTmr & "SSC", 200, 250, 3300, 300, _
                "Enable single shot mode (T" & iTmr & "SSC)")) Then Exit Function

        If (Not ps.AddFrame("frmT" & iTmr & "RSEL", 100, 1900, 4350, 1000, _
              "Timer T12 External Run Selection (T" & iTmr & "RSEL)")) Then Exit Function
            If (Not ps.AddCombo("cboT" & iTmr & "RSEL", 1750, 350, 2525, 380)) Then Exit Function
            If (Not ps.AddLabel("lblT" & iTmr & "RSEL", 0, 100, 350, 1400, 530, _
                "Timer T12 External Run Selection")) Then Exit Function

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

        '-------------------------------
        ' frame: frmTxIE
        '-------------------------------
        If (Not ps.AddFrame("frmT" & iTmr & "IC", 100, 4100, 4350, 1200, _
            "Interrupt Control of Timer " & iTmr)) 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, 3800, 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, 2300, _
            "Timer " & iTmr & " Period Register")) 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, 400, _
                "Period register" & vbCrLf & "(T" & iTmr & "PRH, T" & iTmr & "PRL)")) Then Exit Function
            If (Not ps.AddText("txtT" & iTmr & "PR", 2200, 1150, 1200, 300)) Then Exit Function

        '-------------------------------
        ' frame: frmDTM
        '-------------------------------
        If (Not ps.AddFrame("frmDTM", 4600, 3500, 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, 5550, 1000, _
            "Timer T13 Trigger Event Control (T13TEC)")) Then Exit Function
            If (Not ps.AddCombo("cboT13TEC", 1350, 400, 4150, 315)) Then Exit Function
            If (Not ps.AddLabel("lblT13TEC", 0, 200, 450, 1100, 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: frmTxRSEL
        '-------------------------------

        If (Not ps.AddFrame("frmT" & iTmr & "RSEL", 100, 3250, 5350, 800, _
            "Timer T13 External Run Selection (T" & iTmr & " RSEL)")) Then Exit Function
            If (Not ps.AddCombo("cboT" & iTmr & "RSEL", 2300, 350, 2600, 380)) Then Exit Function
            If (Not ps.AddLabel("lblT" & iTmr & "RSEL", 0, 100, 350, 1900, 530, _
                "Timer T13 External Run Selection")) Then Exit Function
        
        '-------------------------------
        ' frame: frmTxSSC
        '-------------------------------
        If (Not ps.AddFrame("frmT" & iTmr & "SSC", 5750, 1150, 2850, 1000, _
            "Timer " & iTmr & " Single Shot Control")) Then Exit Function
            If (Not ps.AddCheck("chkT" & iTmr & "SSC", 200, 300, 2300, 600, _
                "Enable single shot mode (T" & iTmr & "SSC)")) Then Exit Function


        '-------------------------------
        ' frame: frmTxIE
        '-------------------------------
        If (Not ps.AddFrame("frmT" & iTmr & "IC", 100, 4100, 5350, 1200, _
            "Interrupt Control of Timer " & iTmr)) 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", 5600, 3250, 3000, 2050, _
            "Timer " & iTmr & " Period Register")) 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", 1700, 500, 1200, 300)) Then Exit Function
        
            If (Not ps.AddLabel("lblT" & iTmr & "PR", 0, 200, 1300, 2000, 400, _
                "Period register" & vbCrLf & "(T" & iTmr & "PRH, T" & iTmr & "PRL)")) Then Exit Function
            If (Not ps.AddText("txtT" & iTmr & "PR", 1700, 1350, 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
  Dim sHelp As String


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

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

  If (iTmr = 12) Then
      sHelp = "L"
  Else
      sHelp = "H"
  End If

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

  If (Pagename = "Timer " & iTmr) Then
    '-------------------------------------------------------------------------
    ' page: Timer_x_y (action)
    '-------------------------------------------------------------------------
  
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: cboT" & iTmr & "CLK (action)
        '---------------------------------------------------------------------
        Case "cboT" & iTmr & "CLK"
            For i = 0 To 15
                If (v(1) = GetTextForCLKcbo(r, vIndex, iTmr, i)) Then
                    r.v(sRegPre & "TCTR0" & sHelp & "_T" & iTmr & "CLK") = i Mod 8
                 If i < 8 Then
                    r.v(sRegPre & "TCTR0" & sHelp & "_T" & iTmr & "PRE") = 0
                 Else
                    r.v(sRegPre & "TCTR0" & sHelp & "_T" & iTmr & "PRE") = 1
                 End If
                End If
            Next i
            
        '---------------------------------------------------------------------
        ' control: cboT" & iTmr & "CLK (action)
        '---------------------------------------------------------------------
        Case "cboT" & iTmr & "RSEL"
            Select Case (v(1))
               Case ("Disable external setting of T" & iTmr)
                  r.v(sRegPre & "TCTR2H_T" & iTmr & "RSEL") = 0
               Case ("Rising edge of signal T" & iTmr & "HR")
                  r.v(sRegPre & "TCTR2H_T" & iTmr & "RSEL") = 1
               Case ("Falling edge of signal T" & iTmr & "HR")
                  r.v(sRegPre & "TCTR2H_T" & iTmr & "RSEL") = 2
               Case ("Edge of signal T" & iTmr & "HR")
                  r.v(sRegPre & "TCTR2H_T" & iTmr & "RSEL") = 3

        End Select

        '---------------------------------------------------------------------
        ' control: chkT..RR (action)
        '---------------------------------------------------------------------
        Case "chkT" & iTmr & "RS"
            r.v(sRegPre & "TCTR4" & sHelp & "_T" & iTmr & "RS") = v(1)
            If (v(1) = 1) Then
                If (iTmr = 13) Then
                    r.v(sRegPre & "TCTR2L_T13TEC") = 0
                End If
            End If
        
        '---------------------------------------------------------------------
        ' control: chkT..SSC (action)
        '---------------------------------------------------------------------
        Case "chkT" & iTmr & "SSC"
            r.v(sRegPre & "TCTR2L_T" & iTmr & "SSC") = v(1)
        
        '---------------------------------------------------------------------
        ' control: chkENT" & iTmr & "PM (action)
        '---------------------------------------------------------------------
        Case "chkENT" & iTmr & "PM"
            r.v(sRegPre & "IEN" & sHelp & "_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
              Call SetCC6Register_L_and_H(r, "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
        
              Call SetCC6Register_L_and_H(r, "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 & "TCTR0L_CTM") = 0
                r.v(sRegPre & "TCTR2L_T13TED") = 0

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

            '---------------------------------------------------------------------
            ' control: txtT.. (action)
            '---------------------------------------------------------------------
            Case "txtDTM"
                If (IsInputFormatOK(v(1), "H2", c("lblDTM").Caption, 1, 255)) Then
                  r.l(sRegPre & "T12DTCL_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 & "T12DTCL_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" & sHelp & "_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" & sHelp & "_ENT" & iTmr & "CM") = v(1)

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

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

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

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

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

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

                    Case ("Start T13 upon a zero-match of T12 (while counting up)")
                        r.v(sRegPre & "TCTR2L_T13TEC") = 6
                        r.v(sRegPre & "TCTR2L_T13TED") = 0

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

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

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

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

                    Case ("Start T13 independent on the count direction of T12")
                        r.v(sRegPre & "TCTR2L_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 & "RSEL").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" & sHelp & "_T" & iTmr & "RS") = 1)
    
    If (r.v(sRegPre & "TCTR4" & sHelp & "_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 & "TCTR2L_T13TEC") = 0)

    If (r.v(sRegPre & "TCTR2L_T13TEC") = 0) Then
        sDisabledTooltip = sDisabledTooltip & FormatDisabledToolTip("the trigger control is disabled")
        r.v(sRegPre & "TCTR2L_T13TED") = 0
    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 15
          .AddItem GetTextForCLKcbo(r, vIndex, iTmr, i)
        Next i
        If r.v(sRegPre & "TCTR0" & sHelp & "_T" & iTmr & "PRE") = 0 Then
        .ListIndex = r.v(sRegPre & "TCTR0" & sHelp & "_T" & iTmr & "CLK")
        Else
        .ListIndex = r.v(sRegPre & "TCTR0" & sHelp & "_T" & iTmr & "CLK") + 8
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: cboTxRSEL (show)
    '-------------------------------------------------------------------------
    With c("cboT" & iTmr & "RSEL")
        .Clear

          .AddItem "Disable external setting of T" & iTmr
                  .AddItem "Rising edge of signal T" & iTmr & "HR"
                  .AddItem "Falling edge of signal T" & iTmr & "HR"
                  .AddItem "Edge of signal T" & iTmr & "HR"

        .ListIndex = r.v(sRegPre & "TCTR2H_T" & iTmr & "RSEL")
    
    End With

    '-------------------------------------------------------------------------
    ' control: chkTxRR (show)
    '-------------------------------------------------------------------------
    With c("chkT" & iTmr & "RS")
        .Value = -CInt(r.v(sRegPre & "TCTR4" & sHelp & "_T" & iTmr & "RS") = 1)
    End With
    
    '-------------------------------------------------------------------------
    ' control: chkTxSSC (show)
    '-------------------------------------------------------------------------
    With c("chkT" & iTmr & "SSC")
        .Value = -CInt(r.v(sRegPre & "TCTR2L_T" & iTmr & "SSC") = 1)
    End With
    
    '-------------------------------------------------------------------------
    ' control: chkENT" & iTmr & "PM (show)
    '-------------------------------------------------------------------------
    With c("chkENT" & iTmr & "PM")
        .Value = -CInt(r.v(sRegPre & "IEN" & sHelp & "_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(GetRegisterValue_L_and_H(r, "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 & "TCTR0L_CTM") = 0)
        End With

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

        '-------------------------------------------------------------------------
        ' control: txtTxPR (show)
        '-------------------------------------------------------------------------
        With c("txtDTM")
            If (IsModuleClockDisabled(r, vIndex)) Then
                .Text = CALCULATION_NOT_POSSIBLE
            Else
                .Text = FormatTextOutput(r.v(sRegPre & "T12DTCL_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" & sHelp & "_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 & "TCTR2L_T13TEC")
        End With

        '-------------------------------------------------------------------------
        ' control: cboT13TED (show)
        '-------------------------------------------------------------------------
        With c("cboT13TED")
            .Clear
            .AddItem "no action"
            .AddItem "Start T13 while T12 is counting up"
            If (r.v(sRegPre & "TCTR0L_CTM") = 1 And Not (r.v(sRegPre & "TCTR2L_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 & "TCTR2L_T13TED")

        End With
        '-------------------------------------------------------------------------
        ' control: chkENT" & iTmr & "CM (show)
        '-------------------------------------------------------------------------
        With c("chkENT" & iTmr & "CM")
            .Value = -CInt(r.v(sRegPre & "IEN" & sHelp & "_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 Channel")) 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 Channel").Loaded) And (Pagename = "Multi Channel") Then
    ps.ExtenderCollection("Multi Channel").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: frmSWSEL
    '-------------------------------
    If (Not ps.AddFrame("frmSWSEL", 100, 1150, 4150, 2500, "Switching Selection (SWSEL)")) Then Exit Function
        If (Not ps.AddOption("optSWSEL_0", 200, 250, 3000, 400, "No trigger request will be generated")) Then Exit Function
        If (Not ps.AddOption("optSWSEL_1", 200, 600, 2700, 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, 3800, 400, "Transfer on T12 period match (while counting up)")) 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, 3200, 380, "Enable hall sensor mode (T12MSEL)")) Then Exit Function

    '-------------------------------
    ' frame: frmSWSYN
    '-------------------------------
    If (Not ps.AddFrame("frmSWSYN", 4400, 1150, 4150, 1650, "Switching Synchronization (SWSYN)")) Then Exit Function
        If (Not ps.AddOption("optSWSYN_0", 200, 300, 1800, 350, "Direct transfer")) Then Exit Function
        If (Not ps.AddOption("optSWSYN_1", 200, 650, 2800, 350, "Synchronization on T13 zero-match")) Then Exit Function
        If (Not ps.AddOption("optSWSYN_2", 200, 1000, 2800, 400, "Synchronization on T12 zero-match (while counting up)")) Then Exit Function

    '-------------------------------
    ' frame: frmENIDLE
    '-------------------------------
    If (Not ps.AddFrame("frmENIDLE", 4400, 2800, 4150, 850, "IDLE Control")) Then Exit Function
        If (Not ps.AddCheck("chkENIDLE", 200, 300, 3300, 400, "Enable the automatic entering of the idle state (ENIDLE)")) Then Exit Function
    
    '-------------------------------
    ' frame: frmHall_IC
    '-------------------------------
    If (Not ps.AddFrame("frmHall_IC", 100, 3700, 8450, 1500, "Interrupt Control")) Then Exit Function
        If (Not ps.AddCheck("chkENCHE", 200, 250, 3900, 300, "Enable interrupt for correct hall event (ENCHE)")) Then Exit Function
        If (Not ps.AddCheck("chkENWHE", 200, 650, 3900, 300, "Enable interrupt for wrong hall event (ENWHE)")) Then Exit Function
        If (Not ps.AddCheck("chkENSTR", 200, 1000, 4900, 300, "Enable Multi-Channel Mode Shadow Transfer Interrupt (ENSTR)")) 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 Channel") Then
    '-------------------------------------------------------------------------
    ' page: MultiChMode (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: chkMCMEN (action)
        '---------------------------------------------------------------------
        Case "chkMCMEN"
            r.v(sRegPre & "MODCTRL_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 & "IENH_ENIDLE") = 0
                r.v(sRegPre & "IENH_ENCHE") = 0
                r.v(sRegPre & "IENH_ENWHE") = 0
                r.v(sRegPre & "IENH_ENSTR") = 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 (GetRegisterValue_L_and_H(r, "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 & "IENH_ENIDLE") = 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 & "IENH_ENIDLE") = 0

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

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

        '---------------------------------------------------------------------
        ' control: optSWSEL_5 (action)
        '---------------------------------------------------------------------
        Case "optSWSEL_5"
            r.v(sRegPre & "MCMCTR_SWSEL") = 5
            r.v(sRegPre & "IENH_ENIDLE") = 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: chkENIDLE (action)
        '---------------------------------------------------------------------
        Case "chkENIDLE"
            r.v(sRegPre & "IENH_ENIDLE") = v(1)

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

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

        '---------------------------------------------------------------------
        ' control: chkENSTR (action)
        '---------------------------------------------------------------------
        Case "chkENSTR"
            r.v(sRegPre & "IENH_ENSTR") = v(1)
      
      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: MultiChMode (show)
    '-------------------------------------------------------------------------
    bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                 r.v(sRegPre & "MODCTRL_MCMEN") = 0)
    
    sDisabledTooltip = ""
    sDisabledTooltip = TOOLTIP_DISABLED_IF
    
    If (IsModuleClockDisabled(r, vIndex)) Then
        sDisabledTooltip = sDisabledTooltip & GetTooltipModuleClockDisabled(r, vIndex)
    End If
    If (r.v(sRegPre & "MODCTRL_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 and frmHall_IC
    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, "")
    
    
    bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                 r.v(sRegPre & "MODCTRL_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 & "MODCTRL_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 & "MODCTRL_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
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkEnHallMode (show)
    '-------------------------------------------------------------------------
    With c("chkEnHallMode")
        bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                    r.v(sRegPre & "MODCTRL_MCMEN") = 0 Or _
                    (Not ((GetPinFunction(r, "CCPOS0_0") = 1) Or _
                         (GetPinFunction(r, "CCPOS0_1") = 1) Or _
                         (GetPinFunction(r, "CCPOS0_2") = 1)) Or _
                     Not ((GetPinFunction(r, "CCPOS1_0") = 1) Or _
                         (GetPinFunction(r, "CCPOS1_1") = 1) Or _
                         (GetPinFunction(r, "CCPOS1_2") = 1)) Or _
                     Not ((GetPinFunction(r, "CCPOS2_0") = 1) Or _
                         (GetPinFunction(r, "CCPOS2_1") = 1) Or _
                         (GetPinFunction(r, "CCPOS2_2") = 1))))
'                    Not (GetPinFunction(r, "CCPOS2_0(Input)") = 1))

        .Enabled = Not (bDisabled)
        .Value = -CInt(GetRegisterValue_L_and_H(r, "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 & "MODCTRL_MCMEN") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledToolTip("multi channel mode is not enabled")
            End If
            If (Not (GetPinFunction(r, "CCPOS0") = 1)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledToolTip("pin CCPOS0 is not used as input")
            End If
            If (Not (GetPinFunction(r, "CCPOS1") = 1)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledToolTip("pin CCPOS1 is not used as input")
            End If
            If (Not (GetPinFunction(r, "CCPOS2") = 1)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledToolTip("pin CCPOS2 is not used as input")
            End If
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSWSEL_0 (show)
    '-------------------------------------------------------------------------
    With c("optSWSEL_0")
        bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                    r.v(sRegPre & "MODCTRL_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 & "MODCTRL_MCMEN") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledToolTip("multi channel mode is not enabled")
            End If
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSWSEL_2 (show)
    '-------------------------------------------------------------------------
    With c("optSWSEL_2")
        .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
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSWSEL_3 (show)
    '-------------------------------------------------------------------------
    With c("optSWSEL_3")
        .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
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSWSEL_4 (show)
    '-------------------------------------------------------------------------
    With c("optSWSEL_4")
        .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
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSWSEL_5 (show)
    '-------------------------------------------------------------------------
    With c("optSWSEL_5")
        .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
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optSWSEL_1 (show)
    '-------------------------------------------------------------------------
    With c("optSWSEL_1")
        bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                    (Not ((GetPinFunction(r, "CCPOS0_0") = 1) Or _
                         (GetPinFunction(r, "CCPOS0_1") = 1) Or _
                         (GetPinFunction(r, "CCPOS0_2") = 1)) Or _
                     Not ((GetPinFunction(r, "CCPOS1_0") = 1) Or _
                         (GetPinFunction(r, "CCPOS1_1") = 1) Or _
                         (GetPinFunction(r, "CCPOS1_2") = 1)) Or _
                     Not ((GetPinFunction(r, "CCPOS2_0") = 1) Or _
                         (GetPinFunction(r, "CCPOS2_1") = 1) Or _
                         (GetPinFunction(r, "CCPOS2_2") = 1)))) Or _
                         (r.v(sRegPre & "MODCTRL_MCMEN") = 0)

        .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 & "MODCTRL_MCMEN") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledToolTip("multi channel mode is not enabled")
            End If
            If (Not (GetPinFunction(r, "CCPOS0") = 1)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledToolTip("pin CCPOS0 is not used as input")
            End If
            If (Not (GetPinFunction(r, "CCPOS1") = 1)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledToolTip("pin CCPOS1 is not used as input")
            End If
            If (Not (GetPinFunction(r, "CCPOS2") = 1)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledToolTip("pin CCPOS2 is not used as input")
            End If
        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: chkENIDLE (show)
    '-------------------------------------------------------------------------
    With c("chkENIDLE")
        .Value = -CInt(r.v(sRegPre & "IENH_ENIDLE") = 1)
    End With

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

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

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

    With e("chkENSTR")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  GetTooltipModuleClockDisabled(r, vIndex)
            End If
            If (r.v(sRegPre & "MODCTRL_MCMEN") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledToolTip("multi channel mode is not enabled")
            End If
        End If
    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
  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

          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 / Interrupt Control")) 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 / Interrupt Control").Loaded) And (Pagename = "Trap / Interrupt Control") Then
    ps.ExtenderCollection("Trap / Interrupt Control").Loaded = True
  
    '-------------------------------
    ' frame: frmTRPPEN
    '-------------------------------
    If (Not ps.AddFrame("frmTRPPEN", 100, 100, 8475, 1200, "Trap Pin Control (TRPPEN)")) Then Exit Function
        If (Not ps.AddOption("optTRPPEN_0", 200, 250, 4500, 380, "A trap can only be generated by SW by setting bit TRPF")) Then Exit Function
        If (Not ps.AddOption("optTRPPEN_1", 200, 700, 4300, 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, 8000, 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, 6400, 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, 6100, 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, 6800, 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, 8000, 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, "Interrupt Control and Interrupt 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 / Interrupt Control") Then
    '-------------------------------------------------------------------------
    ' page: TrapControl (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)

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

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

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

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

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

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

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

        '---------------------------------------------------------------------
        ' control: chkENTRPF (action)
        '---------------------------------------------------------------------
        Case "chkENTRPF"
            r.v(sRegPre & "IENH_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: optTRPPEN_0 (show)
    '-------------------------------------------------------------------------
    With c("optTRPPEN_0")
        bDisabled = (IsModuleClockDisabled(r, vIndex))
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sRegPre & "TRPCTRH_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
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: optTRPPEN_1 (show)
    '-------------------------------------------------------------------------
    With c("optTRPPEN_1")
          bDisabled = (r.v(SCU_PREFIX & "PMCON1_CCU_DIS") = 1) Or ((r.v("CCU6_USE_#CTRAP_PIN") = 0))
          .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sRegPre & "TRPCTRH_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 (r.v("CCU6_USE_#CTRAP_PIN") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & _
                  FormatDisabledToolTip("pin #CTRAP is not used as input")
            End If
        End If
    End With

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

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

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

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

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

    '-------------------------------------------------------------------------
    ' control: optTRPM2_1 (show)
    '-------------------------------------------------------------------------
    With c("chkENTRPF")
        .Value = -CInt(r.v(sRegPre & "IENH_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 = "Interrupt Configuration"
    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 Function1 is called from the OnLoad Function1 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 aFunction(1 To 16) As String

  Dim r As ProjectData
  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, 0, 4150, 700, _
        CAPTION_FRA_USE_INIT)) Then Exit Function
      If (Not ps.AddCheck("chk_Init", 150, 275, 1500, 275, "CC6_vInit")) Then Exit Function
      If (Not ps.AddText("txt_Init", 2400, 250, 1700, 325)) Then Exit Function

    '-------------------------------
    ' frame: fra_CFile
    '-------------------------------
    If (Not ps.AddFrame("fra_CFile", 4400, 0, 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(aFunction) To UBound(aFunction)
      aFunction(i) = ""
    Next i

    ' Function and Macros
    i = LBound(aFunction)

    aFunction(i) = "StartTmr"
    i = i + 1
    aFunction(i) = "StopTmr"
    i = i + 1
    aFunction(i) = "ResetTmr"
    i = i + 1
    aFunction(i) = "SetTmrPeriod"
    i = i + 1
    aFunction(i) = "GetTmrCounter"
    i = i + 1
    aFunction(i) = "SetTmrCounter"
    i = i + 1
    aFunction(i) = "SetDeadTimePeriod"
    i = i + 1
    aFunction(i) = "EnableShadowTransfer"
    i = i + 1
    aFunction(i) = "LoadChannelShadowRegister"
    i = i + 1
    aFunction(i) = "GetChannelShadowRegister"
    i = i + 1
    aFunction(i) = "GetChannelRegister"
    i = i + 1
    aFunction(i) = "SetStatusBit"
    i = i + 1
    aFunction(i) = "ResetStatusBit"
    i = i + 1
   
    If (Not ps.AddFrame("fraLibrary1", 100, 700, 4150, 1500, CAPTION_FRA_LIBRARY1)) Then Exit Function
      For i = LBound(aFunction) To 4
        If Not (aFunction(i) = "") Then
          If (Not ps.AddCheck("chk_" & aFunction(i), 200, 250 + (300 * (i - 1)), 1900, 275, "CC6_v" & aFunction(i))) Then Exit Function
          If (Not ps.AddText("txt_" & aFunction(i), 2400, 225 + (300 * (i - 1)), 1700, 325)) Then Exit Function
        End If
      Next i
    
    If (Not ps.AddFrame("fraLibrary3", 100, 2200, 8450, 3225, "Function Library (Part 3)")) Then Exit Function
      For i = 5 To 6
        If Not (aFunction(i) = "") Then
          If (Not ps.AddCheck("chk_" & aFunction(i), 200, 250 + ((300 * (i - 1)) - 1275), 2100, 275, "CC6_uw" & aFunction(i))) Then Exit Function
          If (Not ps.AddText("txt_" & aFunction(i), 4300, 225 + ((300 * (i - 1)) - 1275), 4000, 325)) Then Exit Function
        End If
      Next i
      
      For i = 7 To 9
        If Not (aFunction(i) = "") Then
          If (Not ps.AddCheck("chk_" & aFunction(i), 200, 250 + ((300 * (i - 1)) - 1275), 2900, 275, "CC6_v" & aFunction(i))) Then Exit Function
          If (Not ps.AddText("txt_" & aFunction(i), 4300, 225 + ((300 * (i - 1)) - 1275), 4000, 325)) Then Exit Function
        End If
      Next i
      For i = 10 To 11
        If Not (aFunction(i) = "") Then
          If (Not ps.AddCheck("chk_" & aFunction(i), 200, 250 + ((300 * (i - 1)) - 1275), 2950, 275, "CC6_uw" & aFunction(i))) Then Exit Function
          If (Not ps.AddText("txt_" & aFunction(i), 4300, 225 + ((300 * (i - 1)) - 1275), 4000, 325)) Then Exit Function
        End If
      Next i
      
      For i = 12 To UBound(aFunction)
        If Not (aFunction(i) = "") Then
          If (Not ps.AddCheck("chk_" & aFunction(i), 200, 250 + ((300 * (i - 1)) - 1275), 2200, 275, "CC6_v" & aFunction(i))) Then Exit Function
          If (Not ps.AddText("txt_" & aFunction(i), 4300, 225 + ((300 * (i - 1)) - 1275), 4000, 325)) Then Exit Function
        End If
      Next i
      
    If (Not ps.AddCheck("chkCC6_GetTmrPeriod", 200, 2875, 2100, 275, "CC6_uwGetTmrPeriod")) Then Exit Function
    If (Not ps.AddText("txtCC6_GetTmrPeriod", 4300, 2850, 4000, 325)) Then Exit Function
    '-------------------------------
    ' frame: fraLibrary2
    '-------------------------------
    ' initialize the array
    For i = LBound(aFunction) To UBound(aFunction)
      aFunction(i) = ""
    Next i

    ' Function and Macros
    i = LBound(aFunction)

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

    If (Not ps.AddFrame("fraLibrary2", 4400, 700, 4150, 1500, CAPTION_FRA_LIBRARY2)) Then Exit Function
      For i = LBound(aFunction) To UBound(aFunction)
        If Not (aFunction(i) = "") Then
             If (IsCpuTypeOK(r)) Then
                If (Not ps.AddCheck("chk_" & aFunction(i), 200, 250 + (300 * (i - 1)), 2000, 275, "SHINT_viXINTR1" & (i - 1) & "Isr")) Then Exit Function
             Else
                If (Not ps.AddCheck("chk_" & aFunction(i), 200, 250 + (300 * (i - 1)), 2000, 275, "CC6_vi" & aFunction(i))) Then Exit Function
             End If
          If (Not ps.AddText("txt_" & aFunction(i), 2400, 225 + (300 * (i - 1)), 1700, 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 OnShowPageFunctionError

  OnShowPageFunctions = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim func As CC6FunctionClass
  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 CC6FunctionClass

  If (Pagename = "Functions") Then
    '-------------------------------------------------------------------------
    ' page: Function (action)
    '-------------------------------------------------------------------------
    Call RefreshFunctionDescriptions(vIndex, func, r)
    
    If (Not UpdateFunction(sVarPre, ps, func, Controlname, v)) Then Exit Function
    If (Not UpdateFunc(ps, Controlname, v, "GetTmrPeriod")) Then Exit Function
    '-------------------------------------------------------------------------
    ' page: Function (show)
    '-------------------------------------------------------------------------
    Set func = New CC6FunctionClass
    Call RefreshFunctionDescriptions(vIndex, func, r)

    sName = sVarPre & "_NAME_Init"
    func.Disabled(sName) = (IsModuleClockDisabled(r, vIndex))
    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
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    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
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    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
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    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
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    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
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    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
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    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
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    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
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    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
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    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
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    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
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    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
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    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
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    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
    func.Disabled(sName) = True
    d = TOOLTIP_DISABLED_ISR
    func.DisabledToolTip(sName) = d
    func.Value(sName) = (r.v(CORE_PREFIX & "IEN1_ECCIP0") = 1 And r.v(sVarPre & "_USE_Init") = 1)

    sFctName = "NodeI1"
    sName = sVarPre & "_NAME_" & sFctName
    func.Disabled(sName) = True
    d = TOOLTIP_DISABLED_ISR
    func.DisabledToolTip(sName) = d
    func.Value(sName) = (r.v(CORE_PREFIX & "IEN1_ECCIP1") = 1 And r.v(sVarPre & "_USE_Init") = 1)

    sFctName = "NodeI2"
    sName = sVarPre & "_NAME_" & sFctName
    func.Disabled(sName) = True
    d = TOOLTIP_DISABLED_ISR
    func.DisabledToolTip(sName) = d
    func.Value(sName) = (r.v(CORE_PREFIX & "IEN1_ECCIP2") = 1 And r.v(sVarPre & "_USE_Init") = 1)

    sFctName = "NodeI3"
    sName = sVarPre & "_NAME_" & sFctName
    func.Disabled(sName) = True
    d = TOOLTIP_DISABLED_ISR
    func.DisabledToolTip(sName) = d
    func.Value(sName) = (r.v(CORE_PREFIX & "IEN1_ECCIP3") = 1 And r.v(sVarPre & "_USE_Init") = 1)

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

  End If         ' if Pagename

  OnShowPageFunctions = True
  Exit Function

OnShowPageFunctionError:
  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)
    '-------------------------------------------------------------------------
    Call RefreshParameterDescriptions(vIndex, para, r)

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


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

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

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

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

  End If         ' if Pagename

  OnShowPageParameters = True
  Exit Function

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




'*****************************************************************************
'Description:
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the Project Data Object
'        Controlname     control name
'        v()             value array
'        sName           function keyword
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function UpdateFunc(ps As Peripherals, Controlname As String, v() As Variant, sName As String) As Boolean
  On Error GoTo ExitLabel
  UpdateFunc = False

  Dim r As ProjectData
  Dim c As Collection

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

  '---------------------------------------------------------------------
  ' control: chkADC_USE_.. (action)
  'chkCC6_GetTmrPeriod
  '---------------------------------------------------------------------
  If (Controlname = "chkCC6_" & sName) Then
    r.v("CAN_USE_WriteCANAddress_I") = v(1)
  End If
  '---------------------------------------------------------------------
  ' control: txtADC_NAME_.. (action)
  '---------------------------------------------------------------------
  If (Controlname = "txtCC6_" & sName) Then
    If (IsInputFormatOK(v(1), FORMAT_FUNCTIONS, c("chkCC6_GetTmrPeriod").Caption)) Then
        r.v("CAN_NAME_WriteCANAddress_I") = v(1)
    Else
       Exit Function
    End If
  End If
  
  UpdateFunc = True
ExitLabel:
End Function


'*****************************************************************************
'Description:
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        v()             value array
'        func            reference to the function object
'        sName           function keyword
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************

Function ShowFunc(ps As Peripherals, v() As Variant, func As CC6FunctionClass, sName As String) As Boolean
  On Error GoTo ExitLabel1
  ShowFunc = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  
  Dim vIndex As Variant

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
    If (r.v("CAN_NAME_WriteCANAddress_I") = "CAN_vWriteCANAddress_I") Then
        r.v("CAN_NAME_WriteCANAddress_I") = "CC6_uwGetTmrPeriod"
    End If

  '-------------------------------------------------------------------------
  ' control: chk_USE_.. (show)
  '-------------------------------------------------------------------------
  ' action on showing the control
  With c("chkCC6_" & sName)
    Select Case sName

        Case "Isr"      ' ISR functions are always disabled
            bDisabled = True
        
        Case Else
            bDisabled = (r.v("CCU6_USE_Init") = 0)
    End Select    ' disable condition
    .Enabled = Not bDisabled
    .Value = -CInt((r.v("CCU6_USE_Init") = 1) And (r.v("CAN_USE_WriteCANAddress_I") = 1))
  End With

  With e("chkCC6_" & sName)
    If (bDisabled) Then
        ' tooltip if control is disabled
        .DisabledTooltipText = GetDisabledFunctionToolTipEntry(func, "CAN_NAME_WriteCANAddress_I")
        .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
  End With

'  -------------------------------------------------------------------------
'   control: txt_NAME_... (show)
'  -------------------------------------------------------------------------
  With c("txtCC6_" & sName)
    bDisabled = c("chkCC6_" & sName).Value = 0
       .Enabled = Not bDisabled
       .Text = FormatTextOutput(r.s("CAN_NAME_WriteCANAddress_I"), "S")
  End With

  With e("txtCC6_" & sName)
    If (bDisabled) Then
          .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_NAME) & vbCrLf & vbCrLf & FormatFunctionToolTip(r, func, "CAN_NAME_WriteCANAddress_I")
    End If
  End With

  ShowFunc = True
ExitLabel1:
End Function
