1 / 42

Les 6 - onderwerpen

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.

Download Presentation

Les 6 - onderwerpen

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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

  3. 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

  4. Switch bounce (denderen) Als je een drukknop indrukt maakt hij niet 1 keer contact: hij dendert een tijdje (maximaal ~ 50 ms)

  5. 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

  6. PIC - USART DB038 manual 2.4

  7. 16F887 datasheet p 149-164

  8. BRGH = 0 BRGH = 1 16F887 datasheet p 149-164

  9. - 0 1 0 - 1 R - 16F887 datasheet p 149-164

  10. 1 0 - 1 0 R R - 16F887 datasheet p 149-164

  11. 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

  12. 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)

  13. 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)

  14. power van de 2e USB poort

  15. 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

  16. 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

  17. De IR ontvanger • RA2 must be a digital input • RE0..RE2 outputs, value 0b110 DB038 manual 2.8

  18. 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)

  19. De IR ontvanger (alleen) gevoelig voor een 36 kHz signaal. Bij 10% afwijking, dus 33-40 kHz, 60% vd. Afstand.

  20. De IR ontvanger Aanbevolen: puls >= 400uS, periode =< 0.4

  21. De IR ontvanger

  22. 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

  23. DB038 circuit – multiplexers DB038 manual 2.8 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  24. 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

  25. PIC – A/D – configure pin as analog 16F887 datasheet p 99-108 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  26. PIC – A/D – aan zetten 16F887 datasheet p 99-108 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  27. PIC – A/D – channel  16F887 datasheet p 99-108 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  28. PIC – A/D – clock 16F887 datasheet p 99-108 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  29. PIC – A/D – start, wait 16F887 datasheet p 99-108 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  30. PIC – A/D – start, wait   16F887 datasheet p 99-108 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  31. PIC – A/D – enable, go / done 16F887 datasheet p 99-108 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  32. PIC – A/D – result format 16F887 datasheet p 99-108 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  33. 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

  34. Hoogte en duur Met een punt er achter: 50% langer Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  35. nootnaam  frequentie Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  36. 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

  37. DB038 - motortjes 37 Aansluitingen Driver chips Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  38. H-brug (H-bridge) 38 Motor 1 Motor 2 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  39. 39 DB038 manual 2.19 Hogeschool Utrecht / Institute for Computer, Communication and Media Technology

  40. 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

  41. 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

  42. 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

More Related