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

Option Explicit

'*****************************************************************************
' Module:
'        ADC
'-----------------------------------------------------------------------------
' Description:
'        This module contains all functions that are used in the
'        ADC dialog script and in the ADC codegenerator script.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ----------------------------------------------------------------------
'        0.1  sheshadri    03.12.04     initial version for XC866
'        0.2  Radhish      31-12-04     Code for resetting of enable ADC interrupt is added
'        0.3  Sunil        24-01-05     Function "GetAdcConversionTime" chaged.
'                                       n value is changed from 0 or 1 to 8 or 10.
'
'
'*****************************************************************************

'*****************************************************************************
' Constants
'*****************************************************************************
Global Const ADC_PRECISION = "0.000"
Global Const Max_fADCI = 40

' tooltip constants
Global Const TOOLTIP_ADC_MODULECLK_DISABLED = "the ADC module clock is disabled"
Global Const TOOLTIP_ADC_MODULECLK_HIGH = "the ADC module clock is toohigh"
Global Const TOOLTIP_ADC_ARBSLOT_DISABLED = "the arbitration slot is not enabled"
Global Const TOOLTIP_ADC_ARBSLOT0_DISABLED = "the arbitration slot 0 is not enabled"
Global Const TOOLTIP_ADC_ARBSLOT1_DISABLED = "the arbitration slot 1 is not enabled"
Global Const TOOLTIP_ADC_GATING_0 = "the gating line is permanently 0(switch off)"
Global Const TOOLTIP_ADC_SEQPAR_DISABLED = "the sequential or parallel source not enabled"
Global Const TOOLTIP_ADC_RES_INTR_DISABLED = "the result register interrupt is not enabled"
Global Const TOOLTIP_ADC_EXTR_TRG_DISABLED = "the external trigger is not enabled"
Global Const TOOLTIP_ADC_CC6_DISABLED = "the external trigger source from CCU6 is not initialized"
Global Const TOOLTIP_ADC_SRCINTR_DISABLED = "the source interrupt is not enabled"
Global Const TOOLTIP_ADC_T2CCU_DISABLED = "the external trigger source from T2CCU is not initialized"
'*****************************************************************************
'Description:
'        For each function which should be used for this module a line
'        "If (Not func.AddFunction .." must be insert in this function.
'        For each parameter that should be used for this function a
'        line "If (Not func.AddParameter .." must be insert in this function.
'
'        Note:
'        For each added function a project variable with the name
'        "ADC_NAME_Functionname" must be exist in the *.vars file.
'-----------------------------------------------------------------------------
'Parameters:
'        func             reference to the FunctionClass object
'        r                reference to the Registers object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Public Function RefreshFunctionDescriptions(func As FunctionClass, r As ProjectData) As Boolean
  On Error Resume Next

  Dim sDescription As String
  Dim sReturnValue As String
  Dim sChannelList As String
  Dim iChannel     As Integer
  Dim sFctName     As String
  
  RefreshFunctionDescriptions = False

  ' for each function of this module the property AddFunction must be called
  '
  ' AddFunction(sFuncName As String, sFuncType As String, sFuncDescription As String,
  '             sReturnvalue As String, lSort As Long) As Boolean
  '
  ' sFuncName          | String | function name as key (use the name of the variable
  '                               for the function name e.g. SSC_NAME_Init)
  ' sFuncType          | String | type of the function
  ' sFuncDescription   | String | description of the function
  ' sReturnvalue       | String | description of the return value
  ' lSort              | Long   | ' sort of the function (0 => macro, 1 => function, 2 => ISR)

    ' for each parameter of a function the property AddParameter must be called
    '
    'AddParameter(sParName As String, sPar As String, sParType As String, sParDescription As String) As Boolean
    '
    ' sParName         | String | parameter name (key)
    ' sPar             | String | parameter name
    ' sParType         | String | type of the parameter
    ' sParDescription  | String | description of the parameter

  ' Generate name list of the available channel values:
  sChannelList = ""
  For iChannel = 0 To 7
    If (r.v("ADC_USE_CHANNEL_" & iChannel) = 1) Then
        If (iChannel > 0) Then
            sChannelList = sChannelList & ", "
        End If
        sChannelList = sChannelList & r.v("ADC_PARA_CHANNEL_" & iChannel)
    End If
  Next iChannel

  '------------------------------------------------------------------------------------------------
  ' Description for ADC_NAME_Init
  '------------------------------------------------------------------------------------------------
  sDescription = GetGeneralInitDescription("ADC") & vbCrLf & vbCrLf & _
                 "Following SFR fields will be initialized:" & vbCrLf & _
                 "GLOBCTR  - Global Control" & vbCrLf & _
                 "PRAR     - Priority and Arbitration Register" & vbCrLf & _
                 "ETRCR    - External Trigger Control Register" & vbCrLf & _
                 "CHCTRx   - Channel Control Register x" & vbCrLf & _
                 "RCRx     - Result Control Register x"
  sReturnValue = "None"
  If (Not func.AddFunction("ADC_NAME_Init", "void", sDescription, sReturnValue, 1)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_NAME_Isr
  '------------------------------------------------------------------------------------------------
  sDescription = "This is the service routine for the A/D converter interrupt. " & _
                "It is activated by different interrupt sources (Channel Interrupts or Event Interrupts). " & _
                "The user obtains the conversion result by calling the function " & _
                "ADC_uwGetResultDataX(0,1,2,3)" & "." & vbCrLf & _
                TOOLTIP_ISR_USERCODE
  sReturnValue = "none"
  If (Not func.AddFunction("ADC_NAME_Isr", "void", sDescription, sReturnValue, 2)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for ADC_NAME_SeqCEV
  '------------------------------------------------------------------------------------------------
  sFctName = "SeqCEV"
  sDescription = "This function clears EV Bit"
  sReturnValue = "None"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for ADC_NAME_SeqTREV
  '------------------------------------------------------------------------------------------------
  sFctName = "SeqTREV"
  sDescription = "This function trigger software event. If the source waits for a " & _
                 "trigger event, a conversion request is started."
  sReturnValue = "None"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for ADC_NAME_SeqFLUSH
  '------------------------------------------------------------------------------------------------
  sFctName = "SeqFLUSH"
  sDescription = "This function resets all bits V in the queue registers and bit EV." & vbCrLf & _
                 "The queue contains no more valid entry."
  sReturnValue = "None"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for ADC_NAME_SeqCLRV
  '------------------------------------------------------------------------------------------------
  sFctName = "SeqCLRV"
  sDescription = "This function resets bit V in the queue register Q0R0 or QBUR0." & vbCrLf & _
                 "If QBUR0.V = 1, then QBUR0.V is reset." & vbCrLf & _
                 "If QBUR0.V = 0, then Q0R0.V is reset."
  sReturnValue = "None"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for ADC_uwSeqREQCHNR...
  '------------------------------------------------------------------------------------------------
  sFctName = "SeqREQCHNR"
  sDescription = "This function request software controlled conversion for new channel." & vbCrLf
  sReturnValue = "None"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function
                sDescription = "External Trigger : defines external trigger"
                If (Not func.AddParameter("ADC_NAME_" & sFctName & "_Para1", "ubExtTrg", "ubyte", sDescription)) Then Exit Function
            sDescription = "Enable Source Interrupt : defines source interrupt"
            If (Not func.AddParameter("ADC_NAME_" & sFctName & "_Para2", "ubEnIntr", "ubyte", sDescription)) Then Exit Function
        sDescription = "Refill : defines the refill"
        If (Not func.AddParameter("ADC_NAME_" & sFctName & "_Para3", "ubRFill", "ubyte", sDescription)) Then Exit Function
    sDescription = "Name of the Request Channel Number (0 - 7)"
    If (Not func.AddParameter("ADC_NAME_" & sFctName & "_Para4", "ubChannelNum", "ubyte", sDescription)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_bSeqSrcEvent...
  '------------------------------------------------------------------------------------------------
  sFctName = "SeqSrcFillLevel"
  sDescription = "This function checks how many entries are valid in the " & _
                 "sequential-sourced queue." & vbCrLf & _
                 "The possible return values are: " & vbCrLf & _
                 "0 if 1 valid entry in the queue." & vbCrLf & _
                 "1 if 2 valid entry in the queue." & vbCrLf & _
                 "2 if 3 valid entry in the queue." & vbCrLf & _
                 "3 if 4 valid entry in the queue." & vbCrLf & _
                 "4 if The queue is empty, no valid entries are present in the queue."
  sReturnValue = "Filling Level"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for ADC_bSeqSrcEvent...
  '------------------------------------------------------------------------------------------------
  sFctName = "SeqSrcEvent"
  sDescription = "This function checks the Queue Status by reading (EV)"
  sReturnValue = "1 if event has been detected, else 0"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for ADC_bQueueEmpty...
  '------------------------------------------------------------------------------------------------
  sFctName = "SeqSrcQueueEmpty"
  sDescription = "This function checks the sequential source contains valid entries" & _
                 " by reading Queue Status Register (EMPTY)."
  sReturnValue = "1 if queue is empty, else 0"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for ADC_ubGetQueueReqChNum...
  '------------------------------------------------------------------------------------------------
  sFctName = "SeqSrcReqChNum"
  sDescription = "This function reads the Request Channel Number" & _
                 " by reading Queue 0 Register (REQCHNR)."
  sReturnValue = "Request Channel Number"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
        
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_bReqChValid...
  '------------------------------------------------------------------------------------------------
  sFctName = "SeqSrcReqChValid"
  sDescription = "This function checks the data in REQCHNR, RF, TR and ENSI is valid by reading Queue 0 Register (V)." & _
                 " Bit V is set when a valid entry is written to the queue input register QINR0."
  sReturnValue = "1 if data is valid, else 0"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_bQueueExternalTrigger...
  '------------------------------------------------------------------------------------------------
  sFctName = "SeqSrcQueExtTrg"
  sDescription = "This function checks the External Trigger. This bit defines if the" & _
                " conversion request is sensitive to an external trigger event. The event" & _
                " flag (bit EV) indicates if an external event has taken place and a conversion" & _
                " can be requested."
  sReturnValue = "1 if bit EV is used to start conversion request, else 0"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
        
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_NAME_ParLDEV
  '------------------------------------------------------------------------------------------------
  sFctName = "ParLDEV"
  sDescription = "This function generates load event."
  sReturnValue = "None"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function
        
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_NAME_ParCLRPND
  '------------------------------------------------------------------------------------------------
  sFctName = "ParCLRPND"
  sDescription = "This function resets bints in CRPR1 register."
  sReturnValue = "None"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function
        
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_NAME_ParREQCH
  '------------------------------------------------------------------------------------------------
  sFctName = "ParREQCH"
  sDescription = "This function strarts conversion request of analog channel." & _
                 "The possible values for the request channels are: " & vbCrLf & _
                 "Bit 4 = 1   ->  analog channel 4 is requested for conversion " & vbCrLf & _
                 "Bit 5 = 1   ->  analog channel 5 is requested for conversion " & vbCrLf & _
                 "Bit 6 = 1   ->  analog channel 6 is requested for conversion " & vbCrLf & _
                 "Bit 7 = 1   ->  analog channel 7 is requested for conversion "
  sReturnValue = "None"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Name of the Valid Flag Register"
    If (Not func.AddParameter("ADC_NAME_" & sFctName & "_Para1", "ubChannelNum", "ubyte", sDescription)) Then Exit Function
        
        
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_ubGetConvReqPending...
  '------------------------------------------------------------------------------------------------
  sFctName = "ParConvPending"
  sDescription = "This function checks the conversion request pending register." & _
                 "The possible values for the returned channels are: " & vbCrLf & _
                 "Bit 4 = 1   ->  analog channel 4 is requested for conversion " & vbCrLf & _
                 "Bit 5 = 1   ->  analog channel 5 is requested for conversion " & vbCrLf & _
                 "Bit 6 = 1   ->  analog channel 6 is requested for conversion " & vbCrLf & _
                 "Bit 7 = 1   ->  analog channel 7 is requested for conversion "
  sReturnValue = "Returns the Channel Number"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for ADC_NAME_Busy
  '------------------------------------------------------------------------------------------------
  sFctName = "Busy"
  sDescription = "This function checks the conversion state of the current " & _
                "ADC-channel by examination of the busy flag (BUSY). " & _
                "It returns '1' while a conversion is running."
  sReturnValue = "1 if conversion is currently active, else 0"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for ADC_NAME_SamplePhase...
  '------------------------------------------------------------------------------------------------
  sFctName = "SamplePhase"
  sDescription = "This function checks the Sample state of the current" & _
                 " ADC-channel by examination of the sample phase (SAMPLE). " & _
                "It returns '1' while analog part is in sampling phase."
  sReturnValue = "1 if analog part is in the sampling phase, else 0"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
  
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_ubGetConvChNum...
  '------------------------------------------------------------------------------------------------
  sFctName = "GetConvChNum"
  sDescription = "This function checks the Sample state of the current" & _
                 " ADC-channel by reading Channel Number (CHNR)."
  sReturnValue = "analog input channel is currently converted"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
 
      
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_vClearValidFlag...
  '------------------------------------------------------------------------------------------------
  sFctName = "ClrValidFlag"
  sDescription = "This function sets the 'Clear Valid Flag' bit in register VFCR." & _
                 " Which intern clears the corresponding valid flag" & _
                 " in registers RESRx/RESRAx. If a hardware event trigger the setting of a bit VFx and" & _
                 " VFCx = 1, the bit VFx is cleared(software overrules hardware)." & vbCrLf & _
                 " The possible values for the Clear Valid Flag Register are: " & vbCrLf & _
                 "1   ->  Bit VFCR.VFC0 is reset" & vbCrLf & _
                 "2   ->  Bit VFCR.VFC1 is reset" & vbCrLf & _
                 "4   ->  Bit VFCR.VFC2 is reset" & vbCrLf & _
                 "8   ->  Bit VFCR.VFC3 is reset"
  sReturnValue = "None"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Name of the Valid Flag Register"
    If (Not func.AddParameter("ADC_NAME_" & sFctName & "_Para1", "ubRegisterNum", "ubyte", sDescription)) Then Exit Function
        
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_ubGetChInterruptFlag...
  '------------------------------------------------------------------------------------------------
  sFctName = "GetChIntrFlag"
  sDescription = "This function monitors the activated channel interrupt flags" & vbCrLf & _
                 "The possible values for the retuned values are: " & vbCrLf & _
                 "Bit x = 1   ->  A channel interrupt for channel x has occured" & vbCrLf & vbCrLf & _
                 "Example : " & vbCrLf & _
                 "Bit 0 = 1   ->  A channel interrupt for channel 0 has occured" & vbCrLf & _
                 "Bit 1 = 1   ->  A channel interrupt for channel 1 has occured"
  sReturnValue = "Returns Channel Interrupt Flag Status"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
        
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_vSetChInterrupt...
  '------------------------------------------------------------------------------------------------
  sFctName = "SetChIntr"
  sDescription = "This function sets 'Set Interrupt Flag' bit in the channel interrupt set " & _
                "register CHINSR. Which intern sets the corresponding channel interrupt flag in register " & _
                "CHINFR and generates an interrupt pulse" & vbCrLf & _
                "Example: " & vbCrLf & _
                 r.v("ADC_NAME_" & sFctName) & "( 0x03 )" & vbCrLf & _
                 "sets CHINSR.CHINS0 (bit 0) and CHINSR.CHINS1 (bit 1)"
  sReturnValue = "None"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Name of the Channel Interrupt to be set"
    If (Not func.AddParameter("ADC_NAME_" & sFctName & "_Para1", "ubChannelNum", "ubyte", sDescription)) Then Exit Function
        
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_vClearChInterrupt...
  '------------------------------------------------------------------------------------------------
  sFctName = "ClrChIntr"
  sDescription = "This function clears the corresponding channel interrupt flag in register CHINFR." & vbCrLf & _
                "Example: " & vbCrLf & _
                 r.v("ADC_NAME_" & sFctName) & "( 0x03 )" & vbCrLf & _
                 "clears CHINCR.CHINC0 (bit 0) and CHINCR.CHINC1 (bit 1)"
  sReturnValue = "None"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Name of the Channel Interrupt to be cleared"
    If (Not func.AddParameter("ADC_NAME_" & sFctName & "_Para1", "ubChannelNum", "ubyte", sDescription)) Then Exit Function
        
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_ubGetEventInterruptFlag...
  '------------------------------------------------------------------------------------------------
  sFctName = "GetEventIntrFlag"
  sDescription = "This function reads the activated event interupt flags EVINFR"
  sReturnValue = "Bit x = 1 if event interrupt for event x has occured, else 0"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
        
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_vSetEventInterrupt...
  '------------------------------------------------------------------------------------------------
  sFctName = "SetEventIntr"
  sDescription = "This function sets the corresponding channel interrupt flag in register CHINFR and" & _
                " generates an interrupt pulse." & vbCrLf & _
                "Example: " & vbCrLf & _
                 r.v("ADC_NAME_" & sFctName) & "( 0x03 )" & vbCrLf & _
                 "sets EVINSR.EVINS0 (bit 0) and EVINSR.EVINS1 (bit 1)"
  sReturnValue = "None"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Name of the event to set"
    If (Not func.AddParameter("ADC_NAME_" & sFctName & "_Para1", "ubChannelNum", "ubyte", sDescription)) Then Exit Function
        
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_vClearEventInterruptFlag...
  '------------------------------------------------------------------------------------------------
  sFctName = "ClrEventIntrFlag"
  sDescription = "This function clears the corresponding event interrupt flag in register EVINFR." & vbCrLf & _
                "Example: " & vbCrLf & _
                 r.v("ADC_NAME_" & sFctName) & "( 0x03 )" & vbCrLf & _
                 "clears EVINCR.EVINC0 (bit 0) and EVINCR.EVINC1 (bit 1)"
  sReturnValue = "None"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "void", sDescription, sReturnValue, 1)) Then Exit Function
    sDescription = "Name of the event interrupt to be cleared"
    If (Not func.AddParameter("ADC_NAME_" & sFctName & "_Para1", "ubChannelNum", "ubyte", sDescription)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for ADC_uwReadResultData0...
  '------------------------------------------------------------------------------------------------
  sFctName = "ReadResultData0"
  sDescription = "This function reads the 8- or 10-bit conversion results from result register 0"
  sReturnValue = "Conversion Result"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "uword", sDescription, sReturnValue, 1)) Then Exit Function
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_uwReadResultData1...
  '------------------------------------------------------------------------------------------------
  sFctName = "ReadResultData1"
  sDescription = "This function reads the 8- or 10-bit conversion results from result register 1"
  sReturnValue = "Conversion Result"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "uword", sDescription, sReturnValue, 1)) Then Exit Function
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_uwReadResultData0...
  '------------------------------------------------------------------------------------------------
  sFctName = "ReadResultData2"
  sDescription = "This function reads the 8- or 10-bit conversion results from result register 2"
  sReturnValue = "Conversion Result"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "uword", sDescription, sReturnValue, 1)) Then Exit Function
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_uwReadResultData0...
  '------------------------------------------------------------------------------------------------
  sFctName = "ReadResultData3"
  sDescription = "This function reads the 8- or 10-bit conversion results from result register 3"
  sReturnValue = "Conversion Result"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "uword", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  ' Description for ADC_ubGetResultChNum0...
  '------------------------------------------------------------------------------------------------
  sFctName = "ReadResultChNum0"
  sDescription = "This function reads channel number of the latest register update" & _
                 " by reading RESR0L (CHNR)"
  sReturnValue = "channel number of latest register update"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_ubGetResultChNum1...
  '------------------------------------------------------------------------------------------------
  sFctName = "ReadResultChNum1"
  sDescription = "This function reads channel number of the latest register update" & _
                 " by reading RESR1L (CHNR)"
  sReturnValue = "channel number of latest register update"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_ubGetResultChNum2...
  '------------------------------------------------------------------------------------------------
  sFctName = "ReadResultChNum2"
  sDescription = "This function reads channel number of the latest register update" & _
                 " by reading RESR2L (CHNR)"
  sReturnValue = "channel number of latest register update"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function
  '------------------------------------------------------------------------------------------------
  ' Description for ADC_ubGetResultChNum3...
  '------------------------------------------------------------------------------------------------
  sFctName = "ReadResultChNum3"
  sDescription = "This function reads channel number of the latest register update" & _
                 " by reading RESR3L (CHNR)"
  sReturnValue = "channel number of latest register update"
  If (Not func.AddFunction("ADC_NAME_" & sFctName, "ubyte", sDescription, sReturnValue, 1)) Then Exit Function

  '------------------------------------------------------------------------------------------------
  If (Not func.Sort) Then Exit Function

  RefreshFunctionDescriptions = True
