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:
Thu Jun 06 19:42:05 2013 +0000
Revision:
8:8bc9784e04c0
Parent:
7:9a184ac2c65a
Child:
10:1b9ac2b8c788
ISR callback - doc update on return code

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