KL25Z Comparator library

Dependents:   ComparatorIn_demo TEMT6200_demo 05_comparator_demo 05_comparator_demo ... more

KL25Z Comparator library

Comparator features

  • Operational over the entire supply range
  • Inputs may range from rail to rail
  • Programmable hysteresis control
  • Selectable interrupt on rising-edge, falling-edge, or both rising or falling edges of the comparator output
  • Selectable inversion on comparator output
  • Capability to produce a wide range of outputs such as:
    • Sampled
    • Windowed, which is ideal for certain PWM zero-crossing-detection applications
    • Digitally filtered:
      • Filter can be bypassed
      • Can be clocked via external SAMPLE signal or scaled bus clock
  • External hysteresis can be used at the same time that the output filter is used for internal functions
  • Two software selectable performance levels:
    • Shorter propagation delay at the expense of higher power
    • Low power, with longer propagation delay
  • DMA transfer support not yet implemented in this library
    • A comparison event can be selected to trigger a DMA transfer
  • Functional in all modes of operation
  • The window and filter functions are not available in the following modes:
    • Stop
    • VLPS
    • LLS
    • VLLSx

Block diagram

/media/uploads/frankvnk/kl25z_comparator_block_diagram.jpg

Introduction

This library allows us to create comparator objects between different inputs.
The comparator + and - inputs can be routed to one out of eight reference inputs (see table).
Input selection

Pin name#MUX inputCMP0Comment
PTC6000IN0CMP0_IN0
PTC7001IN1CMP0_IN1
PTC8010IN2CMP0_IN2
PTC9011IN3CMP0_IN3
PTE30100IN4CMP0_IN412-bit DAC0
PTE29101IN5CMP0_IN5
110IN61V internal Bandgap*
NC111IN7internal 6-bit DAC0
(table 1)

* Not yet implemented

Using the library

Selecting pins on initialisation
Upon initialisation, the comparator registers are set to following values:

    CMP0->CR0   = 0x00;  // Filter and digital hysteresis disabled
    CMP0->CR1   = 0x17;  // Continuous mode, high-speed compare, unfiltered output, output pin disabled
    CMP0->FPR   = 0x00;  // Filter disabled
    CMP0->SCR   = 0x06;  // Disable all interrupts and clear flags (flags are cleared by this write)
    CMP0->DACCR = 0xE0;  // DAC enabled, Vdd is 6bit reference, threshold set to 1/2 of full-scale (1.65V)

The library accepts two input parameters:
example:

ComparatorIn compi(PTC8, NC);
  • First parameter : + input pin.
  • Second parameter : - input pin.
    Every pin from the 'Pin name' column in (table 1) can be selected.

notes

  • IN6 (internal 1V bandgap reference) has no pin name and is not selectable on init.
    However, we can use the SwitchPlus and SwitchMin functions to change the corresponding input to IN6.
  • There are two special cases for the input parameters:
    • NC : Connect the internal 6-bit DAC0 to IN7.
    • PTE30 : configures PTE30 as 12-bit DAC0 output and connect to IN4.
      IMPORTANT: Make sure no external output is connected to PTE30 when you declare this pin, otherwise you WILL destroy the external device and/or the CPU.

Example
Following code demonstrates interrupt callback and polling mode.
Note: Polling the comparator this way won't always trigger the printf because of the wait() instructions (if we go above and below the threshold during the wait() time, then the polling cannot not see this change).

/***********************************************************
CODE EXAMPLE FOR AMBIENT LIGHT SENSOR ON KL25Z + Wi-Go BOARD
 ***********************************************************/
#include "ComparatorIn.h"
#include "mbed.h"

DigitalOut blinker(LED_BLUE);
DigitalOut cmpled(LED_GREEN);
DigitalOut cmp_en (PTD5);
AnalogIn cmp_lvl (PTB0);
ComparatorIn compi(PTC8, NC); // in+ = PTC8, in- = internal 6-bit DAC 