End Function


'*****************************************************************************
'Description:
'          This function returns the module clock (in MHz) of the
'          ADC module depending on the configured modes
'-----------------------------------------------------------------------------
'Parameters:
'         r               reference to the Registers object
'         vIndex          ProjectData
'
'-----------------------------------------------------------------------------
'Returns:
'      ADC module clock [MHz]
'
'*****************************************************************************
Function GetADCModuleClock(r As ProjectData) As Double
  On Error Resume Next

 GetADCModuleClock = GetCoreClock(r)

End Function


'*****************************************************************************
'Description:
'        This function returns the fADCI clock [MHz], or strin if the fin is too
'        low or to high.
'
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'
'-----------------------------------------------------------------------------
'Returns:
'        fADCI clock [MHz], or
'        string "to low" or "to high"
'*****************************************************************************

Function Get_fADCI(r As ProjectData) As Variant
    
    Dim dF As Double
    Dim CTC_r    As Integer
    Dim sRegPre As String
    sRegPre = "ADC_"
    
    If (r.v(sRegPre & "GLOBCTR_CTC") = 3) Then
        CTC_r = 32
    Else
        CTC_r = (r.v(sRegPre & "GLOBCTR_CTC") + 2)
    End If
    
    dF = GetADCModuleClock(r) / CTC_r

    If (dF > Max_fADCI) Then
        Get_fADCI = TO_HIGH
    Else
        Get_fADCI = Format(dF, "00.00")
    End If

