ejemplo de leer encoder con bluepill stm32f411
Dependencies: mbed QEI Debounced TextLCD
EJEMPLO USANDO LA PLACA STM32F411CEU6
La intencion es leer un encoder rotatorio de arduino prestar atencion a las fases algo de inestabilidad por ruido, posibles ajustes pulsos por revolucion e insertar condensadores de filtro en las fases
main.cpp@0:401dcb5672a4, 2022-07-21 (annotated)
- Committer:
- tony63
- Date:
- Thu Jul 21 00:46:15 2022 +0000
- Revision:
- 0:401dcb5672a4
Ejemplo con la placa bluepill STM32F411
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tony63 | 0:401dcb5672a4 | 1 | #include "mbed.h" |
tony63 | 0:401dcb5672a4 | 2 | #include "DebouncedIn.h" |
tony63 | 0:401dcb5672a4 | 3 | #include "TextLCD.h" |
tony63 | 0:401dcb5672a4 | 4 | #include "QEI.h" |
tony63 | 0:401dcb5672a4 | 5 | |
tony63 | 0:401dcb5672a4 | 6 | |
tony63 | 0:401dcb5672a4 | 7 | TextLCD lcd(PA_8,PA_9,PB_12,PB_13,PB_14,PB_15); // rs, e, d4-d7 |
tony63 | 0:401dcb5672a4 | 8 | QEI wheel (PB_0,PB_1, NC, 100); |
tony63 | 0:401dcb5672a4 | 9 | |
tony63 | 0:401dcb5672a4 | 10 | |
tony63 | 0:401dcb5672a4 | 11 | //DebouncedIn button1(PTC12); |
tony63 | 0:401dcb5672a4 | 12 | //ebouncedIn button2(PTC13); |
tony63 | 0:401dcb5672a4 | 13 | |
tony63 | 0:401dcb5672a4 | 14 | |
tony63 | 0:401dcb5672a4 | 15 | int C1=0x0E; // solo muestra el curzor |
tony63 | 0:401dcb5672a4 | 16 | int C2=0x18; // desplaza izquierda |
tony63 | 0:401dcb5672a4 | 17 | int C3=0x1A; // desplaza derecha |
tony63 | 0:401dcb5672a4 | 18 | int C4=0x0C; // quito cursor bajo |
tony63 | 0:401dcb5672a4 | 19 | |
tony63 | 0:401dcb5672a4 | 20 | |
tony63 | 0:401dcb5672a4 | 21 | int i; // indice de la variable |
tony63 | 0:401dcb5672a4 | 22 | DigitalIn CHA(PB_0, PullUp); |
tony63 | 0:401dcb5672a4 | 23 | DigitalIn CHB(PB_1, PullUp); |
tony63 | 0:401dcb5672a4 | 24 | |
tony63 | 0:401dcb5672a4 | 25 | int main() { |
tony63 | 0:401dcb5672a4 | 26 | lcd.cls(); |
tony63 | 0:401dcb5672a4 | 27 | |
tony63 | 0:401dcb5672a4 | 28 | lcd.locate(0,0); |
tony63 | 0:401dcb5672a4 | 29 | lcd.printf("CONTEO="); |
tony63 | 0:401dcb5672a4 | 30 | while(1) |
tony63 | 0:401dcb5672a4 | 31 | { |
tony63 | 0:401dcb5672a4 | 32 | lcd.locate(7,0); |
tony63 | 0:401dcb5672a4 | 33 | lcd.printf("%d",wheel.getPulses()); |
tony63 | 0:401dcb5672a4 | 34 | lcd.locate(7,0); |
tony63 | 0:401dcb5672a4 | 35 | wait(0.5); |
tony63 | 0:401dcb5672a4 | 36 | lcd.printf(" "); |
tony63 | 0:401dcb5672a4 | 37 | } |
tony63 | 0:401dcb5672a4 | 38 | } |