KL25Z Comparator demo
Dependencies: ComparatorIn mbed
main.cpp@2:bb19e60cb933, 2013-06-16 (annotated)
- Committer:
- frankvnk
- Date:
- Sun Jun 16 15:17:56 2013 +0000
- Revision:
- 2:bb19e60cb933
- Parent:
- 1:fb35e688f9f4
- Child:
- 4:07dd82e3f934
added 12-bit DAC demo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
frankvnk | 2:bb19e60cb933 | 1 | #include "ComparatorIn.h" |
frankvnk | 2:bb19e60cb933 | 2 | #include "mbed.h" |
frankvnk | 2:bb19e60cb933 | 3 | |
frankvnk | 2:bb19e60cb933 | 4 | DigitalOut blinker (LED_BLUE); |
frankvnk | 2:bb19e60cb933 | 5 | DigitalOut cmpled (LED_GREEN); |
frankvnk | 2:bb19e60cb933 | 6 | DigitalOut cmp_en (PTD5); |
frankvnk | 2:bb19e60cb933 | 7 | AnalogIn cmp_lvl (PTB0); |
frankvnk | 2:bb19e60cb933 | 8 | ComparatorIn compi(PTC8, PTE30); // in+ = PTC8, in- = 12-bit DAC |
frankvnk | 2:bb19e60cb933 | 9 | |
frankvnk | 2:bb19e60cb933 | 10 | // Comparator callback functions |
frankvnk | 2:bb19e60cb933 | 11 | void cmp_rise_ISR(void) |
frankvnk | 2:bb19e60cb933 | 12 | { |
frankvnk | 2:bb19e60cb933 | 13 | cmpled = 0; |
frankvnk | 2:bb19e60cb933 | 14 | } |
frankvnk | 2:bb19e60cb933 | 15 | |
frankvnk | 2:bb19e60cb933 | 16 | void cmp_fall_ISR(void) |
frankvnk | 2:bb19e60cb933 | 17 | { |
frankvnk | 2:bb19e60cb933 | 18 | cmpled = 1; |
frankvnk | 2:bb19e60cb933 | 19 | } |
frankvnk | 2:bb19e60cb933 | 20 | |
frankvnk | 2:bb19e60cb933 | 21 | |
frankvnk | 2:bb19e60cb933 | 22 | |
frankvnk | 2:bb19e60cb933 | 23 | int main() |
frankvnk | 2:bb19e60cb933 | 24 | { |
frankvnk | 2:bb19e60cb933 | 25 | cmp_en = 1; |
frankvnk | 2:bb19e60cb933 | 26 | cmpled = 1; |
frankvnk | 2:bb19e60cb933 | 27 | |
frankvnk | 2:bb19e60cb933 | 28 | compi.rising(&cmp_rise_ISR); // Set pointer to rising interrupt function |
frankvnk | 2:bb19e60cb933 | 29 | compi.falling(&cmp_fall_ISR); // Set pointer to falling interrupt function |
frankvnk | 2:bb19e60cb933 | 30 | compi.treshold(0.3); // Set comparator threshold to 1V = 0.3 * 3.3V |
frankvnk | 2:bb19e60cb933 | 31 | compi.int_en(1); // Enable comparator interrupts |
frankvnk | 2:bb19e60cb933 | 32 | |
frankvnk | 2:bb19e60cb933 | 33 | while(1) |
frankvnk | 2:bb19e60cb933 | 34 | { |
frankvnk | 2:bb19e60cb933 | 35 | printf("Light sensor : %7.5f Volt\n",cmp_lvl*3.3); |
frankvnk | 2:bb19e60cb933 | 36 | blinker = 1; |
frankvnk | 2:bb19e60cb933 | 37 | wait(1); |
frankvnk | 2:bb19e60cb933 | 38 | blinker = 0; |
frankvnk | 2:bb19e60cb933 | 39 | wait(0.2); |
frankvnk | 2:bb19e60cb933 | 40 | if (compi.status() == 0x01) |
frankvnk | 2:bb19e60cb933 | 41 | { |
frankvnk | 2:bb19e60cb933 | 42 | printf("*** Treshold reached : %7.5f\n",cmp_lvl*3.3); |
frankvnk | 2:bb19e60cb933 | 43 | } |
frankvnk | 2:bb19e60cb933 | 44 | } |
frankvnk | 2:bb19e60cb933 | 45 | } |
frankvnk | 2:bb19e60cb933 | 46 | |
frankvnk | 2:bb19e60cb933 | 47 | |
frankvnk | 2:bb19e60cb933 | 48 |