End Function

'*****************************************************************************
'Description:
'        This function returns the fADCI clock [MHz]
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'
'-----------------------------------------------------------------------------
'Returns:
'        fADCI clock [MHz], or
'*****************************************************************************

Function Get_fADCImsg(r As ProjectData) As Variant
    Dim dF As Double
    Dim CTC_r    As Integer
    Dim sRegPre As String
    sRegPre = "ADC_"
    If (r.v(sRegPre & "GLOBCTR_CTC") = 3) Then
        CTC_r = 32
    Else
        CTC_r = (r.v(sRegPre & "GLOBCTR_CTC") + 2)
    End If
    dF = GetADCModuleClock(r) / CTC_r
    Get_fADCImsg = Format(dF, "00.00")

End Function

'*****************************************************************************
'Description:
'        This function Reset Channelx Register.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          module index
'
'-----------------------------------------------------------------------------
'Returns:
'       disable bit name
'*****************************************************************************
Function ResetChannelRegister(r As ProjectData, vNumber As Variant) As String
    
    Dim sVarPre As String
    Dim sRegPre As String

  sVarPre = "ADC"
  sRegPre = sVarPre & "_"
     
     r.v("ADC_USE_CHANNEL_" & vNumber) = 0
     r.sfr(sRegPre & "CHCTR" & vNumber) = &H0
     r.v(sRegPre & "CHINFR_CHINF" & vNumber) = 0
     r.v(sRegPre & "CHINPR_CHINP" & vNumber) = 0
     r.v(sRegPre & "CHINSR_CHINS" & vNumber) = 0
     
     Call ReleaseAlternateInputPin(r, "AN" & vNumber)