// Comparator callback functions
void cmp_rise_ISR(void)
{
    cmpled = 0;
}

void cmp_fall_ISR(void)
{
    cmpled = 1;
}

int main()
{
    cmp_en = 1;
    cmpled = 1;

    compi.rising(&cmp_rise_ISR);                // Set pointer to rising interrupt function
    compi.falling(&cmp_fall_ISR);               // Set pointer to falling interrupt function
    compi.treshold(0.5);                        // Set comparator threshold to 1.65V = 32 * 3.3V / 64

    while(1)
    {
        printf("Light sensor : %7.5f Volt\n",cmp_lvl*3.3);
        blinker = 1;
        wait(1);
        blinker = 0;
        wait(0.2);
        if (compi.status() == 0x01)
        {
            printf("*** Treshold reached : %7.5f\n",cmp_lvl*3.3);
        }
    }
}


Notes

  • When we enable the comparator interrupt, we need to declare user callback function(s) (rising and/or falling interrupt) AND initialise the function pointer(s).
    example:

compi.rising(&cmp_rise_ISR);
compi.falling(&cmp_fall_ISR);
  • Currently, following functions are not yet implemented:
    • On the fly MUX switching for + input (SwitchPlus function).
    • On the fly MUX switching for - input (SwitchMin function).
    • DMA transfer.
