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:
Fri Jun 07 18:10:23 2013 +0000
Revision:
10:1b9ac2b8c788
Parent:
8:8bc9784e04c0
Child:
12:0a0648bddb98
removed version info from comments

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