420 likes | 627 Views
Les 6 - onderwerpen. Ghosting Dender (bouncing) U(S)ART IR Toontjes en muziek motortjes Opdrachten: kies er (ten minste) 1. Ghosting bij multiplexen. Laat Digit 1 zien (wacht). Laat Digit 2 zien (wacht). Laat Digit 3 zien (wacht). Laat Digit 4 zien (wacht). Doe eventueel ander werk.
E N D
Les 6 - onderwerpen • Ghosting • Dender (bouncing) • U(S)ART • IR • Toontjes en muziek • motortjes • Opdrachten: kies er (ten minste) 1 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
Ghosting bij multiplexen Laat Digit 1 zien (wacht) Laat Digit 2 zien (wacht) Laat Digit 3 zien (wacht) Laat Digit 4 zien (wacht) Doe eventueel ander werk Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
Ghosting bij multiplexen Laat digit 1 zien: • Zet het nieuwe adres op RE0..RE2 • Zet het nieuwe segment-patroon op RD0..RD7 • Wacht 1 ms - Wat gaat hier (heel even) fout? - Hoe is dit op te lossen? Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
Switch bounce (denderen) Als je een drukknop indrukt maakt hij niet 1 keer contact: hij dendert een tijdje (maximaal ~ 50 ms)
PIC - USART USART = Universal Synchronous / Asynchronous Receiver + Transmitter • wij gebruiken asynchroon • PIC UART pins zijn verbonden met een FT232R USB-to-asynchronous converter • Op de PC wordt een (virtuele) seriele poort aangemaakt (XP en Vista hebben al een driver) control panel system hardware device manager ports • Evt. driver van www.ftdichip.com gebruiken • op de PC gebruik je een terminal, bv HyperTerminal (hypertrm, 19k2, no parity, no flow control, hu: com3 (?)) • In de image staat een icoon
PIC - USART DB038 manual 2.4
BRGH = 0 BRGH = 1 16F887 datasheet p 149-164
- 0 1 0 - 1 R - 16F887 datasheet p 149-164
1 0 - 1 0 R R - 16F887 datasheet p 149-164
PIC – USART - init make TxD (RC6) output, RxD (RC7) input SPBRG: 19k2 value for high speed TXSTA: 8 bit, enable, asynch, high speed RCSTA: enable, 8 bit, continuous, no ADDEN
PIC – USART - send • wacht tot TSR bit aangeeft dat TSR empty is • copy het te verzenden byte naar TXREG • (wacht tot TSR bit aangeeft dat TSR empty is)
PIC – USART - receive • als OERR bit gezet is: • clear CREN • wacht een paar instructies • set CREN • als PIR1 : TXIF op 0 gezet is: • lees RCREG, dit is het ontvangen byte (anders is er nog niets ontvangen)
PIC – USART – demo code subroutines UART_INIT : call to inistialise the UART for 19k2 UART_CHAR_SEND : sends the char in W UART_CHAR_RECEIVE : checks the UART for a received char, C flag set when a char is received (char in W), C flag is cleared when no char is received UART_CLRF_SEND : sends the CR LF sequence
PIC – USART – demo code main MAIN CALL UART_INIT MOVLW 'H' CALL UART_CHAR_SEND MOVLW 'i' CALL UART_CHAR_SEND CALL UART_CLRF_SEND MAIN_LOOP CALL UART_CHAR_RECEIVE SKPC GOTO MAIN_LOOP MOVWF Char MOVLW '"' CALL UART_CHAR_SEND MOVFW Char CALL UART_CHAR_SEND MOVLW '"' CALL UART_CHAR_SEND CALL UART_CLRF_SEND GOTO MAIN_LOOP Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
De IR ontvanger • RA2 must be a digital input • RE0..RE2 outputs, value 0b110 DB038 manual 2.8
De IR ontvanger • TFM5360 of TSOP1736 • (alleen) gevoelig voor een ~ 36 kHz signaal. • Dat signaal mag niet continu zijn (goed is bv.1 kHz: 500 us signaal, 500 us uit)
De IR ontvanger (alleen) gevoelig voor een 36 kHz signaal. Bij 10% afwijking, dus 33-40 kHz, 60% vd. Afstand.
De IR ontvanger Aanbevolen: puls >= 400uS, periode =< 0.4
Eenvoudig IR zenden / ontvangen • 36 kHz 28 us per puls 5 * 28 instructies per fase (hoog en laag) • 400 us / 28 us minimaal 14 pulsen, neem bv 30 pulsen • Onmiddelijk daarna de IR ingang lezen (laag == signaal gedetecteerd) • Pauze! (bv. 400 us) • herhaal
DB038 circuit – multiplexers DB038 manual 2.8 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
PIC – A/D A/D converter vertaald een analoge spanning naar een waarde 0..255 (8 bits) of 0..1023 (10 bits) RA0 16F887 datasheet p 99-108 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
PIC – A/D – configure pin as analog 16F887 datasheet p 99-108 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
PIC – A/D – aan zetten 16F887 datasheet p 99-108 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
PIC – A/D – channel 16F887 datasheet p 99-108 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
PIC – A/D – clock 16F887 datasheet p 99-108 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
PIC – A/D – start, wait 16F887 datasheet p 99-108 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
PIC – A/D – start, wait 16F887 datasheet p 99-108 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
PIC – A/D – enable, go / done 16F887 datasheet p 99-108 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
PIC – A/D – result format 16F887 datasheet p 99-108 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
Read an analog input • Zet de juiste code op poort RE • Configureer de pin (RA0) als input (TRISA) • Configureer de pin (RA0 = AN0) in ANSEL als analoog • Activeer de A/D, selecteer het betreffende kanaal, selecteer de conversie clock (ADCON0) • Selecteer VSS en VDD als referenties, en de alignment (ADCON1) • wacht 100 us • start de conversie (ADCON0) • wacht tot de conversie voltooid is (ADCON0) • lees het resultaat (ADRESH, eventueel ADRESL) Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
Hoogte en duur Met een punt er achter: 50% langer Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
nootnaam frequentie Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
C4 – ¼ E4 – ¼ C4 – ¼ E4 – ¼ C4 – ¼ E4 – ¼ G4 – 3/8 Stilte – 1/8 G4 – 3/8 F4 – 1/8 ... Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
DB038 - motortjes 37 Aansluitingen Driver chips Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
H-brug (H-bridge) 38 Motor 1 Motor 2 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
39 DB038 manual 2.19 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
40 Wat moet je op RC0..RC5 zetten om het onderstaande te bereiken: • Motor 1 (links) vooruit, motor 2 (rechts) vooruit • Links vooruit, rechts op de rem (bocht naar rechts) • Links achteruit, rechts vooruit (draai om de as naar links) DB038 manual 2.19 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
oefening 1 : toetsenbord, A/D, display, UART Schrijf een programma dat het toetsenbord leest, en de ingedrukte toets laat zien op het meest linker display. De ingedrukte toets bepaalt het A/D kanaal dat wordt gelezen, en (hexadecimaal) wordt weergegeven op de rechter 2 displays, en verstuurd naar de PC via de UART. Hogeschool Utrecht / Institute for Computer, Communication and Media Technology
oefening 2 : IR Maak een IR-reflex detector. Zend een korte IR puls, lees de IR receiver uit, en laat het resultaat zien (bv op de Leds). oefening 3 : melodie Laateenkortstukje van een (bekende) melodiehoren. Hogeschool Utrecht / Institute for Computer, Communication and Media Technology