End Function

'*****************************************************************************
'Description:
'        This function returns a formated disabled tooltip if the module
'        clock is disabled.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        Formated tooltip
'*****************************************************************************

Function GetTooltipModuleClockDisabled(r As ProjectData, vIndex As Variant) As String
  On Error Resume Next
    Dim s As String
  
    s = ""
    s = FormatDisabledToolTip("the ADC module clock is disabled")
      
    GetTooltipModuleClockDisabled = s

End Function

'*****************************************************************************
'Description:
'        This function is used to Calculate ADC Conversion Time
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'-----------------------------------------------------------------------------
'Returns:   none
'*****************************************************************************
Function GetAdcConversionTime(r As ProjectData) As String
    On Error Resume Next
    
    Dim sVarPre As String
    Dim sRegPre As String

  sVarPre = "ADC"
  sRegPre = sVarPre & "_"
        
        Dim CTC_r    As Integer
        Dim STC    As Integer
        Dim n    As Integer
        Dim fADC    As Double
        
        If (r.v(sRegPre & "GLOBCTR_CTC") = 3) Then
            CTC_r = 32
        Else
            CTC_r = (r.v(sRegPre & "GLOBCTR_CTC") + 2)
        End If
        
        If r.v(sRegPre & "GLOBCTR_DW") = 0 Then
            n = 10
        Else
            n = 8
        End If
            
        STC = r.v(sRegPre & "INPCR0_STC")
        fADC = GetADCModuleClock(r)
        GetAdcConversionTime = FormatTextOutput((1 + CTC_r * (3 + n + STC)) / fADC, "F")
