Freescale-
AnalogComp
 
Component FreescaleAnalogComp
Analog comparator on Freescale derivates
Component Level: Low
Typical Usage:
(Examples of a typical usage of the component in user code. For more information please see the page Component Code Typical Usage.)

Assume the component name "Cmp1".

(1)
The easiest usage of the component is to use the method GetAnalogComparatorOutputValue(byte *pCmpOutputVal) to get the current value of an analog comparator output.

 MAIN.C

void main(void)
{
  byte CmpOutputVal
  byte res;

  ...
  res=Cmp1_GetAnalogComparatorOutputValue(&CmpOutputVal);
  ...

}

(2)
Advanced usage of the component is enabling interrupt service and setting property "Analog comp. mode" in the component inspector to the one of possible value to specify the event to generate interrupt.

 EVENTS.C

void Cmp1_OnCompare(void)
{
  byte CmpOutputVal
  byte res;
  ...
  /* "Analog comp. mode" property is set to 'falling and rising edge' */
  /* Get comp. output value */
  res=Cmp1_GetAnalogComparatorOutputValue(&CmpOutputVal);
  ...
  if(CmpOutputVal)
    ...    /* Actual output compare value is 1 */
  else
    ...    /* Actual output compare value is 0 */
}