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

Option Explicit

'*****************************************************************************
' Module:
'        CAPCOMx
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'CAPCOMx'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        1.0   ahe         18.05.01     final version for XC164CS
'
'        1.1   ahe         05.06.02     no changes
'
'              ahe         06.08.02     dead time generation must disabled
'                                       if hall sensor mode is enabled
'        1.2   ste         18.12.02     stelling correction
'                                       final version for XC167CI

'        ---------------------------------------------------------------------
'        2.0               26.08.04    final version for XC164CM Pegasus light
'
'*****************************************************************************


'*****************************************************************************
'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: Mode
    '-------------------------------------------------------------------------
    If (Not OnLoadPageMode(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: OnLoadPageModulationControlForPinx
    '-------------------------------------------------------------------------
    If (Not OnLoadPageModulationControlForPinx(ps, "CC")) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: OnLoadPageModulationControlForPinx
    '-------------------------------------------------------------------------
    If (Not OnLoadPageModulationControlForPinx(ps, "COUT")) Then Exit Function

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

    '-------------------------------------------------------------------------
    ' end of pages
    '-------------------------------------------------------------------------
    
    '-------------------------------------------------------------------------
    ' call function to initialize the menu
    '-------------------------------------------------------------------------
    If (Not InitMenu(ps, "CC6\CC6_CHANNEL_012")) 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: Mode
    '-------------------------------------------------------------------------
    If (Not OnChangingPageMode(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: OnChangingPageModulationControlForPinx
    '-------------------------------------------------------------------------
    If (Not OnChangingPageModulationControlForPinx(ps, Pagename, "CC")) Then Exit Function

    '-------------------------------------------------------------------------
    'page: OnChangingPageModulationControlForPinx
    '-------------------------------------------------------------------------
    If (Not OnChangingPageModulationControlForPinx(ps, Pagename, "COUT")) Then Exit Function

    '-------------------------------------------------------------------------
    'page: OnChangingPageControl
    '-------------------------------------------------------------------------
    If (Not OnChangingPageControl(ps, Pagename)) 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: Mode
    '-------------------------------------------------------------------------
    If (Not OnShowPageMode(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: OnShowPageModulationControlForPinx
    '-------------------------------------------------------------------------
    If (Not OnShowPageModulationControlForPinx(ps, Controlname, Pagename, v, "CC")) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: OnShowPageModulationControlForPinx
    '-------------------------------------------------------------------------
    If (Not OnShowPageModulationControlForPinx(ps, Controlname, Pagename, v, "COUT")) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: OnShowPageControl
    '-------------------------------------------------------------------------
    If (Not OnShowPageControl(ps, Controlname, Pagename, 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

  

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

  OnLoadPageMode = False
  Dim vIndex As Variant
  Dim iChannel As Integer

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

  If (Not ps.AddPage("Mode Selection")) Then Exit Function

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

  OnChangingPageMode = False
  Dim vIndex As Variant
  Dim iChannel As Integer
  Dim iTmr As Integer
  Dim iChannel_for_CC2 As Integer
  Dim sVarPre As String
  Dim sRegPre As String
  Dim i As Integer

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

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

  If (iChannel = 0 Or iChannel = 1 Or iChannel = 2) Then
      iTmr = 12
  End If
  If (iChannel = 3) Then
      iTmr = 13
  End If
  i = 0
  
  If (Not ps.ExtenderCollection("Mode Selection").Loaded) And (Pagename = "Mode Selection") Then
    ps.ExtenderCollection("Mode Selection").Loaded = True
  

    '-------------------------------
    ' frame: frmCCMODx
    '-------------------------------
    If (Not ps.AddFrame("frmMSEL6" & iChannel, 100, 100, 8475, 5200, _
        "Mode Selection for Capture / Compare Channel " & iChannel & _
        " (MSEL6" & iChannel & ")")) Then Exit Function

        If (Not ps.AddOption("optMSEL6" & iChannel & "_" & i, 200, 250 + i * 320, 8000, 380, _
            "Disable capture and compare modes")) Then Exit Function
        i = i + 1

        If (Not ps.AddOption("optMSEL6" & iChannel & "_" & i, 200, 250 + i * 320, 8000, 380, _
            "Compare mode 1 (use pin CC6" & iChannel & " as output)")) Then Exit Function
        i = i + 1

        If (Not ps.AddOption("optMSEL6" & iChannel & "_" & i, 200, 250 + i * 320, 8000, 380, _
            "Compare mode 2 (use pin COUT6" & iChannel & " as output)")) Then Exit Function
        i = i + 1

        If (Not ps.AddOption("optMSEL6" & iChannel & "_" & i, 200, 250 + i * 320, 8000, 380, _
            "Compare mode 3 (use pins CC6" & iChannel & " and COUT6" & iChannel & " as output)")) Then Exit Function
        i = i + 1

        If (Not ps.AddOption("optMSEL6" & iChannel & "_" & i, 200, 250 + i * 320, 8000, 380, _
            "Double register capture mode 1 (use pin CC6" & iChannel & " as input)")) Then Exit Function
        i = i + 1

        If (Not ps.AddOption("optMSEL6" & iChannel & "_" & i, 200, 250 + i * 320, 8000, 380, _
            "Double register capture mode 2 (use pin CC6" & iChannel & " as input)")) Then Exit Function
        i = i + 1

        If (Not ps.AddOption("optMSEL6" & iChannel & "_" & i, 200, 250 + i * 320, 8000, 380, _
            "Double register capture mode 3 (use pin CC6" & iChannel & " as input)")) Then Exit Function
        i = i + 1

        If (Not ps.AddOption("optMSEL6" & iChannel & "_" & i, 200, 250 + i * 320, 8000, 380, _
            "Double register capture mode 4 (use pin CC6" & iChannel & " as input)")) Then Exit Function
        i = i + 1

        If (Not ps.AddOption("optMSEL6" & iChannel & "_" & i, 200, 250 + i * 320, 8000, 380, _
            "Hall sensor mode (use pin #CCPOS" & iChannel & " as input)")) Then Exit Function
        i = i + 1

        If (Not ps.AddOption("optMSEL6" & iChannel & "_" & i, 200, 250 + i * 320, 8000, 380, _
            "Hysteresis like control mode with dead time generation (use pin #CCPOS" & iChannel & " as input)")) Then Exit Function
        i = i + 1

        If (Not ps.AddOption("optMSEL6" & iChannel & "_" & i, 200, 250 + i * 320, 8000, 380, _
            "Multi input capture mode 1 (use pins CC6" & iChannel & " and #CCPOS" & iChannel & " as input)")) Then Exit Function
        i = i + 1

        If (Not ps.AddOption("optMSEL6" & iChannel & "_" & i, 200, 250 + i * 320, 8000, 380, _
            "Multi input capture mode 2 (use pins CC6" & iChannel & " and #CCPOS" & iChannel & " as input)")) Then Exit Function
        i = i + 1

        If (Not ps.AddOption("optMSEL6" & iChannel & "_" & i, 200, 250 + i * 320, 8000, 380, _
            "Multi input capture mode 3 (use pins CC6" & iChannel & " and #CCPOS" & iChannel & " as input)")) Then Exit Function
        i = i + 1

        If (Not ps.AddOption("optMSEL6" & iChannel & "_" & i, 200, 250 + i * 320, 8000, 380, _
            "Multi input capture mode 4 (use pins CC6" & iChannel & " and #CCPOS" & iChannel & " as input)")) Then Exit Function
        i = i + 1

        If (Not ps.AddOption("optMSEL6" & iChannel & "_" & i, 200, 250 + i * 320, 8000, 380, _
            "Multi input capture mode 5 (use pins CC6" & iChannel & " and #CCPOS" & iChannel & " as input)")) Then Exit Function
        i = i + 1


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

  OnShowPageMode = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim vIndex As Variant
  Dim iChannel As Integer
  Dim iTmr_12 As Integer
  Dim iTmr_13 As Integer
  Dim bDisabled As Boolean
  Dim lRegPre As Long
  Dim sRegPre As String
  Dim sVarPre As String
  Dim sDisabledTooltip As String
  Dim sCCx As String
  Dim iChannel_for_CC2 As Integer
  Dim i As Integer

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

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

  lRegPre = iChannel \ 4
  sCCx = sRegPre & "M" & lRegPre & "_"

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

  If (Pagename = "Mode Selection") Then
    '-------------------------------------------------------------------------
    ' page: Channel (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)

      Case Else
    End Select

    For i = 0 To 14
        If (Controlname = "optMSEL6" & iChannel & "_" & i) Then
            Call SelectModeForCC6Channelx(r, vIndex, iChannel, i)
        End If
    Next i

    '-------------------------------------------------------------------------
    ' control: optMSEL6" & iChannel & "_" & i (show)
    '-------------------------------------------------------------------------
    i = 0
    With c("optMSEL6" & iChannel & "_" & i)
        bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                     IsHallSensorModeEnable(r, vIndex))
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = i)
    End With
   
    With e("optMSEL6" & iChannel & "_" & i)
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleClockDisabled(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            GetTooltipModuleClockDisabled(r, vIndex)
        End If
        If (IsHallSensorModeEnable(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledTooltip("hall sensor mode is selected. This mode can deselected on the 'Multi Channel'-page")
        End If
      End If
    End With
   
    '-------------------------------------------------------------------------
    ' control: optMSEL6" & iChannel & "_" & i (show)
    '-------------------------------------------------------------------------
    i = 1
    With c("optMSEL6" & iChannel & "_" & i)
        bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                     IsHallSensorModeEnable(r, vIndex) Or _
                     Not (GetPinFunction(r, sVarPre & "_CC6" & iChannel & "_O") = 2))
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = i)
    End With
   
    With e("optMSEL6" & iChannel & "_" & i)
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleClockDisabled(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            GetTooltipModuleClockDisabled(r, vIndex)
        End If
        If (IsHallSensorModeEnable(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledTooltip("hall sensor mode is selected. This mode can deselected on the 'Multi Channel'-page")
        End If
        If (Not (GetPinFunction(r, sVarPre & "_CC6" & iChannel & "_O") = 2)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledTooltip("pin CC6" & iChannel & " is not used als output")
        End If
      End If
    End With
   
    '-------------------------------------------------------------------------
    ' control: optMSEL6" & iChannel & "_" & i (show)
    '-------------------------------------------------------------------------
    i = 2
    With c("optMSEL6" & iChannel & "_" & i)
        bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                     IsHallSensorModeEnable(r, vIndex) Or _
                     Not (GetPinFunction(r, sVarPre & "_COUT6" & iChannel & "_O") = 2))
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = i)
    End With
   
    With e("optMSEL6" & iChannel & "_" & i)
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleClockDisabled(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            GetTooltipModuleClockDisabled(r, vIndex)
        End If
        If (IsHallSensorModeEnable(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledTooltip("hall sensor mode is selected. This mode can deselected on the 'Multi Channel'-page")
        End If
        If (Not (GetPinFunction(r, sVarPre & "_COUT6" & iChannel & "_O") = 2)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledTooltip("pin COUT6" & iChannel & " is not used als output")
        End If
      End If
    End With
   
    '-------------------------------------------------------------------------
    ' control: optMSEL6" & iChannel & "_" & i (show)
    '-------------------------------------------------------------------------
    i = 3
    With c("optMSEL6" & iChannel & "_" & i)
        bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                     IsHallSensorModeEnable(r, vIndex) Or _
                     Not (GetPinFunction(r, sVarPre & "_CC6" & iChannel & "_O") = 2) Or _
                     Not (GetPinFunction(r, sVarPre & "_COUT6" & iChannel & "_O") = 2))
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = i)
    End With
   
    With e("optMSEL6" & iChannel & "_" & i)
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleClockDisabled(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            GetTooltipModuleClockDisabled(r, vIndex)
        End If
        If (IsHallSensorModeEnable(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledTooltip("hall sensor mode is selected. This mode can deselected on the 'Multi Channel'-page")
        End If
        If (Not (GetPinFunction(r, sVarPre & "_CC6" & iChannel & "_O") = 2)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledTooltip("pin CC6" & iChannel & " is not used als output")
        End If
        If (Not (GetPinFunction(r, sVarPre & "_COUT6" & iChannel & "_O") = 2)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledTooltip("pin COUT6" & iChannel & " is not used als output")
        End If
      End If
    End With
   
    '-------------------------------------------------------------------------
    ' control: optMSEL6" & iChannel & "_" & i (show)
    '-------------------------------------------------------------------------
    i = 4
    With c("optMSEL6" & iChannel & "_" & i)
        bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                     IsHallSensorModeEnable(r, vIndex) Or _
                     Not (GetPinFunction(r, sVarPre & "_CC6" & iChannel & "_I") = 1))
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = i)
    End With
   
    With e("optMSEL6" & iChannel & "_" & i)
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleClockDisabled(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            GetTooltipModuleClockDisabled(r, vIndex)
        End If
        If (IsHallSensorModeEnable(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledTooltip("hall sensor mode is selected. This mode can deselected on the 'Multi Channel'-page")
        End If
        If (Not (GetPinFunction(r, sVarPre & "_CC6" & iChannel & "_I") = 1)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledTooltip("pin CC6" & iChannel & " is not used als input")
        End If
      End If
    End With
   
    '-------------------------------------------------------------------------
    ' control: optMSEL6" & iChannel & "_" & i (show)
    '-------------------------------------------------------------------------
    i = 5
    With c("optMSEL6" & iChannel & "_" & i)
        'bDisabled  i = 4
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = i)
    End With
   
    With e("optMSEL6" & iChannel & "_" & i)
      If (bDisabled) Then
        .DisabledTooltipText = e("optMSEL6" & iChannel & "_4").DisabledTooltipText
      End If
    End With
   
    '-------------------------------------------------------------------------
    ' control: optMSEL6" & iChannel & "_" & i (show)
    '-------------------------------------------------------------------------
    i = 6
    With c("optMSEL6" & iChannel & "_" & i)
        'bDisabled  i = 4
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = i)
    End With
   
    With e("optMSEL6" & iChannel & "_" & i)
      If (bDisabled) Then
        .DisabledTooltipText = e("optMSEL6" & iChannel & "_4").DisabledTooltipText
      End If
    End With
   
    '-------------------------------------------------------------------------
    ' control: optMSEL6" & iChannel & "_" & i (show)
    '-------------------------------------------------------------------------
    i = 7
    With c("optMSEL6" & iChannel & "_" & i)
        'bDisabled  i = 4
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = i)
    End With
   
    With e("optMSEL6" & iChannel & "_" & i)
      If (bDisabled) Then
        .DisabledTooltipText = e("optMSEL6" & iChannel & "_4").DisabledTooltipText
      End If
    End With
   
    '-------------------------------------------------------------------------
    ' control: optMSEL6" & iChannel & "_" & i (show)
    '-------------------------------------------------------------------------
    i = 8
    With c("optMSEL6" & iChannel & "_" & i)
        bDisabled = Not (IsHallSensorModeEnable(r, vIndex))
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = i)
    End With
   
    With e("optMSEL6" & iChannel & "_" & i)
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & _
          FormatDisabledTooltip("this mode can only selected on the page 'Multi Channel'")
      End If
    End With
   
    '-------------------------------------------------------------------------
    ' control: optMSEL6" & iChannel & "_" & i (show)
    '-------------------------------------------------------------------------
    i = 9
    With c("optMSEL6" & iChannel & "_" & i)
        bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                     IsHallSensorModeEnable(r, vIndex) Or _
                     Not (GetPinFunction(r, sVarPre & "_CC6POS" & iChannel & "_I") = 1))
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = i)
    End With
   
    With e("optMSEL6" & iChannel & "_" & i)
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleClockDisabled(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            GetTooltipModuleClockDisabled(r, vIndex)
        End If
        If (IsHallSensorModeEnable(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledTooltip("hall sensor mode is selected. This mode can deselected on the 'Multi Channel'-page")
        End If
        If (Not (GetPinFunction(r, sVarPre & "_CC6POS" & iChannel & "_I") = 1)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledTooltip("pin #CC6POS" & iChannel & " is not used als input")
        End If
      End If
    End With
   
    '-------------------------------------------------------------------------
    ' control: optMSEL6" & iChannel & "_" & i (show)
    '-------------------------------------------------------------------------
    i = 10
    With c("optMSEL6" & iChannel & "_" & i)
        bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                     IsHallSensorModeEnable(r, vIndex) Or _
                     Not (GetPinFunction(r, sVarPre & "_CC6" & iChannel & "_I") = 1) Or _
                     Not (GetPinFunction(r, sVarPre & "_CC6POS" & iChannel & "_I") = 1))
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = i)
    End With
   
    With e("optMSEL6" & iChannel & "_" & i)
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleClockDisabled(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            GetTooltipModuleClockDisabled(r, vIndex)
        End If
        If (IsHallSensorModeEnable(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledTooltip("hall sensor mode is selected. This mode can deselected on the 'Multi Channel'-page")
        End If
        If (Not (GetPinFunction(r, sVarPre & "_CC6" & iChannel & "_I") = 1)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledTooltip("pin CC6" & iChannel & " is not used als input")
        End If
        If (Not (GetPinFunction(r, sVarPre & "_CC6POS" & iChannel & "_I") = 1)) Then
          .DisabledTooltipText = .DisabledTooltipText & _
            FormatDisabledTooltip("pin #CC6POS" & iChannel & " is not used als input")
        End If
      End If
    End With
   
    '-------------------------------------------------------------------------
    ' control: optMSEL6" & iChannel & "_" & i (show)
    '-------------------------------------------------------------------------
    i = 11
    With c("optMSEL6" & iChannel & "_" & i)
        'bDisabled  i = 10
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = i)
    End With
   
    With e("optMSEL6" & iChannel & "_" & i)
      If (bDisabled) Then
        .DisabledTooltipText = e("optMSEL6" & iChannel & "_10").DisabledTooltipText
      End If
    End With
   
    '-------------------------------------------------------------------------
    ' control: optMSEL6" & iChannel & "_" & i (show)
    '-------------------------------------------------------------------------
    i = 12
    With c("optMSEL6" & iChannel & "_" & i)
        'bDisabled  i = 10
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = i)
    End With
   
    With e("optMSEL6" & iChannel & "_" & i)
      If (bDisabled) Then
        .DisabledTooltipText = e("optMSEL6" & iChannel & "_10").DisabledTooltipText
      End If
    End With
   
    '-------------------------------------------------------------------------
    ' control: optMSEL6" & iChannel & "_" & i (show)
    '-------------------------------------------------------------------------
    i = 13
    With c("optMSEL6" & iChannel & "_" & i)
        'bDisabled  i = 10
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = i)
    End With
   
    With e("optMSEL6" & iChannel & "_" & i)
      If (bDisabled) Then
        .DisabledTooltipText = e("optMSEL6" & iChannel & "_10").DisabledTooltipText
      End If
    End With
   
    '-------------------------------------------------------------------------
    ' control: optMSEL6" & iChannel & "_" & i (show)
    '-------------------------------------------------------------------------
    i = 14
    With c("optMSEL6" & iChannel & "_" & i)
        'bDisabled  i = 10
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = i)
    End With
   
    With e("optMSEL6" & iChannel & "_" & i)
      If (bDisabled) Then
        .DisabledTooltipText = e("optMSEL6" & iChannel & "_10").DisabledTooltipText
      End If
    End With
   

  End If

  OnShowPageMode = True
  Exit Function

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

  Dim iChannel As Integer

  iChannel = ps.Parameters.v("Channel")

  OnLoadPageModulationControlForPinx = False

  If (Not ps.AddPage("Modulation Control for " & sPin & "6" & iChannel)) Then Exit Function

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

  Dim iChannel As Integer

  iChannel = ps.Parameters.v("Channel")

  OnChangingPageModulationControlForPinx = False
  
  If (Not ps.ExtenderCollection("Modulation Control for " & sPin & "6" & iChannel).Loaded) And _
       (Pagename = "Modulation Control for " & sPin & "6" & iChannel) Then
    ps.ExtenderCollection("Modulation Control for " & sPin & "6" & iChannel).Loaded = True
  

    '-------------------------------
    ' frame: frmT12MODEN_" & sPin & "6x
    '-------------------------------
    If (Not ps.AddFrame("frmT12MODEN_" & sPin & "6x", 100, 100, 4150, 800, _
      "T12 Modulation Control for " & sPin & "6" & iChannel)) Then Exit Function
        If (Not ps.AddCheck("chkT12MODEN_" & sPin & "6x", 200, 250, 3750, 380, _
          "Enable T12 modulation for " & sPin & "6" & iChannel & " (T12MODEN)")) Then Exit Function

    '-------------------------------
    ' frame: frmT13MODEN_" & sPin & "6x
    '-------------------------------
    If (Not ps.AddFrame("frmT13MODEN_" & sPin & "6x", 4400, 100, 4150, 800, _
        "T13 Modulation Control for " & sPin & "6" & iChannel)) Then Exit Function
        If (Not ps.AddCheck("chkT13MODEN_" & sPin & "6x", 200, 250, 3900, 380, _
            "Enable T13 modulation for " & sPin & "6" & iChannel & " (T13MODEN)")) Then Exit Function

    '-------------------------------
    ' frame: frm" & sPin & "6xPS
    '-------------------------------
    If (Not ps.AddFrame("frm" & sPin & "6xPS", 100, 950, 4150, 1300, _
      "Passive State Select (" & sPin & "6" & iChannel & "PS)")) Then Exit Function
        If (Not ps.AddOption("opt" & sPin & "6xPS_0", 200, 250, 3900, 380, _
           "The compare output " & sPin & "6" & iChannel & " drives passive level while CC6" & iChannel & _
           "ST is '0'")) Then Exit Function
        If (Not ps.AddOption("opt" & sPin & "6xPS_1", 200, 750, 3900, 380, _
           "The compare output " & sPin & "6" & iChannel & " drives passive level while CC6" & iChannel & _
           "ST is '1'")) Then Exit Function

    '-------------------------------
    ' frame: frmMCPMS_" & sPin & "6x
    '-------------------------------
    If (Not ps.AddFrame("frmMCMPS_" & sPin & "6x", 4400, 950, 4150, 1300, _
      "Multi-Channel Control for " & sPin & "6" & iChannel & " (MCMPS)")) Then Exit Function
        If (Not ps.AddOption("optMCMPS_0_" & sPin & "6x", 200, 250, 3900, 380, _
          "Set the " & sPin & "6" & iChannel & " output to the passive state")) Then Exit Function
        If (Not ps.AddOption("optMCMPS_1_" & sPin & "6x", 200, 750, 3900, 380, _
          "The " & sPin & "6" & iChannel & " output can deliver the PWM generated by T12 or T13")) Then Exit Function

    '-------------------------------
    ' frame: frmTRPENx_" & sPin & "6x
    '-------------------------------
    If (Not ps.AddFrame("frmTRPENx_" & sPin & "6x", 100, 2300, 4150, 1300, _
      "Trap Control for " & sPin & "6" & iChannel)) Then Exit Function
        If (Not ps.AddCheck("chkTRPENx_" & sPin & "6x", 200, 450, 3825, 380, _
          "Enable the trap functionality of the output pin " & sPin & "6" & iChannel & " (TRPEN)")) Then Exit Function

    '-------------------------------
    ' frame: frmPSLx_" & sPin & "6x
    '-------------------------------
    If (Not ps.AddFrame("frmPSLx_" & sPin & "6x", 4400, 2300, 4150, 1300, _
      "Compare Output Control for " & sPin & "6" & iChannel & " (PSL)")) Then Exit Function
        If (Not ps.AddOption("optPSLx_0_" & sPin & "6x", 200, 250, 3900, 380, _
          "The passive level of " & sPin & "6" & iChannel & " output is '0'")) Then Exit Function
        If (Not ps.AddOption("optPSLx_1_" & sPin & "6x", 200, 750, 3900, 380, _
          "The passive level of " & sPin & "6" & iChannel & " output is '1'")) Then Exit Function

  End If
  OnChangingPageModulationControlForPinx = 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 OnShowPageModulationControlForPinx(ps As Object, Controlname As String, Pagename As String, v() As Variant, sPin As String) As Boolean
  On Error GoTo OnShowPageModulationControlForPinxError

  OnShowPageModulationControlForPinx = False

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


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

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

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

  If (Pagename = "Modulation Control for " & sPin & "6" & iChannel) Then
    '-------------------------------------------------------------------------
    ' page: ModulationControlForPinx (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: chkT12MODEN_" & sPin & "6x (action)
        '---------------------------------------------------------------------
        Case "chkT12MODEN_" & sPin & "6x"
            r.v(sRegPre & "T12MODEN_" & sPin & "6" & iChannel) = v(1)
            Call LoadT12MODENValue(r, vIndex)

        '---------------------------------------------------------------------
        ' control: opt" & sPin & "6xPS_0 (action)
        '---------------------------------------------------------------------
        Case "opt" & sPin & "6xPS_0"
            r.v(sRegPre & "CMPSTAT_" & sPin & "6" & iChannel & "PS") = 0

        '---------------------------------------------------------------------
        ' control: opt" & sPin & "6xPS_1 (action)
        '---------------------------------------------------------------------
        Case "opt" & sPin & "6xPS_1"
            r.v(sRegPre & "CMPSTAT_" & sPin & "6" & iChannel & "PS") = 1

        '---------------------------------------------------------------------
        ' control: chkT13MODEN_" & sPin & "6x (action)
        '---------------------------------------------------------------------
        Case "chkT13MODEN_" & sPin & "6x"
            r.v(sRegPre & "T13MODEN_" & sPin & "6" & iChannel) = v(1)
            Call LoadT13MODENValue(r, vIndex)

        '---------------------------------------------------------------------
        ' control: optMCMPS_0_" & sPin & "6x (action)
        '---------------------------------------------------------------------
        Case "optMCMPS_0_" & sPin & "6x"
            r.v(sRegPre & "MCMPS_" & sPin & "6" & iChannel) = 0
            Call LoadMCMPSValue(r, vIndex)

        '---------------------------------------------------------------------
        ' control: optMCMPS_1_" & sPin & "6x (action)
        '---------------------------------------------------------------------
        Case "optMCMPS_1_" & sPin & "6x"
            r.v(sRegPre & "MCMPS_" & sPin & "6" & iChannel) = 1
            Call LoadMCMPSValue(r, vIndex)

        '---------------------------------------------------------------------
        ' control: chkTRPENx_" & sPin & "6x (action)
        '---------------------------------------------------------------------
        Case "chkTRPENx_" & sPin & "6x"
            r.v(sRegPre & "TRPEN_" & sPin & "6" & iChannel) = v(1)
            Call LoadTRPENValue(r, vIndex)

        '---------------------------------------------------------------------
        ' control: optPSLx_0_" & sPin & "6x (action)
        '---------------------------------------------------------------------
        Case "optPSLx_0_" & sPin & "6x"
            r.v(sRegPre & "PSL_" & sPin & "6" & iChannel) = 0
            Call LoadPSLValue(r, vIndex)

        '---------------------------------------------------------------------
        ' control: optPSLx_1_" & sPin & "6x (action)
        '---------------------------------------------------------------------
        Case "optPSLx_1_" & sPin & "6x"
            r.v(sRegPre & "PSL_" & sPin & "6" & iChannel) = 1
            Call LoadPSLValue(r, vIndex)

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: ModulationControlForPinx (show)
    '-------------------------------------------------------------------------
    bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
      Not (GetPinFunction(r, sVarPre & "_" & sPin & "6" & iChannel & "_O") = 2))
    
    sDisabledTooltip = ""
    sDisabledTooltip = TOOLTIP_DISABLED_IF
    
    If (IsModuleClockDisabled(r, vIndex)) Then
        sDisabledTooltip = sDisabledTooltip & GetTooltipModuleClockDisabled(r, vIndex)
    End If
    If (Not (GetPinFunction(r, sVarPre & "_" & sPin & "6" & iChannel & "_O") = 2)) Then
        sDisabledTooltip = sDisabledTooltip & FormatDisabledTooltip _
          ("pin " & sPin & "6" & iChannel & " is not used as output")
    End If
    
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmT13MODEN_" & sPin & "6x").Caption, c, e, bDisabled, sDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmTRPENx_" & sPin & "6x").Caption, c, e, bDisabled, sDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmPSLx_" & sPin & "6x").Caption, c, e, bDisabled, sDisabledTooltip, "")

    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
      Not (GetPinFunction(r, sVarPre & "_" & sPin & "6" & iChannel & "_O") = 2) Or _
      r.v(sRegPre & "MODCTR_MCMEN") = 0)
    
    sDisabledTooltip = ""
    sDisabledTooltip = TOOLTIP_DISABLED_IF
    
    If (IsModuleClockDisabled(r, vIndex)) Then
        sDisabledTooltip = sDisabledTooltip & GetTooltipModuleClockDisabled(r, vIndex)
    End If
    If (Not (GetPinFunction(r, sVarPre & "_" & sPin & "6" & iChannel & "_O") = 2)) Then
        sDisabledTooltip = sDisabledTooltip & FormatDisabledTooltip _
          ("pin " & sPin & "6" & iChannel & " is not used as output")
    End If
    If (r.v(sRegPre & "MODCTR_MCMEN") = 0) Then
        sDisabledTooltip = sDisabledTooltip & FormatDisabledTooltip("multi channel mode is not enabled")
    End If
    
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmMCMPS_" & sPin & "6x").Caption, c, e, bDisabled, sDisabledTooltip, "")

    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
      Not (GetPinFunction(r, sVarPre & "_" & sPin & "6" & iChannel & "_O") = 2) Or _
      r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = 0 Or _
      IsHallSensorModeEnable(r, vIndex))
    
    sDisabledTooltip = ""
    sDisabledTooltip = TOOLTIP_DISABLED_IF
    
    If (IsModuleClockDisabled(r, vIndex)) Then
        sDisabledTooltip = sDisabledTooltip & GetTooltipModuleClockDisabled(r, vIndex)
    End If
    If (Not (GetPinFunction(r, sVarPre & "_" & sPin & "6" & iChannel & "_O") = 2)) Then
        sDisabledTooltip = sDisabledTooltip & FormatDisabledTooltip _
          ("pin " & sPin & "6" & iChannel & " is not used as output")
    End If
    If (r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = 0) Then
        sDisabledTooltip = sDisabledTooltip & FormatDisabledTooltip _
          ("capture/compare mode of channel " & iChannel & " is disabled")
    End If
    If (IsHallSensorModeEnable(r, vIndex)) Then
        sDisabledTooltip = sDisabledTooltip & FormatDisabledTooltip _
          ("hall sensor mode is enabled")
    End If
    
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmT12MODEN_" & sPin & "6x").Caption, c, e, bDisabled, sDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frm" & sPin & "6xPS").Caption, c, e, bDisabled, sDisabledTooltip, "")

    '-------------------------------------------------------------------------
    ' control: chkT12MODEN_" & sPin & "6x (show)
    '-------------------------------------------------------------------------
    With c("chkT12MODEN_" & sPin & "6x")
        .Value = -CInt(r.v(sRegPre & "T12MODEN_" & sPin & "6" & iChannel) = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: opt" & sPin & "6xPS_0 (show)
    '-------------------------------------------------------------------------
    With c("opt" & sPin & "6xPS_0")
        .Value = -CInt(r.v(sRegPre & "CMPSTAT_" & sPin & "6" & iChannel & "PS") = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: opt" & sPin & "6xPS_1 (show)
    '-------------------------------------------------------------------------
    With c("opt" & sPin & "6xPS_1")
        .Value = -CInt(r.v(sRegPre & "CMPSTAT_" & sPin & "6" & iChannel & "PS") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkT13MODEN_" & sPin & "6x (show)
    '-------------------------------------------------------------------------
    With c("chkT13MODEN_" & sPin & "6x")
        .Value = -CInt(r.v(sRegPre & "T13MODEN_" & sPin & "6" & iChannel) = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: optMCMPS_0_" & sPin & "6x (show)
    '-------------------------------------------------------------------------
    With c("optMCMPS_0_" & sPin & "6x")
        .Value = -CInt(r.v(sRegPre & "MCMPS_" & sPin & "6" & iChannel) = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: optMCMPS_1_" & sPin & "6x (show)
    '-------------------------------------------------------------------------
    With c("optMCMPS_1_" & sPin & "6x")
        .Value = -CInt(r.v(sRegPre & "MCMPS_" & sPin & "6" & iChannel) = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkTRPENx_" & sPin & "6x (show)
    '-------------------------------------------------------------------------
    With c("chkTRPENx_" & sPin & "6x")
        .Value = -CInt(r.v(sRegPre & "TRPEN_" & sPin & "6" & iChannel) = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: optPSLx_0_" & sPin & "6x (show)
    '-------------------------------------------------------------------------
    With c("optPSLx_0_" & sPin & "6x")
        .Value = -CInt(r.v(sRegPre & "PSL_" & sPin & "6" & iChannel) = 0)
    End With

    '-------------------------------------------------------------------------
    ' control: optPSLx_1_" & sPin & "6x (show)
    '-------------------------------------------------------------------------
    With c("optPSLx_1_" & sPin & "6x")
        .Value = -CInt(r.v(sRegPre & "PSL_" & sPin & "6" & iChannel) = 1)
    End With

  End If

  OnShowPageModulationControlForPinx = True
  Exit Function

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

  OnLoadPageControl = False

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

  OnLoadPageControl = 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 OnChangingPageControl(ps As Object, Pagename As String) As Boolean
  On Error Resume Next
  Dim iChannel As Integer

  iChannel = ps.Parameters.v("Channel")

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

    '-------------------------------
    ' frame: frmDTEx
    '-------------------------------
    If (Not ps.AddFrame("frmDTEx", 100, 100, 4150, 1800, _
      "Dead Time Control")) Then Exit Function
        If (Not ps.AddCheck("chkDTEx", 200, 750, 3350, 380, _
          "Enable dead time generation (DTE" & iChannel & ")")) Then Exit Function

    '-------------------------------
    ' frame: frmCC6xSR
    '-------------------------------
    If (Not ps.AddFrame("frmCC6xSR", 4400, 100, 4150, 1800, "Duty Cycle")) Then Exit Function
        If (Not ps.AddLabel("lblReq", 0, 275, 350, 1750, 300, "Required duty cycle [%]")) Then Exit Function
        If (Not ps.AddText("txtReq", 2650, 300, 975, 315)) Then Exit Function

        If (Not ps.AddLabel("lblReal", 0, 275, 850, 1775, 300, "Real duty cycle [%]")) Then Exit Function
        If (Not ps.AddLabel("txtReal", 1, 2650, 800, 975, 315, "50")) Then Exit Function

        If (Not ps.AddLabel("lblCC6xSR", 0, 275, 1275, 1575, 400, "Compare register (CCU6_CC6" & iChannel & "SR)")) Then Exit Function
        If (Not ps.AddText("txtCC6xSR", 2650, 1300, 975, 315)) Then Exit Function

    '-------------------------------
    ' frame: frmIC
    '-------------------------------
    If (Not ps.AddFrame("frmIC", 100, 1950, 8450, 1475, "Interrupt Control")) Then Exit Function
        If (Not ps.AddCheck("chkENCC6xR", 200, 300, 7550, 400, _
          "Generate interrupt in compare mode if a compare match has been detected while T12 is counting up, or in capture mode if a rising edge has been detected at the pin CC6" & iChannel & " (ENCC6" & iChannel & "R)")) Then Exit Function
        If (Not ps.AddCheck("chkENCC6xF", 200, 900, 7750, 400, _
          "Generate interrupt in compare mode if a compare match has been detected while T12 is counting down, or in capture mode if a falling edge has been detected at the pin CC6" & iChannel & " (ENCC6" & iChannel & "F)")) Then Exit Function
 
 
 
  End If
  OnChangingPageControl = 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 OnShowPageControl(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageControlError

  OnShowPageControl = False

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

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

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

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

  If (Pagename = "Control") Then
    '-------------------------------------------------------------------------
    ' page: Control (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: chkDTEx (action)
        '---------------------------------------------------------------------
        Case "chkDTEx"
            r.v(sRegPre & "T12DTC_DTE" & iChannel) = v(1)

        '---------------------------------------------------------------------
        ' control: txt0 (action)
        '---------------------------------------------------------------------
        Case "txtReq"
            If (IsInputFormatOK(v(1), "F", c("lblReq").Caption, 0, 100)) Then
                r.v(sVarPre & "_REQ_DUTY_CYCLE_" & iChannel) = v(1)
                Call UpdateDutyCycle(r, vIndex, iChannel)
            Else
                Exit Function
            End If

        '---------------------------------------------------------------------
        ' control: txtCC6xSR (action)
        '---------------------------------------------------------------------
        Case "txtCC6xSR"
            If (IsInputFormatOK(v(1), "H4", c("lblCC6xSR").Caption, 0, 65535)) Then
                r.sfr(sRegPre & "CC6" & iChannel & "SR") = v(1)
                r.v(sVarPre & "_REQ_DUTY_CYCLE_" & iChannel) = _
                GetRealDutyCecle(r, vIndex, iChannel)
            Else
                Exit Function
            End If


        '---------------------------------------------------------------------
        ' control: chkENCC6xR (action)
        '---------------------------------------------------------------------
        Case "chkENCC6xR"
            r.v(sRegPre & "IEN_ENCC6" & iChannel & "R") = v(1)

        '---------------------------------------------------------------------
        ' control: chkENCC6xF (action)
        '---------------------------------------------------------------------
        Case "chkENCC6xF"
            r.v(sRegPre & "IEN_ENCC6" & iChannel & "F") = v(1)


      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: Control (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("frmIC").Caption, c, e, bDisabled, sDisabledTooltip, "")
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmCC6xSR").Caption, c, e, bDisabled, sDisabledTooltip, "")

    bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
      r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = 0 Or _
      IsHallSensorModeEnable(r, vIndex) = True)
    
    sDisabledTooltip = ""
    sDisabledTooltip = TOOLTIP_DISABLED_IF
    
    If (IsModuleClockDisabled(r, vIndex)) Then
        sDisabledTooltip = sDisabledTooltip & GetTooltipModuleClockDisabled(r, vIndex)
    End If
    If (r.v(sRegPre & "T12MSEL_MSEL6" & iChannel) = 0) Then
        sDisabledTooltip = sDisabledTooltip & FormatDisabledTooltip _
          ("capture/compare mode of channel " & iChannel & " is disabled")
    End If
    If (IsHallSensorModeEnable(r, vIndex) = True) Then
        sDisabledTooltip = sDisabledTooltip & FormatDisabledTooltip _
          ("hall sensor mode is enabled")
    End If


    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmDTEx").Caption, c, e, bDisabled, sDisabledTooltip, "")
    '-------------------------------------------------------------------------
    ' control: chkDTEx (show)
    '-------------------------------------------------------------------------
    With c("chkDTEx")
        .Value = -CInt(r.v(sRegPre & "T12DTC_DTE" & iChannel) = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: lblReq (show)
    '-------------------------------------------------------------------------
    With c("lblReq")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: lblReq
    End With

    '-------------------------------------------------------------------------
    ' control: txt0 (show)
    '-------------------------------------------------------------------------
    With c("txtReq")
        If (IsModuleClockDisabled(r, vIndex)) Then
            .Text = CALCULATION_NOT_POSSIBLE
        Else
            .Text = Format(r.v(sVarPre & "_REQ_DUTY_CYCLE_" & iChannel), "0.00")
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblReal (show)
    '-------------------------------------------------------------------------
    With c("lblReal")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: lblReal
    End With

    '-------------------------------------------------------------------------
    ' control: lblCC6xSR (show)
    '-------------------------------------------------------------------------
    With c("lblCC6xSR")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: lblCC6xSR
    End With

    '-------------------------------------------------------------------------
    ' control: txtCC6xSR (show)
    '-------------------------------------------------------------------------
    With c("txtCC6xSR")
        If (IsModuleClockDisabled(r, vIndex)) Then
            .Text = CALCULATION_NOT_POSSIBLE
        Else
            .Text = FormatTextOutput(r.sfr(sRegPre & "CC6" & iChannel & "SR"), "H4")
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: txtReal (show)
    '-------------------------------------------------------------------------
    With c("txtReal")
        If (IsModuleClockDisabled(r, vIndex)) Then
            .Caption = CALCULATION_NOT_POSSIBLE
        Else
            .Caption = Format(GetRealDutyCecle(r, vIndex, iChannel), "0.00")
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkENCC6xR (show)
    '-------------------------------------------------------------------------
    With c("chkENCC6xR")
        .Value = -CInt(r.v(sRegPre & "IEN_ENCC6" & iChannel & "R") = 1)
    End With

    '-------------------------------------------------------------------------
    ' control: chkENCC6xF (show)
    '-------------------------------------------------------------------------
    With c("chkENCC6xF")
        .Value = -CInt(r.v(sRegPre & "IEN_ENCC6" & iChannel & "F") = 1)
    End With

  End If

  OnShowPageControl = True
  Exit Function

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