End Function

'*****************************************************************************
'Description:
'        This function checks if the module clock is disabled.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            the module clock is disabled
'        False           else
'*****************************************************************************
Function IsModuleClockDisabled(r As ProjectData, vIndex As Variant) As Boolean
  On Error Resume Next
  
  IsModuleClockDisabled = False
  
  IsModuleClockDisabled = r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1

End Function


'*****************************************************************************
'Description:
'        This function checks if the module clock is disabled.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            the module clock is disabled
'        False           else
'*****************************************************************************
Function IsClocktoohigh(r As ProjectData) As Boolean
  On Error Resume Next
  
  If (Get_fADCI(r) = TO_HIGH) Then
    IsClocktoohigh = True
  Else
    IsClocktoohigh = False
  End If

End Function

'*****************************************************************************
'Description:
'        This function returns a formated disabled tooltip if the module
'        clock is too high
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        Formated tooltip
'*****************************************************************************

Function GetTooltipModuleClocktooHigh(r As ProjectData) As String
  On Error Resume Next
    Dim s As String
  
    s = ""
    s = FormatDisabledToolTip(TOOLTIP_ADC_MODULECLK_HIGH)
      
    GetTooltipModuleClocktooHigh = s

End Function

'*****************************************************************************
'Description:
'        This function returns a formated disabled tooltip if the module
'        tooltip
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        Formated tooltip
'*****************************************************************************

