งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

ADC & UART.

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "ADC & UART."— ใบสำเนางานนำเสนอ:

1 ADC & UART

2 Analog & Digital Signal
Analog Signal Digital Signal Digital Signal

3 Analog to Digital Converter
Sampling and Hold Quantize

4 Sampling Rate Selection
fs >= 2 Bandwidth

5 Sampling Rate Selection
Resolution LSB = (Vref+-Vref-)/2k

6 ADC ชนิด Successive Approximation

7 ADC ของ PIC18F8722 PIC18F8722 มีวงจร Analog to Digital Converter ขนาด 10 bit ทั้งหมด 16 วงจร (AN0-AN15)

8 ADC ของ PIC18F8722

9 ADC ของ PIC18F8722

10 ADC ของ PIC18F8722

11 Register ของ ADC PIC มี Register ที่เกี่ยวกับ ADC ทั้งหมด 5 ตัวคือ
A/D Result High Register (ADRESH) A/D Result Low Register (ADRESL) A/D Control Register 0 (ADCON0) A/D Control Register 1 (ADCON1) A/D Control Register 2 (ADCON2)

12 ADRESH และ ADRESL ADRESH และ ADRESL เป็น Register ที่ใช้เก็บผลลัพธ์ของการ แปลง ADC

13 ADCON0 ADCON0 เป็น Register ที่ใช้กำหนดว่าจะให้วงจร VAin ของวงจร ADC ต่อกับ AN ตัวที่เท่าใด (CHS3:0) สั่งให้ ADC เริ่มทำงาน Go/DONE และตรวจสอบว่า ADC ทำงานเสร็จหรือยัง ADON

14 ADCON0

15 ADCON1 ADCON1 เป็น Register ที่ใช้กำหนดให้ AN ตัวใดทำงานเป็น Analog Input Port หรือทำงานเป็น Digital I/O Port (PCFG3:0) และกำหนดให้ RA3/AN3 เป็น VRef+ และ RA2/AN2 เป็น VRef- (VCFG1:0)

16 ADCON1

17 ADCON2 ADCON2 เป็น Register ที่ ใช้กำหนด Acquisitio n Time ของวงจร ADC

18 Acquisition Time สัญญาณ Analog จะถูกป้อนผ่านสวิทซ์ไปเข้าที่ขา VAin ของวงจร ADC จากนั้น CHOLD จะถูกชาร์จประจุให้มีแรงดันเท่ากับขา VAin

19 Acquisition Time เพื่อให้การแปลง ADC มีความถูกต้อง จะต้องให้แรงดันของ CHOLD เท่ากับ VAin เนื่องจาก VAin ชาร์จประจุ CHOLD ผ่าน RS, RSS ดังนั้นจึงต้องใช้เวลาใน การชาร์จประจุ เราเรียกเวลาดังกล่าวว่า Acquisition Time (TACQ)

20 Acquisition Time

21 เราสามารถตั้งค่า Acquisition Time ได้จาก ACQT<2:0>
เมื่อเซ็ทให้ GO/DONE = 1 PIC จะรอเป็นเท่ากับ Acquisition Time จากนั้นจึงเริ่มแปลง ADC และเมื่อแปลง ADC เสร็จแล้ว GO/DONE จะเท่ากับ 0

22 ขั้นตอนการแปลง ADC

23 #include <p18f8722.h> #include <adc.h> #include <delays.h> #include <timers.h> #define NUMBER_OF_LEDS 8 #pragma code int result; int shift; void main(void) { TRISAbits.TRISA0=1; TRISD = 0; PORTD = 0; ADCON1 = 0b ; ADCON2 = 0b ; ADCON0bits.ADON = 1; while(1) { ADCON0bits.GO=1; while(ADCON0bits.GO); result = ADRES; result >>=2; if(result==0) result = 1; // PORTD = result; PORTD=1<<shift; shift++; shift %=8; Delay10KTCYx(20); }

24 การสื่อสารแบบดิจิตอล
การสื่อสารแบบดิจิตอลสามารถแบ่งออกเป็น 2 กลุ่มคือ การสื่อสารแบบขนาน (Parallel Communication) IEEE 488 หรือ General Purpose Interface Bus (GPIB) IEEE 1248 หรือ Centronics Parallel Protocol SCSI (Small Computer System Interface) IDE (Integrated Drive Electronics) ISA (Industrial Standard Architecture) PCI (Peripheral Component Interconnect) AGP (Accelerated Graphics Port)

25 การสื่อสารแบบดิจิตอล
การสื่อสารแบบอนุกรม (Serial Communication) RS 232 RS 422 RS 485 UART (Universal Asynchronous receiver-transmitter) USART (Universal Synchronous- Asynchronous receiver-transmitter) MIDI IEEE1394 หรือ FireWire CAN (Controller Area Network) USB (Universal Serial Bus) I2C (Inter Integrated Circuit) SPI (Serial Peripheral Interface bus) Micro-wire Ethernet Fiber optics Bluetooth WiFi

