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:
Wed Jun 05 15:42:41 2013 +0000
Revision:
0:e742ad3d7dac
Child:
1:ccac56d8f1cb
KL25Z ComparatorIn - initial version

Who changed what in which revision?

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