KL25Z Comparator demo
Dependencies: ComparatorIn mbed
main.cpp@6:59d91df28f63, 2013-08-25 (annotated)
- Committer:
- frankvnk
- Date:
- Sun Aug 25 18:01:58 2013 +0000
- Revision:
- 6:59d91df28f63
- Parent:
- 4:07dd82e3f934
library : _fptr names were too generic. Added comparatorin_ to each name.
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 | |
frankvnk | 2:bb19e60cb933 | 32 | while(1) |
frankvnk | 2:bb19e60cb933 | 33 | { |
frankvnk | 2:bb19e60cb933 | 34 | printf("Light sensor : %7.5f Volt\n",cmp_lvl*3.3); |
frankvnk | 2:bb19e60cb933 | 35 | blinker = 1; |
frankvnk | 2:bb19e60cb933 | 36 | wait(1); |
frankvnk | 2:bb19e60cb933 | 37 | blinker = 0; |
frankvnk | 2:bb19e60cb933 | 38 | wait(0.2); |
frankvnk | 2:bb19e60cb933 | 39 | if (compi.status() == 0x01) |
frankvnk | 2:bb19e60cb933 | 40 | { |
frankvnk | 2:bb19e60cb933 | 41 | printf("*** Treshold reached : %7.5f\n",cmp_lvl*3.3); |
frankvnk | 2:bb19e60cb933 | 42 | } |
frankvnk | 2:bb19e60cb933 | 43 | } |
frankvnk | 2:bb19e60cb933 | 44 | } |
frankvnk | 2:bb19e60cb933 | 45 | |
frankvnk | 2:bb19e60cb933 | 46 | |
frankvnk | 2:bb19e60cb933 | 47 |