26 เปรียบเทียบการสื่อสารแบบขนานและอนุกรม
การสื่อสารแบบขนานสามารถรับส่งข้อมูลได้เร็วกว่าการสื่อสารแบบอนุกรม เนื่องจากสามารถรับส่งข้อมูลได้หลายบิทพร้อมกัน การสื่อสารแบบขนานใช้จำนวน Port มากกว่าการสื่อสารแบบอนุกรม การสื่อสารแบบขนานสามารถรับส่งข้อมูลได้สั้นกว่าแบบอนุกรมเนื่องจาก เกิดสัญญาณ Crosstalk ขึ้นระหว่างสายสัญญาณแต่ละเส้น

27 Universal Asynchronous Receiver and Transmitter (UART)
Transmit (TX) ใช้ในการส่งข้อมูล Receiver (RX) ใช้ในการรับข้อมูล สามารถรับส่งข้อมูลได้ 2 โหมดคือ 8 bit-Transmission ประกอบด้วย 1 start bit, 8-bit data, 1 stop

28 Universal Asynchronous Receiver and Transmitter (UART)
9 bit-Transmission ประกอบด้วย 1 start, 9-bit Data (บิทที่ 8 มักใช้ เป็น parity bit), 1 stop Bit parity Bit ใช้ในการตรวจสอบความ ถูกต้องของข้อมูล มีอยู่ 2 แบบคือ even parity, parity bit = 1 ถ้า จำนวนบิทข้อมูลที่เป็น 1 เป็นเลขคี่ odd parity, parity bit = 1 ถ้า จำนวนบิทข้อมูลที่เป็น 1 เป็นเลขคู่

29 Universal Asynchronous Receiver and Transmitter (UART)
BAUD Rate หมายถึงจำนวนบิททั้งหมด (start + stop + data + parity) ที่สามารถรับส่งได้ใน 1 วินาที BAUD Rate มาตรฐานมีดังนี้ 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, , และ

30 Register ที่เกี่ยวข้อง

31 Register ที่เกี่ยวข้อง

32 Register ที่เกี่ยวข้อง

33 ตารางการเซ็ท Configuration Bit สำหรับ คำนวณ BAUD Rate
Configuration Bits BRG/EUSART Mode BAUD Rate Formula SYNC BRG16 BRGH 8-bit/Asynchronous Fosc/[64(n+1)] 1 Fosc/[16(n+1)] 16-bit/Asynchronous Fosc/[4(n+1)] x 8-bit/Synchronous 16-bit/Synchronous n = SPBRGx (8-bit Asynchronous) หรือ n = SPBRGHx:SPBRGx (16-bit Asynchronous

34 วิธีการคำนวณ BAUD Rate
n=SPBRGHx:SPBRGx

35 ตัวอย่างการคำนวณ BAUD Rate

36 void UART_Init(void) { BRGH = 1; BRG16 = 0; SPBRG = 25; SYNC = 0; //Setting Asynchronous Mode, ie UART SPEN = 1; //Enables Serial Port TRISC7 = 1; //As Prescribed in Datasheet TRISC6 = 0; //As Prescribed in Datasheet CREN = 1; //Enables Continuous Reception TXEN = 1; //Enables Transmission } void UART_Write(char data) { while(!TRMT); TXREG = data; } char UART_TX_Empty() return TRMT; void UART_Write_Text(char *text) int i; for(i=0;text[i]!='\0';i++) UART_Write(text[i]);

37 char UART_Data_Ready() { return RCIF; } char UART_Read() while(
char UART_Data_Ready() { return RCIF; } char UART_Read() while(!RCIF); return RCREG; void UART_Read_Text(char *Output, unsigned int length) unsigned int i; for(int i=0;i<length;i++) Output[i] = UART_Read();

38 #define _XTAL_FREQ 8000000 #include <xc
#define _XTAL_FREQ #include <xc.h> #include <pic18f8722.h> #include "uart.h" // BEGIN CONFIG #pragma config FOSC = HS #pragma config WDTE = OFF #pragma config PWRTE = OFF #pragma config BOREN = ON #pragma config LVP = OFF #pragma config CPD = OFF #pragma config WRT = OFF #pragma config CP = OFF //END CONFIG void main() { TRISB = 0xFF; //PORTB as Input nRBPU = 0; //Enables PORTB Internal Pull Up Resistors UART_Init(); do UART_Write(PORTB); __delay_ms(100); } while(1); } #define _XTAL_FREQ #include <xc.h> #include <pic18f8722.h> #include "uart.h" // BEGIN CONFIG #pragma config FOSC = HS #pragma config WDTE = OFF #pragma config PWRTE = OFF #pragma config BOREN = ON #pragma config LVP = OFF #pragma config CPD = OFF #pragma config WRT = OFF #pragma config CP = OFF //END CONFIG void main() { TRISB = 0x00; //PORTB as Output UART_Init(); do if(UART_Data_Ready()) PORTB = UART_Read(); __delay_ms(100); }while(1); }


ดาวน์โหลด ppt ADC & UART.

งานนำเสนอที่คล้ายกัน


Ads by Google