OpenMoCo
/
QEIx4_Example
QEIx4 Example
main.cpp@0:bbf48777e304, 2014-09-02 (annotated)
- Committer:
- jocis
- Date:
- Tue Sep 02 18:24:13 2014 +0000
- Revision:
- 0:bbf48777e304
- Child:
- 2:7c787d83331e
Added documentation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jocis | 0:bbf48777e304 | 1 | #include "mbed.h" |
jocis | 0:bbf48777e304 | 2 | #include "QEIx4.h" |
jocis | 0:bbf48777e304 | 3 | |
jocis | 0:bbf48777e304 | 4 | DigitalOut myled(LED1); |
jocis | 0:bbf48777e304 | 5 | Timer t; |
jocis | 0:bbf48777e304 | 6 | |
jocis | 0:bbf48777e304 | 7 | // ports for nxp LPC 1768 |
jocis | 0:bbf48777e304 | 8 | QEIx4 qei1(p30, p29, p28); // QEI with index signal for zeroing |
jocis | 0:bbf48777e304 | 9 | QEIx4 qei2(p27, p26, NC); // QEI only with AB signals |
jocis | 0:bbf48777e304 | 10 | QEIx4 qei3(p25, p24, NC, false); // QEI without interrups for polling mode |
jocis | 0:bbf48777e304 | 11 | |
jocis | 0:bbf48777e304 | 12 | int main() { |
jocis | 0:bbf48777e304 | 13 | t.start(); |
jocis | 0:bbf48777e304 | 14 | |
jocis | 0:bbf48777e304 | 15 | qei1.SetZeroOnIndex(true); // Set the flag to zero counter on next index signal rises |
jocis | 0:bbf48777e304 | 16 | |
jocis | 0:bbf48777e304 | 17 | while(1) |
jocis | 0:bbf48777e304 | 18 | { |
jocis | 0:bbf48777e304 | 19 | qei3.poll(); // poll manually without interrupt - sampling in this loop with about 2kHz |
jocis | 0:bbf48777e304 | 20 | |
jocis | 0:bbf48777e304 | 21 | if ( t.read_ms() > 500 ) // every half second |
jocis | 0:bbf48777e304 | 22 | { |
jocis | 0:bbf48777e304 | 23 | t.reset(); |
jocis | 0:bbf48777e304 | 24 | t.start(); |
jocis | 0:bbf48777e304 | 25 | myled = !myled; |
jocis | 0:bbf48777e304 | 26 | |
jocis | 0:bbf48777e304 | 27 | printf ( "\r\n%6d %6d %6d", (int)qei1, (int)qei2, (int)qei3 ); // print counter values |
jocis | 0:bbf48777e304 | 28 | } |
jocis | 0:bbf48777e304 | 29 | |
jocis | 0:bbf48777e304 | 30 | wait_us(500); // for about 2kHz |
jocis | 0:bbf48777e304 | 31 | } |
jocis | 0:bbf48777e304 | 32 | } |