Function GetTooltipModule(r As ProjectData, tooltip As Integer) As String
  On Error Resume Next
    Dim s As String
      
      Dim sVarPre As String
      Dim sRegPre As String

      sVarPre = "ADC"
      sRegPre = sVarPre & "_"
   
    GetTooltipModule = TOOLTIP_DISABLED_IF
    
    If (tooltip = 0) Then
        If (IsModuleClockDisabled(r, "")) Then
              GetTooltipModule = GetTooltipModule & GetTooltipModuleClockDisabled(r, "")
        ElseIf (IsClocktoohigh(r)) Then
              GetTooltipModule = GetTooltipModule & GetTooltipModuleClocktooHigh(r)
        End If
    End If
    
    If (tooltip = 1) Then
        If (IsModuleClockDisabled(r, "")) Then
              GetTooltipModule = GetTooltipModule & GetTooltipModuleClockDisabled(r, "")
        ElseIf (IsClocktoohigh(r)) Then
              GetTooltipModule = GetTooltipModule & GetTooltipModuleClocktooHigh(r)
        ElseIf (r.v(sRegPre & "PRAR_ASEN0") = 0) Then
              GetTooltipModule = GetTooltipModule & FormatDisabledToolTip(TOOLTIP_ADC_ARBSLOT0_DISABLED)
        End If
    End If

    If (tooltip = 2) Then
        If (IsModuleClockDisabled(r, "")) Then
              GetTooltipModule = GetTooltipModule & GetTooltipModuleClockDisabled(r, "")
        ElseIf (IsClocktoohigh(r)) Then
              GetTooltipModule = GetTooltipModule & GetTooltipModuleClocktooHigh(r)
        ElseIf (r.v(sRegPre & "PRAR_ASEN1") = 0) Then
              GetTooltipModule = GetTooltipModule & FormatDisabledToolTip(TOOLTIP_ADC_ARBSLOT1_DISABLED)
        End If
    End If

    If (tooltip = 22) Then
        If (IsModuleClockDisabled(r, "")) Then
              GetTooltipModule = GetTooltipModule & GetTooltipModuleClockDisabled(r, "")
        ElseIf (IsClocktoohigh(r)) Then
              GetTooltipModule = GetTooltipModule & GetTooltipModuleClocktooHigh(r)
        ElseIf (r.v(sRegPre & "PRAR_ASEN0") = 0 Or r.v(sRegPre & "PRAR_ASEN1") = 0) Then
              GetTooltipModule = GetTooltipModule & FormatDisabledToolTip(TOOLTIP_ADC_ARBSLOT_DISABLED)
        End If
    End If

    If (tooltip = 3) Then
        If (IsModuleClockDisabled(r, "")) Then
              GetTooltipModule = GetTooltipModule & GetTooltipModuleClockDisabled(r, "")
        ElseIf (IsClocktoohigh(r)) Then
              GetTooltipModule = GetTooltipModule & GetTooltipModuleClocktooHigh(r)
        ElseIf (r.v(sRegPre & "PRAR_ASEN1") = 0) Then
              GetTooltipModule = GetTooltipModule & FormatDisabledToolTip(TOOLTIP_ADC_ARBSLOT1_DISABLED)
        ElseIf (r.v(sRegPre & "CRMR1_ENGT") = 0) Then
              GetTooltipModule = GetTooltipModule & FormatDisabledToolTip(TOOLTIP_ADC_GATING_0)
        End If
    End If
    
    If (tooltip = 4) Then
        If (IsModuleClockDisabled(r, "")) Then
              GetTooltipModule = GetTooltipModule & GetTooltipModuleClockDisabled(r, "")
        ElseIf (IsClocktoohigh(r)) Then
              GetTooltipModule = GetTooltipModule & GetTooltipModuleClocktooHigh(r)
        ElseIf (r.v(sRegPre & "PRAR_ASEN0") = 0) Then
              GetTooltipModule = GetTooltipModule & FormatDisabledToolTip(TOOLTIP_ADC_ARBSLOT0_DISABLED)
        ElseIf (r.v(sRegPre & "QMR0_ENGT") = 0) Then
              GetTooltipModule = GetTooltipModule & FormatDisabledToolTip(TOOLTIP_ADC_GATING_0)
        End If
    End If

    If (tooltip = 44) Then
        If (IsModuleClockDisabled(r, "")) Then
              GetTooltipModule = GetTooltipModule & GetTooltipModuleClockDisabled(r, "")
        ElseIf (IsClocktoohigh(r)) Then
              GetTooltipModule = GetTooltipModule & GetTooltipModuleClocktooHigh(r)
        ElseIf (r.v(sRegPre & "PRAR_ASEN0") = 0 Or r.v(sRegPre & "PRAR_ASEN1") = 0) Then
              GetTooltipModule = GetTooltipModule & FormatDisabledToolTip(TOOLTIP_ADC_ARBSLOT_DISABLED)
        ElseIf (r.v(sRegPre & "QMR0_ENGT") = 0 Or r.v(sRegPre & "CRMR1_ENGT") = 0) Then
              GetTooltipModule = GetTooltipModule & FormatDisabledToolTip(TOOLTIP_ADC_SEQPAR_DISABLED)
        End If
    End If

    If (tooltip = 48) Then
        If (IsModuleClockDisabled(r, "")) Then
              GetTooltipModule = GetTooltipModule & GetTooltipModuleClockDisabled(r, "")
        ElseIf (IsClocktoohigh(r)) Then
              GetTooltipModule = GetTooltipModule & GetTooltipModuleClocktooHigh(r)
        ElseIf ((r.v(sRegPre & "RCR0_IEN") = 0 Or r.v(sRegPre & "RCR1_IEN") = 0 Or r.v(sRegPre & "RCR2_IEN") = 0) Or r.v(sRegPre & "RCR0_IEN") = 0) Then
              GetTooltipModule = GetTooltipModule & FormatDisabledToolTip(TOOLTIP_ADC_RES_INTR_DISABLED)
        End If
    End If

End Function

'*****************************************************************************
'Description:
'        This function checks interrupt enabled/disabled.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'-----------------------------------------------------------------------------
'Returns:
'        Enables Interrupt Flag
'*****************************************************************************

