ADC
 
Component ADC
A/D converter
Component Level: High
Methods:
(Methods are user-callable functions/subroutines intended for the component functions control. Please see the Embedded Components page for more information.)
  • Enable - Enables A/D converter component. Events may be generated (DisableEvent/EnableEvent). If possible, this method switches on A/D converter device, voltage reference, etc.

      ANSIC prototype: byte Enable(void)
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode

  • Disable - Disables A/D converter component. No events will be generated. If possible, this method switches off A/D converter device, voltage reference, etc.

      ANSIC prototype: byte Disable(void)
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode

  • EnableEvent - Enables the events.

      ANSIC prototype: byte EnableEvent(void)
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode

  • DisableEvent - Disables the events.

      ANSIC prototype: byte DisableEvent(void)
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode

  • Start - This method starts continuous conversion on all channels that are set in the component inspector. When each measurement on all channels has finished the OnEnd event may be invoked. This method is not available if the interrupt service is disabled and the device doesn't support the continuous mode. Note: If time of measurement is too short and the instruction clock is too slow then the conversion complete interrupt and its handler may cause a system overflow.

      ANSIC prototype: byte Start(void)
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_DISABLED - Device is disabled
      ERR_BUSY - A conversion is already running

  • Stop - This method stops the continuous measurement or disables a trigger mode (if supported by HW), which has been started by one of the following methods:
    Version specific information for Freescale ColdFireV1, HCS08, HC08 and RS08 derivatives
    Version specific information not for Freescale 56800 and HCS08 and HC08 and HCS12 and HCS12X derivatives
    • Start
    • EnableInt(Chan)Trigger
    • EnableExt(Chan)Trigger
    The Stop method is available if one of the previously mentioned methods is supported by A/D converter device and is enabled to be generated.

      ANSIC prototype: byte Stop(void)
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_BUSY - No continuous measurement is running. Neither internal trigger nor external trigger have been enabled (if these are supported by HW).

  • Measure - This method performs one measurement on all channels that are set in the component inspector. (Note: If the number of conversions is more than one the conversion of A/D channels is performed specified number of times.)

      ANSIC prototype: byte Measure(bool WaitForResult)
    • WaitForResult:bool - Wait for a result of a conversion. If interrupt service is disabled, A/D peripheral doesn't support measuring all channels at once or Autoscan mode property isn't enabled and at the same time the number of channel is greater than 1, then the WaitForResult parameter is ignored and the method waits for each result every time. If the interrupt service is disabled and a number of conversions is greater than 1, the parameter is ignored and the method also waits for each result every time.
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_DISABLED - Device is disabled
      ERR_BUSY - A conversion is already running

  • MeasureChan - This method performs measurement on one channel. (Note: If the number of conversions is more than one the conversion of the A/D channel is performed specified number of times.)

      ANSIC prototype: byte MeasureChan(bool WaitForResult, byte Channel)
    • WaitForResult:bool - Wait for a result of conversion. If the interrupt service is disabled and at the same time a number of conversions is greater than 1, the WaitForResult parameter is ignored and the method waits for each result every time.
    • Channel:byte - Channel number. If only one channel in the component is set this parameter is ignored, because the parameter is set inside this method.
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_DISABLED - Device is disabled
      ERR_BUSY - A conversion is already running
      ERR_RANGE - Parameter "Channel" out of range

  • Methods for Freescale HCS12/HCS12X and Freescale HCS08 DZ, DE, DN, DV, EN, FL and SV and MCF derivatives.
    • EnableExtChanTrigger - Enables the trigger mode. If an active edge or an active level (property Trigger active) is detected, a conversion of only one required channel will be performed. If the Number of conversions is greater than 1, a conversion will be launched more than once (by an external signal) according to Number of conversions. It's possible to disable the trigger mode by Stop method.
      Version specific information for other derivatives than Freescale HCS12 and HCS12X
      This EnableExtChanTrigger method is available only when External trigger property is enabled.

        ANSIC prototype: byte EnableExtChanTrigger(byte Channel)
      • Channel:byte - Channel number which will be measured on an external trigger (control). If only one channel in the component is set then this parameter is ignored.
      • Return value:byte - Error code, possible codes:
        ERR_OK - OK
        ERR_BUSY - A conversion is already running
        ERR_RANGE - Parameter "Channel" out of range

  • Methods for Freescale ColdFireV1, 56800, HCS12X, HCS12 P, RS08, HCS08 AC, AW, DE, DN, DV, DZ, EL, EN, IA, IB, IC, JE, JM, LC, LG, LH, LL, MM, MP, QA, QB, QE, QG8, QG4, RT16, SC, SE, SG, SH and SV derivatives.
    • EnableIntChanTrigger - Enables the internal trigger mode. A conversion of one required channel will be launched by internal sync pulse. If the Number of conversions property is greater than 1, a conversion will be launched more than once (by an internal signal) according to Number of conversions. It's possible to disable the trigger mode by Stop method.
      Version specific information for other derivatives than Freescale HCS12 and HCS12X
      This EnableIntChanTrigger method is available only when the Internal trigger property is enabled.

        ANSIC prototype: byte EnableIntChanTrigger(byte Channel)
      • Channel:byte - Channel number which will be measured at internal trigger control. If only one channel in the component is set then this parameter is ignored.
      • Return value:byte - Error code, possible codes:
        ERR_OK - OK
        ERR_BUSY - A conversion is already running
        ERR_RANGE - Parameter "Channel" out of range

  • GetValue - Returns the last measured values for all channels. Format and width of the value is a native format of the A/D converter.

      ANSIC prototype: byte GetValue(void* Values)
    • Values:void* - Pointer to the array that contains the measured data. Data type is a byte, a word or an int. It depends on the supported modes, resolution, etc. of the AD converter. See the Version specific information for the current CPU in General Info.
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_NOTAVAIL - Requested value not available
      ERR_OVERRUN - External trigger overrun flag was detected after the last value(s) was obtained (for example by GetValue). This error may not be supported on some CPUs (see generated code).

  • GetChanValue - Returns the last measured value of the required channel. Format and width of the value is a native format of the A/D converter.

      ANSIC prototype: byte GetChanValue(byte Channel, void* Value)
    • Channel:byte - Channel number. If only one channel in the component is set then this parameter is ignored.
    • Value:void* - Pointer to the measured value. Data type is a byte, a word or an int. It depends on the supported modes, resolution, etc. of the AD converter. See the Version specific information for the current CPU in General Info.
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_NOTAVAIL - Requested value not available
      ERR_RANGE - Parameter "Channel" out of range
      ERR_OVERRUN - External trigger overrun flag was detected after the last value(s) was obtained (for example by GetValue). This error may not be supported on some CPUs (see generated code).

  • GetValue8 - This method returns the last measured values of all channels justified to the left. Compared with GetValue method this method returns more accurate result if the number of conversions is greater than 1 and AD resolution is less than 8 bits. In addition, the user code dependency on AD resolution is eliminated.

      ANSIC prototype: byte GetValue8(byte *Values)
    • Values: Pointer to byte - Pointer to the array that contains the measured data.
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_NOTAVAIL - Requested value not available
      ERR_OVERRUN - External trigger overrun flag was detected after the last value(s) was obtained (for example by GetValue). This error may not be supported on some CPUs (see generated code).

  • GetChanValue8 - This method returns the last measured value of required channel justified to the left. Compared with GetChanValue method this method returns more accurate result if the number of conversions is greater than 1 and AD resolution is less than 8 bits. In addition, the user code dependency on AD resolution is eliminated.

      ANSIC prototype: byte GetChanValue8(byte Channel, byte *Value)
    • Channel:byte - Channel number. If only one channel in the component is set then this parameter is ignored.
    • Value: Pointer to byte - Pointer to the measured value.
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_NOTAVAIL - Requested value not available
      ERR_RANGE - Parameter "Channel" out of range
      ERR_OVERRUN - External trigger overrun flag was detected after the last value(s) was obtained (for example by GetValue). This error may not be supported on some CPUs (see generated code).

  • GetValue16 - This method returns the last measured values of all channels justified to the left. Compared with GetValue method this method returns more accurate result if the number of conversions is greater than 1 and AD resolution is less than 16 bits. In addition, the user code dependency on AD resolution is eliminated.

      ANSIC prototype: byte GetValue16(word *Values)
    • Values: Pointer to word - Pointer to the array that contains the measured data.
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_NOTAVAIL - Requested value not available
      ERR_OVERRUN - External trigger overrun flag was detected after the last value(s) was obtained (for example by GetValue). This error may not be supported on some CPUs (see generated code).

  • GetChanValue16 - This method returns the last measured value of the required channel justified to the left. Compared with GetChanValue method this method returns more accurate result if the number of conversions is greater than 1 and AD resolution is less than 16 bits. In addition, the user code dependency on AD resolution is eliminated.

      ANSIC prototype: byte GetChanValue16(byte Channel, word *Value)
    • Channel:byte - Channel number. If only one channel in the component is set then this parameter is ignored.
    • Value: Pointer to word - Pointer to the measured value.
    • Return value:byte - Error code, possible codes:
      ERR_OK - OK
      ERR_SPEED - This device does not work in the active speed mode
      ERR_NOTAVAIL - Requested value not available
      ERR_RANGE - Parameter "Channel" out of range
      ERR_OVERRUN - External trigger overrun flag was detected after the last value(s) was obtained (for example by GetValue). This error may not be supported on some CPUs (see generated code).

  • Methods only if ADC support Self calibration.
    • Calibrate - This method starts self calibration process. Calibration is typically used to remove the effects of the gain and offset from a specific reading.

        ANSIC prototype: byte Calibrate(bool WaitForResult)
      • WaitForResult:bool - Wait for a result of calibration. If the interrupt service is disabled, the WaitForResult parameter is ignored and the method waits for calibration result every time.
      • Return value:byte - Error code
        ERR_OK - OK
        ERR_BUSY - A conversion is already running
        ERR_SPEED - This device does not work in the active speed mode
        ERR_DISABLED - Device is disabled
        ERR_FAILED - Calibration hasn't been finished correctly

    • GetCalibrationStatus - This method should be used for check the last calibration result, return value is invalid if no calibration is called.

        ANSIC prototype: byte GetCalibrationStatus(void)
      • Return value:byte - Error code
        ERR_OK - OK
        ERR_FAILED - Last calibration hasn't been finished correctly

  • Methods for Freescale ColdFireV1, RS08, HC08 EY16A, JL16, JK16, LV8, QB8, QC16, QL4, QT4A, QT8, QY4A, QY8 and HCS08 AC, AW60, DE, DN, DV, DZ, EL, EN, FL, IA, IB, IC, JE, JM, LC, LG, LH, LL, MM, MP, QA, QB, QE, QG8, QG4, SC, SE, SF, SG, SH, RT16 and SV derivatives.
    • EnableAsynchroClock - This method selects the asynchronous clock as a source clock for the AD converter. The asynchronous clock is applied directly with no prescaler. For details about this asynchronous clock and its frequency see documentation of the specific derivative.

        ANSIC prototype: void EnableAsynchroClock(void)

    • DisableAsynchroClock - This method disables the previously enabled asynchronous clock source and restores the original clock setting of the actual speed mode. This method is available only if the EnableAsynchroClock method is enabled.

        ANSIC prototype: void DisableAsynchroClock(void)

  • Methods only if ADC support compare.
    • EnableAutoCompare - This method enables the automatic compare function of the AD converter. This method should be used in cooperation with EnableIntChanTrigger method.

        ANSIC prototype: byte EnableAutoCompare(bool CompareType, word CompareValue)
      • CompareType:bool - Determines type of compare function:
        true - Compare triggers when input is greater than or equal to compare level
        false - Compare triggers when input is less than compare level
      • CompareValue:word - The compare level used for comparison.
      • Return value:byte - Error code
        ERR_OK - OK
        ERR_BUSY - A conversion is already running
        ERR_SPEED - This device does not work in the active speed mode
        ERR_DISABLED - Device is disabled

    • Methods only if ADC support Range compare.
      • EnableRangeAutoCompare - This method enables the automatic range compare function of the AD converter. This method should be used in cooperation with EnableIntChanTrigger method.

          ANSIC prototype: byte EnableRangeAutoCompare(bool CompareType, word CompareValue1, word CompareValue2)
        • CompareType:bool - Determines type of compare function:
          true - If CompareValue1 <= CompareValue2 compare triggers when input is inside range inclusive endpoint; if CompareValue1 > CompareValue2 compare triggers when input is outside range inclusive endpoint.
          false - If CompareValue1 <= CompareValue2 compare triggers when input is outside range exclusive endpoint; if CompareValue1 > CompareValue2 compare triggers when input is inside range exclusive endpoint.
        • CompareValue1:word - The compare level 1 used for comparison.
        • CompareValue2:word - The compare level 2 used for comparison.
        • Return value:byte - Error code
          ERR_OK - OK
          ERR_BUSY - A conversion is already running
          ERR_SPEED - This device does not work in the active speed mode
          ERR_DISABLED - Device is disabled

    • DisableAutoCompare - Disables the automatic (range) compare function of the AD converter.

        ANSIC prototype: byte DisableAutoCompare(void)
      • Return value:byte - Error code
        ERR_OK - OK


Note: Some methods can be implemented as macros.