Committer:
frankvnk
Date:
Sun Aug 25 18:00:42 2013 +0000
Revision:
19:e6a4cd28e217
Parent:
18:efa8d41b738f
_fptr names were too generic. Added comparatorin_ to each name.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frankvnk 1:ccac56d8f1cb 1 /**************************************************************************************************
frankvnk 1:ccac56d8f1cb 2 ***** *****
frankvnk 1:ccac56d8f1cb 3 ***** Name: ComparatorIn.h *****
frankvnk 1:ccac56d8f1cb 4 ***** Date: 05/06/2013 *****
frankvnk 1:ccac56d8f1cb 5 ***** Auth: Frank Vannieuwkerke *****
frankvnk 1:ccac56d8f1cb 6 ***** Func: library for KL25Z Comparator *****
frankvnk 1:ccac56d8f1cb 7 ***** *****
frankvnk 1:ccac56d8f1cb 8 **************************************************************************************************/
frankvnk 1:ccac56d8f1cb 9
frankvnk 0:e742ad3d7dac 10 #ifndef COMPARATORIN_H
frankvnk 0:e742ad3d7dac 11 #define COMPARATORIN_H
frankvnk 0:e742ad3d7dac 12
frankvnk 0:e742ad3d7dac 13 /*
frankvnk 0:e742ad3d7dac 14 * Includes
frankvnk 0:e742ad3d7dac 15 */
frankvnk 0:e742ad3d7dac 16 #include "mbed.h"
frankvnk 0:e742ad3d7dac 17 #include "pinmap.h"
frankvnk 0:e742ad3d7dac 18
frankvnk 0:e742ad3d7dac 19 #ifndef TARGET_KL25Z
frankvnk 0:e742ad3d7dac 20 #error "Target not supported"
frankvnk 0:e742ad3d7dac 21 #endif
frankvnk 0:e742ad3d7dac 22
frankvnk 0:e742ad3d7dac 23 /** ComparatorIn library
frankvnk 0:e742ad3d7dac 24 *
frankvnk 0:e742ad3d7dac 25 * INP/INM connection selection :
frankvnk 0:e742ad3d7dac 26 * PTC6 (IN0) CMP0_IN0
frankvnk 0:e742ad3d7dac 27 * PTC7 (IN1) CMP0_IN1
frankvnk 0:e742ad3d7dac 28 * PTC8 (IN2) CMP0_IN2
frankvnk 0:e742ad3d7dac 29 * PTC9 (IN3) CMP0_IN3
frankvnk 18:efa8d41b738f 30 * PTE30 (IN4) CMP0_IN4 (External 12-bit DAC0, auto connect to IN4)
frankvnk 0:e742ad3d7dac 31 * PTE29 (IN5) CMP0_IN5
frankvnk 0:e742ad3d7dac 32 * Internal 6-bit DAC reference voltage = VDD (3.3V)
frankvnk 18:efa8d41b738f 33 * Hysteresis, filter count and sample period are initialised to these values when ComparatorIn is initialized:
frankvnk 18:efa8d41b738f 34 * CMP0->CR0 = 0x00; // Filter and digital hysteresis disabled
frankvnk 0:e742ad3d7dac 35 * CMP0->CR1 = 0x17; // Continuous mode, high-speed compare, unfiltered output, output pin disabled
frankvnk 0:e742ad3d7dac 36 * CMP0->FPR = 0x00; // Filter disabled
frankvnk 13:2d499824ba05 37 * CMP0->SCR = 0x06; // Disable all interrupts and clear flags (flags are cleared by this write)
frankvnk 0:e742ad3d7dac 38 * CMP0->DACCR = 0xC4; // DAC enabled, Vdd is 6bit reference, threshold set to 1/16 of full-scale (0.2V)
frankvnk 0:e742ad3d7dac 39 */
frankvnk 0:e742ad3d7dac 40
frankvnk 0:e742ad3d7dac 41 typedef enum {
frankvnk 0:e742ad3d7dac 42 CMP0_IN0 = 0,
frankvnk 0:e742ad3d7dac 43 CMP0_IN1 = 1,
frankvnk 0:e742ad3d7dac 44 CMP0_IN2 = 2,
frankvnk 0:e742ad3d7dac 45 CMP0_IN3 = 3,
frankvnk 0:e742ad3d7dac 46 CMP0_IN4 = 4,
frankvnk 0:e742ad3d7dac 47 CMP0_IN5 = 5,
frankvnk 0:e742ad3d7dac 48 } CMPName;
frankvnk 0:e742ad3d7dac 49
frankvnk 2:43fd96e8687d 50 /** Class to use KL25Z Comparator
frankvnk 2:43fd96e8687d 51 */
frankvnk 0:e742ad3d7dac 52 class ComparatorIn {
frankvnk 0:e742ad3d7dac 53
frankvnk 0:e742ad3d7dac 54 public:
frankvnk 0:e742ad3d7dac 55
frankvnk 18:efa8d41b738f 56 /** Create a ComparatorIn, connected to the specified pins.
frankvnk 0:e742ad3d7dac 57 * @param pinP = positive ComparatorIn pin to connect to
frankvnk 18:efa8d41b738f 58 * @param pinM = negative ComparatorIn pin to connect to\n
frankvnk 18:efa8d41b738f 59 * @note Valid values for pinP/pinM:\n
frankvnk 18:efa8d41b738f 60 * PTC6, PTC7, PTC8, PTC9, PTE30, PTE29, NC\n
frankvnk 18:efa8d41b738f 61 * Special cases:\n
frankvnk 18:efa8d41b738f 62 * NC the corresponding input is connected to the internal 6-bit DAC0\n
frankvnk 18:efa8d41b738f 63 * PTE30 PTE30 is set as 12-bit DAC0 output and connected to IN4\n
frankvnk 0:e742ad3d7dac 64 * @return none
frankvnk 0:e742ad3d7dac 65 */
frankvnk 0:e742ad3d7dac 66 ComparatorIn(PinName pinP,PinName pinM);
frankvnk 0:e742ad3d7dac 67
frankvnk 18:efa8d41b738f 68 /** Set the number of consecutive threshold samples.
frankvnk 18:efa8d41b738f 69 * Represents the number of consecutive samples that must agree\n
frankvnk 18:efa8d41b738f 70 * prior to the comparator ouput filter accepting a new output state.\n
frankvnk 0:e742ad3d7dac 71 * @param input Unsigned char - range : 1..7
frankvnk 0:e742ad3d7dac 72 * @return none
frankvnk 0:e742ad3d7dac 73 */
frankvnk 17:048474f28d28 74 void FilterCount(unsigned char fico);
frankvnk 0:e742ad3d7dac 75
frankvnk 18:efa8d41b738f 76 /** Set the hysteresis.
frankvnk 18:efa8d41b738f 77 * 0 : 5mV\n
frankvnk 18:efa8d41b738f 78 * 1 : 10mV\n
frankvnk 18:efa8d41b738f 79 * 2 : 20mV\n
frankvnk 18:efa8d41b738f 80 * 3 : 30mV\n
frankvnk 0:e742ad3d7dac 81 * @param input Unsigned char
frankvnk 0:e742ad3d7dac 82 * @return none
frankvnk 0:e742ad3d7dac 83 */
frankvnk 12:0a0648bddb98 84 void hysteresis(unsigned char hyst);
frankvnk 0:e742ad3d7dac 85
frankvnk 18:efa8d41b738f 86 /** Sampling mode control.
frankvnk 18:efa8d41b738f 87 * This mode cannot be set when windowing mode is enabled.
frankvnk 18:efa8d41b738f 88 * @param input Unsigned char (0 = disable, 1 = enable)
frankvnk 0:e742ad3d7dac 89 * @return none
frankvnk 0:e742ad3d7dac 90 */
frankvnk 17:048474f28d28 91 void SampleMode(unsigned char samp_en);
frankvnk 0:e742ad3d7dac 92
frankvnk 18:efa8d41b738f 93 /** Windowing mode control.
frankvnk 18:efa8d41b738f 94 * This mode cannot be set when sampling mode is enabled.
frankvnk 18:efa8d41b738f 95 * @param input Unsigned char (0 = disable, 1 = enable)
frankvnk 0:e742ad3d7dac 96 * @return none
frankvnk 0:e742ad3d7dac 97 */
frankvnk 17:048474f28d28 98 void WindowMode(unsigned char win_en);
frankvnk 0:e742ad3d7dac 99
frankvnk 18:efa8d41b738f 100 /** Trigger mode control.
frankvnk 18:efa8d41b738f 101 * CMP and DAC are configured to CMP Trigger mode when CMP_CR1[TRIGM] is set to 1.\n
frankvnk 18:efa8d41b738f 102 * In addition, the CMP should be enabled. If the DAC is to be used as a reference\n
frankvnk 18:efa8d41b738f 103 * to the CMP, it should also be enabled.\n
frankvnk 18:efa8d41b738f 104 * CMP Trigger mode depends on an external timer resource to periodically enable the\n
frankvnk 18:efa8d41b738f 105 * CMP and 6-bit DAC in order to generate a triggered compare. Upon setting TRIGM,\n
frankvnk 18:efa8d41b738f 106 * the CMP and DAC are placed in a standby state until an external timer resource\n
frankvnk 18:efa8d41b738f 107 * trigger is received.\n
frankvnk 18:efa8d41b738f 108 * @param input Unsigned char (0 = disable, 1 = enable)
frankvnk 0:e742ad3d7dac 109 * @return none
frankvnk 0:e742ad3d7dac 110 */
frankvnk 17:048474f28d28 111 void TrigMode(unsigned char trig_en);
frankvnk 0:e742ad3d7dac 112
frankvnk 18:efa8d41b738f 113 /** Power mode control.
frankvnk 18:efa8d41b738f 114 * 0 Low-Speed (LS) Comparison mode selected. In this mode, CMP has\n
frankvnk 18:efa8d41b738f 115 * slower output propagation delay and lower current consumption.\n
frankvnk 18:efa8d41b738f 116 * 1 High-Speed (HS) Comparison mode selected. In this mode, CMP has\n
frankvnk 18:efa8d41b738f 117 * faster output propagation delay and higher current consumption.\n
frankvnk 18:efa8d41b738f 118 * @param input Unsigned char - (0 = Low-Speed, 1 = high-Speed)
frankvnk 0:e742ad3d7dac 119 * @return none
frankvnk 0:e742ad3d7dac 120 */
frankvnk 17:048474f28d28 121 void PowerMode(unsigned char pmode);
frankvnk 0:e742ad3d7dac 122
frankvnk 18:efa8d41b738f 123 /** Invert mode control.
frankvnk 18:efa8d41b738f 124 * Allows selection of the polarity of the analog comparator function.\n
frankvnk 18:efa8d41b738f 125 * It is also driven to the COUT output, on both the device pin and as SCR[COUT], when OPE=0.\n
frankvnk 18:efa8d41b738f 126 * 0 Does not invert the comparator output.\n
frankvnk 18:efa8d41b738f 127 * 1 Inverts the comparator output.\n
frankvnk 18:efa8d41b738f 128 * @param input Unsigned char - (0 = not inverted, 1 = inverted)
frankvnk 0:e742ad3d7dac 129 * @return none
frankvnk 0:e742ad3d7dac 130 */
frankvnk 12:0a0648bddb98 131 void invert(unsigned char inv);
frankvnk 0:e742ad3d7dac 132
frankvnk 18:efa8d41b738f 133 /** Comparator Output Select.
frankvnk 18:efa8d41b738f 134 * 0 Set the filtered comparator output (CMPO) to equal COUT.\n
frankvnk 18:efa8d41b738f 135 * 1 Set the unfiltered comparator output (CMPO) to equal COUTA.\n
frankvnk 18:efa8d41b738f 136 * @param input Unsigned char - (0 : CMPO = COUT, 1 : CMPO = COUTA)
frankvnk 0:e742ad3d7dac 137 * @return none
frankvnk 0:e742ad3d7dac 138 */
frankvnk 17:048474f28d28 139 void OutputSelect(unsigned char cos);
frankvnk 0:e742ad3d7dac 140
frankvnk 18:efa8d41b738f 141 /** Connect the comparator Output Pin to an external pin.
frankvnk 18:efa8d41b738f 142 * Only one pin can be connected at any time.\n
frankvnk 18:efa8d41b738f 143 * Each time this function is called, the last active pin will be disabled before the new pin is enabled.\n
frankvnk 12:0a0648bddb98 144 * @param input NC disconnect CMPO from the associated CMPO output pin.
frankvnk 12:0a0648bddb98 145 * @param input PTC0 connect CMPO to PTC0.
frankvnk 12:0a0648bddb98 146 * @param input PTC5 connect CMPO to PTC5.
frankvnk 12:0a0648bddb98 147 * @param input PTE0 connect CMPO to PTE0.
frankvnk 0:e742ad3d7dac 148 */
frankvnk 17:048474f28d28 149 void OutputPin(PinName ope);
frankvnk 0:e742ad3d7dac 150
frankvnk 18:efa8d41b738f 151 /** Comparator Module control.
frankvnk 18:efa8d41b738f 152 * Used to switch the Analog Comparator module on/off. When the module is not enabled,\n
frankvnk 18:efa8d41b738f 153 * it remains in the off state, and consumes no power. When the user selects the same\n
frankvnk 18:efa8d41b738f 154 * input from analog mux to the positive and negative port, the comparator is disabled automatically.\n
frankvnk 18:efa8d41b738f 155 * 0 Analog Comparator is disabled.\n
frankvnk 18:efa8d41b738f 156 * 1 Analog Comparator is enabled.\n
frankvnk 18:efa8d41b738f 157 * @param input Unsigned char - (0 = disable, 1 = enable)
frankvnk 0:e742ad3d7dac 158 * @return none
frankvnk 0:e742ad3d7dac 159 */
frankvnk 12:0a0648bddb98 160 void enable(unsigned char en);
frankvnk 0:e742ad3d7dac 161
frankvnk 18:efa8d41b738f 162 /** Set the filter sample period.
frankvnk 18:efa8d41b738f 163 * Specifies the sampling period, in bus clock cycles, of the comparator\n
frankvnk 18:efa8d41b738f 164 * output filter, when CR1[SE]=0. Setting FILT_PER to 0x0 disables the filter.\n
frankvnk 0:e742ad3d7dac 165 * @param input Unsigned char - range : 0..255
frankvnk 0:e742ad3d7dac 166 * @return none
frankvnk 0:e742ad3d7dac 167 */
frankvnk 17:048474f28d28 168 void FilterPeriod(unsigned char fipe);
frankvnk 0:e742ad3d7dac 169
frankvnk 18:efa8d41b738f 170 /** DMA Control.
frankvnk 18:efa8d41b738f 171 * Used to switch the DMA transfer triggered from the CMP module on/off.\n
frankvnk 18:efa8d41b738f 172 * When this field is set, a DMA request is asserted when CFR or CFF is set.\n
frankvnk 18:efa8d41b738f 173 * 0 DMA is disabled.\n
frankvnk 18:efa8d41b738f 174 * 1 DMA is enabled.\n
frankvnk 18:efa8d41b738f 175 * @param input Unsigned char - (0 = disable, 1 = enable)
frankvnk 0:e742ad3d7dac 176 * @return none
frankvnk 0:e742ad3d7dac 177 */
frankvnk 17:048474f28d28 178 void dma(unsigned char dmaen);
frankvnk 0:e742ad3d7dac 179
frankvnk 18:efa8d41b738f 180 /** Analog Comparator Output.
frankvnk 18:efa8d41b738f 181 * Returns the current value of the Analog Comparator output.\n
frankvnk 18:efa8d41b738f 182 * The field is reset to 0 and will read as CR1[INV] when the Analog Comparator\n
frankvnk 18:efa8d41b738f 183 * module is disabled, that is, when CR1[EN] = 0. Writes to this field are ignored.\n
frankvnk 0:e742ad3d7dac 184 * @param none
frankvnk 5:787a9f72600f 185 * @return comparator status (unsigned char)
frankvnk 0:e742ad3d7dac 186 */
frankvnk 0:e742ad3d7dac 187 unsigned char status(void);
frankvnk 0:e742ad3d7dac 188
frankvnk 18:efa8d41b738f 189 /** DAC Control.
frankvnk 18:efa8d41b738f 190 * Used to switch the internal DAC on/off. When the DAC is disabled, it is powered down to conserve power.\n
frankvnk 18:efa8d41b738f 191 * 0 DAC is disabled.\n
frankvnk 18:efa8d41b738f 192 * 1 DAC is enabled.\n
frankvnk 0:e742ad3d7dac 193 * @param input Unsigned char - 0 or 1
frankvnk 0:e742ad3d7dac 194 * @return none
frankvnk 0:e742ad3d7dac 195 */
frankvnk 17:048474f28d28 196 void dac(unsigned char den);
frankvnk 0:e742ad3d7dac 197
frankvnk 18:efa8d41b738f 198 /** Supply Voltage Reference Source Select.
frankvnk 18:efa8d41b738f 199 * 0 - V is selected as resistor ladder network supply reference Vin1 = VREFH\n
frankvnk 18:efa8d41b738f 200 * 1 - V is selected as resistor ladder network supply reference Vin2 = VDD\n
frankvnk 18:efa8d41b738f 201 * (Use this option for the best ADC operation).\n
frankvnk 0:e742ad3d7dac 202 * @param input Unsigned char - 0 or 1
frankvnk 0:e742ad3d7dac 203 * @return none
frankvnk 0:e742ad3d7dac 204 */
frankvnk 17:048474f28d28 205 void RefSource(unsigned char res);
frankvnk 0:e742ad3d7dac 206
frankvnk 18:efa8d41b738f 207 /** Set the detection threshold level (DAC Output Voltage Select).
frankvnk 18:efa8d41b738f 208 * Sets The 6-bit or 12-bit DAC output voltage, depending on which DAC is selected on init.\n
frankvnk 18:efa8d41b738f 209 * 6-bit DACO range is from Vin/64 to Vin.\n
frankvnk 18:efa8d41b738f 210 * 12-bit DACO range is from Vin/4096 to Vin.\n
frankvnk 13:2d499824ba05 211 * @param input float - range 0.0 .. 1.0
frankvnk 0:e742ad3d7dac 212 * @return none
frankvnk 0:e742ad3d7dac 213 */
frankvnk 13:2d499824ba05 214 void treshold(float vo_pct);
frankvnk 0:e742ad3d7dac 215
frankvnk 18:efa8d41b738f 216 /** Pass Through Mode Control.
frankvnk 18:efa8d41b738f 217 * Set the MUX pass through mode. Pass through mode is always available, but for\n
frankvnk 18:efa8d41b738f 218 * some devices, this feature must be always disabled due to the lack of package pins.\n
frankvnk 18:efa8d41b738f 219 * 0 Pass Through Mode is disabled.\n
frankvnk 18:efa8d41b738f 220 * 1 Pass Through Mode is enabled.\n
frankvnk 18:efa8d41b738f 221 * @param input Unsigned char - (0 = disable, 1 = enable)
frankvnk 0:e742ad3d7dac 222 * @return none
frankvnk 0:e742ad3d7dac 223 */
frankvnk 17:048474f28d28 224 void PassThrough(unsigned char ptm);
frankvnk 0:e742ad3d7dac 225
frankvnk 18:efa8d41b738f 226 /** Plus Input Mux Control.
frankvnk 18:efa8d41b738f 227 * Determines which input is selected for the plus input of the comparator.\n
frankvnk 18:efa8d41b738f 228 * For INx inputs, see CMP, DAC, and ANMUX block diagrams.\n
frankvnk 18:efa8d41b738f 229 * 0 : IN0 PTC6 CMP0_IN0\n
frankvnk 18:efa8d41b738f 230 * 1 : IN1 PTC7 CMP0_IN1\n
frankvnk 18:efa8d41b738f 231 * 2 : IN2 PTC8 CMP0_IN2\n
frankvnk 18:efa8d41b738f 232 * 3 : IN3 PTC9 CMP0_IN3\n
frankvnk 18:efa8d41b738f 233 * 4 : IN4 PTE30 CMP0_IN4 12-bit DAC0\n
frankvnk 18:efa8d41b738f 234 * 5 : IN5 PTE29 CMP0_IN5\n
frankvnk 18:efa8d41b738f 235 * 6 : IN6 - Bandgap reference (1V)\n
frankvnk 18:efa8d41b738f 236 * 7 : IN7 - Internal 6-bit DAC0\n
frankvnk 18:efa8d41b738f 237 * @note When an inappropriate operation selects the same input for both muxes, the comparator\n
frankvnk 18:efa8d41b738f 238 * automatically shuts down to prevent itself from becoming a noise generator.\n
frankvnk 18:efa8d41b738f 239 * @note When using the PMC bandgap 1V reference voltage as CMP input, ensure that\n
frankvnk 18:efa8d41b738f 240 * @you enable the bandgap buffer by setting the PMC_REGSC[BGBE] bit.\n
frankvnk 0:e742ad3d7dac 241 * @param input Unsigned char - range 0..7
frankvnk 0:e742ad3d7dac 242 * @return none
frankvnk 0:e742ad3d7dac 243 */
frankvnk 17:048474f28d28 244 void SwitchPlus(unsigned char pinP);
frankvnk 0:e742ad3d7dac 245
frankvnk 18:efa8d41b738f 246 /** Minus Input Mux Control.
frankvnk 18:efa8d41b738f 247 * Determines which input is selected for the plus input of the comparator.\n
frankvnk 18:efa8d41b738f 248 * For INx inputs, see CMP, DAC, and ANMUX block diagrams.\n
frankvnk 18:efa8d41b738f 249 * 0 : IN0 PTC6 CMP0_IN0\n
frankvnk 18:efa8d41b738f 250 * 1 : IN1 PTC7 CMP0_IN1\n
frankvnk 18:efa8d41b738f 251 * 2 : IN2 PTC8 CMP0_IN2\n
frankvnk 18:efa8d41b738f 252 * 3 : IN3 PTC9 CMP0_IN3\n
frankvnk 18:efa8d41b738f 253 * 4 : IN4 PTE30 CMP0_IN4 12-bit DAC0\n
frankvnk 18:efa8d41b738f 254 * 5 : IN5 PTE29 CMP0_IN5\n
frankvnk 18:efa8d41b738f 255 * 6 : IN6 - Bandgap reference (1V)\n
frankvnk 18:efa8d41b738f 256 * 7 : IN7 - Internal 6-bit DAC0\n
frankvnk 18:efa8d41b738f 257 * @note When an inappropriate operation selects the same input for both muxes, the comparator\n
frankvnk 18:efa8d41b738f 258 * automatically shuts down to prevent itself from becoming a noise generator.\n
frankvnk 18:efa8d41b738f 259 * @note When using the PMC bandgap 1V reference voltage as CMP input, ensure that
frankvnk 18:efa8d41b738f 260 * you enable the bandgap buffer by setting the PMC_REGSC[BGBE] bit.
frankvnk 0:e742ad3d7dac 261 * @param input Unsigned char - range 0..7
frankvnk 0:e742ad3d7dac 262 * @return none
frankvnk 0:e742ad3d7dac 263 */
frankvnk 17:048474f28d28 264 void SwitchMin(unsigned char pinM);
frankvnk 14:875486333dc2 265
frankvnk 18:efa8d41b738f 266 /** Comparator rising interrupt callback.
frankvnk 0:e742ad3d7dac 267 * @param pointer to the user function to execute after IRQ assertion
frankvnk 17:048474f28d28 268 * @param NULL to disable the interrupt
frankvnk 14:875486333dc2 269 * @return none
frankvnk 18:efa8d41b738f 270 * @note The interrupt is automatically enabled when a valid pointer is used.\n
frankvnk 18:efa8d41b738f 271 * The interrupt is automatically disabled when both risng and falling are set to NULL.
frankvnk 0:e742ad3d7dac 272 */
frankvnk 14:875486333dc2 273 void rising(void(*fptr)(void));
frankvnk 14:875486333dc2 274
frankvnk 18:efa8d41b738f 275 /** Comparator falling interrupt callback
frankvnk 14:875486333dc2 276 * @param pointer to the user function to execute after IRQ assertion
frankvnk 17:048474f28d28 277 * @param NULL to disable the interrupt
frankvnk 14:875486333dc2 278 * @return none
frankvnk 18:efa8d41b738f 279 * @note The interrupt is automatically enabled when a valid pointer is used.\n
frankvnk 18:efa8d41b738f 280 * The interrupt is automatically disabled when both risng and falling are set to NULL.
frankvnk 14:875486333dc2 281 */
frankvnk 14:875486333dc2 282 void falling(void(*fptr)(void));
frankvnk 0:e742ad3d7dac 283
frankvnk 0:e742ad3d7dac 284 private:
frankvnk 0:e742ad3d7dac 285 static const PinMap PinMap_CMP[7];
frankvnk 0:e742ad3d7dac 286 static void _cmpISR(void);
frankvnk 0:e742ad3d7dac 287 void hscmp_clear(void);
frankvnk 12:0a0648bddb98 288 PinName op_status(void);
frankvnk 12:0a0648bddb98 289 void op_enable(PinName pen, PinName pstat);
frankvnk 12:0a0648bddb98 290 void op_disable(PinName pdi);
frankvnk 13:2d499824ba05 291 void dac6_write(unsigned int value);
frankvnk 0:e742ad3d7dac 292 char CMPnumberP, CMPnumberM;
frankvnk 0:e742ad3d7dac 293 };
frankvnk 0:e742ad3d7dac 294
frankvnk 0:e742ad3d7dac 295 #endif
frankvnk 0:e742ad3d7dac 296
frankvnk 0:e742ad3d7dac 297
frankvnk 0:e742ad3d7dac 298