Function IsInterruptEnabled(r As ProjectData) As Boolean
  On Error Resume Next
  Dim j As Integer
  Dim i As Integer
   
    Dim sVarPre As String
    Dim sRegPre As String

  sVarPre = "ADC"
  sRegPre = sVarPre & "_"

    j = 0
    For i = 0 To 7
      If (r.v(sRegPre & "CHCTR" & i & "_LCC") <> 0) Then
        j = 1
        Exit For
      End If
    Next i
    
    For i = 0 To 3
      If (r.v(sRegPre & "RCR" & i & "_IEN") <> 0) Then
        j = 1
        Exit For
      End If
    Next i

    If (r.v(sRegPre & "CRMR1_ENSI") Or r.v(sRegPre & "QINR0_ENSI")) Then
      j = 1
    End If
    r.v("ADC_USE_Isr") = j
    r.v("IEN1_EADC") = j
End Function

'***********************************************************************************
'Description:
'        This function disables the channel analog input pins if module is disabled.
'-----------------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'
'-----------------------------------------------------------------------------
'Returns:
'           None
'
'*****************************************************************************
Function DisableADC(r As ProjectData)
    On Error Resume Next
  Dim vNumber As Variant
   
   r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1
   r.v("ADC_USE_Init") = 0
   r.v("IEN1_EADC") = 0
   
   For vNumber = 0 To 7
     If (r.v("ADC_USE_CHANNEL_" & vNumber) = 1) Then
         Call ResetChannelRegister(r, vNumber)
     End If
   Next vNumber

End Function
'***********************************************************************************
'Description:
'        This function returns the  module if selected.
'-----------------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'
'-----------------------------------------------------------------------------
'Returns:
'           1    if CCU6 is selected
'           2    if T2CCU is selected
'           3    if both  are selected
'*****************************************************************************
Function GetModuleselect(r As ProjectData) As Integer
    On Error Resume Next
    
   If ((r.v("CCU6_USE_INIT") = 1) And (r.v("T2CCU_USE_INIT") = 1)) Then
     GetModuleselect = 3
    ElseIf (r.v("T2CCU_USE_INIT") = 1) Then
   GetModuleselect = 2
   ElseIf (r.v("CCU6_USE_INIT") = 1) Then
   GetModuleselect = 1
   Else
   GetModuleselect = 0
   End If
  
End Function
   
'*****************************************************************************
'Description:
'        This function adds ETRSEL  options and returns the listindex to the cboSCL.
'-----------------------------------------------------------------------------
'Parameters:
'        r                 reference to the ProjectData object
'        SrNo              Sequential or Parallel source
'        cboCrtl           SCL combo box control
'-----------------------------------------------------------------------------
'Returns: ListIndex to ETRSEL  combobox
'*****************************************************************************

Function AddETRSELIndex(r As ProjectData, SrNo As Integer, cboCrtl As Variant) As Integer
On Error Resume Next

  Dim i As Integer
  Dim j As Integer
  Dim k As Integer
  Dim ModAvl As Integer
  
  
  ModAvl = GetModuleselect(r)
  cboCrtl.Clear
  cboCrtl.AddItem ("None")

  Select Case (ModAvl)
    Case (0)
         cboCrtl.AddItem ("None")
         
    Case (1)
      For i = 0 To 7
        If (i = 0) Then
         cboCrtl.AddItem ("ETR" & SrNo & i & "_T13PM")
        End If
        If (i = 1) Then
         cboCrtl.AddItem ("ETR" & SrNo & i & "_T13CM")
         End If
         If (i = 2) Then
         cboCrtl.AddItem ("ETR" & SrNo & i & "_T12PM")
         End If
         If (i = 3) Then
         cboCrtl.AddItem ("ETR" & SrNo & i & "_T12CM0")
         End If
         If (i = 4) Then
         cboCrtl.AddItem ("ETR" & SrNo & i & "_T12CM1")
         End If
         If (i = 5) Then
         cboCrtl.AddItem ("ETR" & SrNo & i & "_T12CM2")
         End If
         If (i = 6) Then
         cboCrtl.AddItem ("ETR" & SrNo & i & "_SHDWTXEVMCM")
         End If
         If (i = 7) Then
         cboCrtl.AddItem ("ETR" & SrNo & i & "_HALLEVMCM")
         End If
      Next i
'          cboCrtl.AddItem ("ETR00" & "_T13PM")
'         cboCrtl.AddItem ("ETR01" & "_T13CM")
'         cboCrtl.AddItem ("ETR02" & "_T12PM")
'         cboCrtl.AddItem ("ETR03" & "_T12CM0")
'         cboCrtl.AddItem ("ETR04" & "_T12CM1")
'         cboCrtl.AddItem ("ETR05" & "_T12CM2")
'         cboCrtl.AddItem ("ETR06" & "_SHDWTXEVMCM")
'         cboCrtl.AddItem ("ETR07" & "_HALLEVMCM")
    Case (2)
        For j = 0 To 1
         If (j = 0) Then
         cboCrtl.AddItem ("ETR" & SrNo & j & "_CCTOV")
'         cboCrtl.AddItem ("ETR" & SrNo & j & "_CM5F")
         End If
         If (j = 1) Then
         cboCrtl.AddItem ("ETR" & SrNo & j & "_CM5F")
'         cboCrtl.AddItem ("ETR" & SrNo & j & "_CCTOV")
         End If
        Next j
         
'         cboCrtl.AddItem ("ETR00" & "_CM5F")
'         cboCrtl.AddItem ("ETR01" & "_CCTOV")
    Case (3)
      For k = 0 To 7
         If (k = 0) Then
         cboCrtl.AddItem ("ETR" & SrNo & k & "_T13PM")
         cboCrtl.AddItem ("ETR" & SrNo & k & "_CCTOV")
         End If
         If (k = 1) Then
         cboCrtl.AddItem ("ETR" & SrNo & k & "_T13CM")
         cboCrtl.AddItem ("ETR" & SrNo & k & "_CM5F")
         End If
         If (k = 2) Then
         cboCrtl.AddItem ("ETR" & SrNo & k & "_T12PM")
         End If
         If (k = 3) Then
         cboCrtl.AddItem ("ETR" & SrNo & k & "_T12CM0")
         End If
         If (k = 4) Then
         cboCrtl.AddItem ("ETR" & SrNo & k & "_T12CM1")
         End If
         If (k = 5) Then
         cboCrtl.AddItem ("ETR" & SrNo & k & "_T12CM2")
         End If
         If (k = 6) Then
         cboCrtl.AddItem ("ETR" & SrNo & k & "_SHDWTXEVMCM")
         End If
         If (k = 7) Then
         cboCrtl.AddItem ("ETR" & SrNo & k & "_HALLEVMCM")
         End If
      Next k
    Case Else
    
  End Select
  
  For i = 0 To cboCrtl.ListCount - 1
  If (SrNo = 0) Then
    If (cboCrtl.List(i) = r.v("ADC_UserDef0")) Then
        AddETRSELIndex = i
    End If
  Else
   If (cboCrtl.List(i) = r.v("ADC_UserDef1")) Then
        AddETRSELIndex = i
    End If
  End If
  Next i

  If ((cboCrtl.ListCount) = 1) Then cboCrtl.Enabled = False

End Function
   

'*****************************************************************************
'Description:
'        This function set the selected combo option for ETRSEL
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        SrNum           sequential or Parallel
'
'        CbNo           Selected combo
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub SetETRSEL(r As ProjectData, SrNum As Integer, CbNo As String)
  On Error Resume Next
   
  Select Case (CbNo)
    
  Case ("ETR" & SrNum & "0" & "_T13PM")
           If (SrNum = 0) Then
            r.v("ADC_ETRCR_ETRSEL0") = 0
            Else
            r.v("ADC_ETRCR_ETRSEL1") = 0
            End If
            r.v("MISC_CON_ADCETR0_MUX") = 0
  Case ("ETR" & SrNum & "1" & "_CM5F")
           If (SrNum = 0) Then
            r.v("ADC_ETRCR_ETRSEL0") = 1
            Else
            r.v("ADC_ETRCR_ETRSEL1") = 1
            End If
            If (r.v("ADC_QMR0_ENTR") = 1) And (r.v("ADC_CRMR1_ENTR") = 1) Then
            r.v("MISC_CON_ADCETR1_MUX") = 1
            ElseIf (r.v("ADC_QMR0_ENTR") = 1) Or (r.v("ADC_CRMR1_ENTR") = 1) Then
            r.v("MISC_CON_ADCETR1_MUX") = 1
            r.v("MISC_CON_ADCETR0_MUX") = 0
            End If
  Case ("ETR" & SrNum & "1" & "_T13CM")
           If (SrNum = 0) Then
            r.v("ADC_ETRCR_ETRSEL0") = 1
            Else
            r.v("ADC_ETRCR_ETRSEL1") = 1
            End If
            r.v("MISC_CON_ADCETR1_MUX") = 0
  Case ("ETR" & SrNum & "0" & "_CCTOV")
           If (SrNum = 0) Then
            r.v("ADC_ETRCR_ETRSEL0") = 0
           Else
            r.v("ADC_ETRCR_ETRSEL1") = 0
           End If
           If (r.v("ADC_QMR0_ENTR") = 1) And (r.v("ADC_CRMR1_ENTR") = 1) Then
            r.v("MISC_CON_ADCETR0_MUX") = 1
           ElseIf (r.v("ADC_QMR0_ENTR") = 1) Or (r.v("ADC_CRMR1_ENTR") = 1) Then
            r.v("MISC_CON_ADCETR0_MUX") = 1
            r.v("MISC_CON_ADCETR1_MUX") = 0
            End If
  Case ("ETR" & SrNum & "2" & "_T12PM")
           If (SrNum = 0) Then
            r.v("ADC_ETRCR_ETRSEL0") = 2
           Else
            r.v("ADC_ETRCR_ETRSEL1") = 2
           End If
  Case ("ETR" & SrNum & "3" & "_T12CM0")
           If (SrNum = 0) Then
            r.v("ADC_ETRCR_ETRSEL0") = 3
           Else
            r.v("ADC_ETRCR_ETRSEL1") = 3
           End If
  Case ("ETR" & SrNum & "4" & "_T12CM1")
           If (SrNum = 0) Then
            r.v("ADC_ETRCR_ETRSEL0") = 4
            Else
            r.v("ADC_ETRCR_ETRSEL1") = 4
            End If
  Case ("ETR" & SrNum & "5" & "_T12CM2")
           If (SrNum = 0) Then
            r.v("ADC_ETRCR_ETRSEL0") = 5
           Else
           r.v("ADC_ETRCR_ETRSEL1") = 5
           End If
  Case ("ETR" & SrNum & "6" & "_SHDWTXEVMCM")
           If (SrNum = 0) Then
            r.v("ADC_ETRCR_ETRSEL0") = 6
           Else
            r.v("ADC_ETRCR_ETRSEL1") = 6
           End If
  Case ("ETR" & SrNum & "7" & "_HALLEVMCM")
           If (SrNum = 0) Then
            r.v("ADC_ETRCR_ETRSEL0") = 7
            Else
            r.v("ADC_ETRCR_ETRSEL1") = 7
            End If
            
  

 End Select

End Sub

