CONVERSOR ANALÓGICO
DIGITAL DEL PIC16F877
RODRÍGUEZ BALLESTEROS NELSON ROBERTO
ARREOLA ROJAS JESUS SALVADOR
Tanto nuestra voz como muchas de las señales que se envían a través
de un medio guiado
como un cable o no guiado como es el aire son de tipo continuo y
pueden tomar infinitos valores a
lo largo del tiempo.
 El muestreo implica que tenemos que coger una muestra de la
señal cada T segundos ya que no hay memoria suficiente capaz de
almacenar los infinitos puntos de una señal en un intervalo
cualquiera de tiempo
 Estos valores van a depender del número de bits que vayamos a
almacenar para cada muestra, por ejemplo, en la imagen se
cogen 4 bits y con ellos se pueden formar 16 combinaciones y por
lo tanto 16 distintos niveles en los que se puede dividir el eje. El PIC
cuantifica con 10 bits luego son 1023 niveles
ERROR DE CUANTIFICACIÓN
 El parámetro fundamental del muestreo digital es el intervalo de
muestreo ▲seg., o su equivalente frecuencia de muestreo 1/▲ Hz.
 cuanto menor sea ▲, mayor número de valores obtendremos de la
señal, y viceversa
 la obtención de una serie discreta ordenada {xr} = {x0, x1, x3,...,
xr,...}, en la que el índice r indica la posición de orden temporal del
valor xr. Así, el valor de la señal original, en el tiempo t = ▲r, x (t), se
representa por xr.
 temp
 ; This code if for the TC74A5-5.0VAT temperature sensor
 ; 1st. Check if temperature is ready to be read in config reg.
 ; 2nd. If ready, retireve temperatute in hex.
 ; If not ready, check config register again.
 banksel TRISC ;initialize MSSP module
 bsf TRISC,3
 bsf TRISC,4
 movlw B'00101000'
 banksel SSPCON
 movwf SSPCON
 banksel SSPSTAT
 bsf SSPSTAT,SMP
 movlw .5
 movwf SSPADD
 banksel PIR1
 bcf PIR1,TMR1IF
 clrf TMR1H ;load regs for 2 sec overflow
 clrf TMR1L
 get_temp
 banksel cmd_byte
 movlw 0x01 ;config register command byte
 movwf cmd_byte
 temp_now
 banksel SSPCON2 ;write to TC74
 bsf SSPCON2,SEN
 btfsc SSPCON2,SEN
 goto $-1
 movlw B'10011010' ;send TC74 ADDRESS (write)
 banksel SSPBUF
 movwf SSPBUF
 call ssprw
 banksel SSPCON2
 btfsc SSPCON2,ACKSTAT ;ack?
 goto $-1
 banksel cmd_byte
 movf cmd_byte,w ;send COMMAND byte (config)
 banksel SSPBUF
 movwf SSPBUF
 call ssprw
 banksel SSPCON2
 btfsc SSPCON2,ACKSTAT ;ack?
 goto $-1
 bsf SSPCON2,RSEN ;send repeated start
 btfsc SSPCON2,RSEN
 goto $-1
 movlw B'10011011' ;send TC74 ADDRESS (read)
 banksel SSPBUF
 movwf SSPBUF
 call ssprw ;module idle?
 banksel SSPCON2
 btfsc SSPCON2,ACKSTAT ;ack?
 goto $-1
 bsf SSPCON2,RCEN ;enable receive mode
 btfsc SSPCON2,RCEN
 goto $-1
 banksel SSPBUF ;retrieve config reg or temp reg
 movf SSPBUF,w

 banksel SSPCON2 ;send NOT-ACK
 bsf SSPCON2,ACKDT
 bsf SSPCON2,ACKEN
 btfsc SSPCON2,ACKEN
 goto $-1

 bsf SSPCON2,PEN ;stop
 btfsc SSPCON2,PEN
 goto $-1

 banksel cmd_byte ;config command OR temp
command
 btfss cmd_byte,0
 goto convert_temp ;get temperature ready for display
 andlw 0x40
 sublw 0x40
 btfss STATUS,Z ;is temp ready ??
 goto get_temp ;NO, try again
 movlw 0x00 ;YES, send temp command
 banksel cmd_byte ;send temp register command
 movwf cmd_byte
 goto temp_now
 convert_temp
 movwf temperature
 call bin_bcd ;NO, get temp ready for LCD
 call LCDLine_1

 movlw A'T' ;send "Temp=" to LCD
 movwf temp_wr
 call d_write
 movlw A'e'
 movwf temp_wr
 call d_write
 movlw A'm'
 movwf temp_wr
 call d_write
 movlw A'p'
 movwf temp_wr
 call d_write
 movlw 0x20 ;space
 movwf temp_wr
 call d_write
 movlw A'='
 movwf temp_wr
 call d_write
 movlw 0x20 ;space
 movwf temp_wr
Instrucción
cambio de señal
 call d_write
 movf MSD,w ;send high digit
 movwf temp_wr
 call d_write
 movf MsD,w ;send middle digit
 movwf temp_wr
 call d_write
 movf LSD,w ;send low digit
 movwf temp_wr
 call d_write
 movlw A'C' ;send "C" for Celsius
 movwf temp_wr
 call d_write
 movlw 0x20 ;space
 movwf temp_wr
 call d_write
 movlw 0x20 ;space
 movwf temp_wr
 call d_write
 movlw 0x20 ;space
 movwf temp_wr
 call d_write
 call LCDLine_2 ;send "RB0 = Exit" to LCD
 banksel ptr_pos
 movlw .144
 movwf ptr_pos
 call stan_char_2

 btfss select ;wait for RB0 release
 goto $-1
 call delay_100ms
 btfss select ;exit ?
 goto menu_clock ;YES, goto main menu
 btfsc PIR1, TMR1IF ;2 second overflow occur ??
 call write_eeprom ;YES
 goto get_temp ;NO, get temperature again
Medidor de temperatura

Conversor analógico

  • 1.
    CONVERSOR ANALÓGICO DIGITAL DELPIC16F877 RODRÍGUEZ BALLESTEROS NELSON ROBERTO ARREOLA ROJAS JESUS SALVADOR
  • 2.
    Tanto nuestra vozcomo muchas de las señales que se envían a través de un medio guiado como un cable o no guiado como es el aire son de tipo continuo y pueden tomar infinitos valores a lo largo del tiempo.
  • 3.
     El muestreoimplica que tenemos que coger una muestra de la señal cada T segundos ya que no hay memoria suficiente capaz de almacenar los infinitos puntos de una señal en un intervalo cualquiera de tiempo
  • 4.
     Estos valoresvan a depender del número de bits que vayamos a almacenar para cada muestra, por ejemplo, en la imagen se cogen 4 bits y con ellos se pueden formar 16 combinaciones y por lo tanto 16 distintos niveles en los que se puede dividir el eje. El PIC cuantifica con 10 bits luego son 1023 niveles
  • 5.
    ERROR DE CUANTIFICACIÓN El parámetro fundamental del muestreo digital es el intervalo de muestreo ▲seg., o su equivalente frecuencia de muestreo 1/▲ Hz.  cuanto menor sea ▲, mayor número de valores obtendremos de la señal, y viceversa  la obtención de una serie discreta ordenada {xr} = {x0, x1, x3,..., xr,...}, en la que el índice r indica la posición de orden temporal del valor xr. Así, el valor de la señal original, en el tiempo t = ▲r, x (t), se representa por xr.
  • 6.
     temp  ;This code if for the TC74A5-5.0VAT temperature sensor  ; 1st. Check if temperature is ready to be read in config reg.  ; 2nd. If ready, retireve temperatute in hex.  ; If not ready, check config register again.  banksel TRISC ;initialize MSSP module  bsf TRISC,3  bsf TRISC,4  movlw B'00101000'  banksel SSPCON  movwf SSPCON  banksel SSPSTAT  bsf SSPSTAT,SMP  movlw .5  movwf SSPADD  banksel PIR1  bcf PIR1,TMR1IF
  • 7.
     clrf TMR1H;load regs for 2 sec overflow  clrf TMR1L  get_temp  banksel cmd_byte  movlw 0x01 ;config register command byte  movwf cmd_byte  temp_now  banksel SSPCON2 ;write to TC74  bsf SSPCON2,SEN  btfsc SSPCON2,SEN  goto $-1  movlw B'10011010' ;send TC74 ADDRESS (write)  banksel SSPBUF  movwf SSPBUF  call ssprw  banksel SSPCON2  btfsc SSPCON2,ACKSTAT ;ack?  goto $-1  banksel cmd_byte  movf cmd_byte,w ;send COMMAND byte (config)  banksel SSPBUF  movwf SSPBUF  call ssprw  banksel SSPCON2  btfsc SSPCON2,ACKSTAT ;ack?  goto $-1  bsf SSPCON2,RSEN ;send repeated start  btfsc SSPCON2,RSEN  goto $-1  movlw B'10011011' ;send TC74 ADDRESS (read)  banksel SSPBUF  movwf SSPBUF  call ssprw ;module idle?  banksel SSPCON2  btfsc SSPCON2,ACKSTAT ;ack?  goto $-1  bsf SSPCON2,RCEN ;enable receive mode  btfsc SSPCON2,RCEN  goto $-1  banksel SSPBUF ;retrieve config reg or temp reg  movf SSPBUF,w   banksel SSPCON2 ;send NOT-ACK
  • 8.
     bsf SSPCON2,ACKDT bsf SSPCON2,ACKEN  btfsc SSPCON2,ACKEN  goto $-1   bsf SSPCON2,PEN ;stop  btfsc SSPCON2,PEN  goto $-1   banksel cmd_byte ;config command OR temp command  btfss cmd_byte,0  goto convert_temp ;get temperature ready for display  andlw 0x40  sublw 0x40  btfss STATUS,Z ;is temp ready ??  goto get_temp ;NO, try again  movlw 0x00 ;YES, send temp command  banksel cmd_byte ;send temp register command  movwf cmd_byte  goto temp_now  convert_temp  movwf temperature  call bin_bcd ;NO, get temp ready for LCD  call LCDLine_1   movlw A'T' ;send "Temp=" to LCD  movwf temp_wr  call d_write  movlw A'e'  movwf temp_wr  call d_write  movlw A'm'  movwf temp_wr  call d_write  movlw A'p'  movwf temp_wr  call d_write  movlw 0x20 ;space  movwf temp_wr  call d_write  movlw A'='  movwf temp_wr  call d_write  movlw 0x20 ;space  movwf temp_wr Instrucción cambio de señal
  • 9.
     call d_write movf MSD,w ;send high digit  movwf temp_wr  call d_write  movf MsD,w ;send middle digit  movwf temp_wr  call d_write  movf LSD,w ;send low digit  movwf temp_wr  call d_write  movlw A'C' ;send "C" for Celsius  movwf temp_wr  call d_write  movlw 0x20 ;space  movwf temp_wr  call d_write  movlw 0x20 ;space  movwf temp_wr  call d_write  movlw 0x20 ;space  movwf temp_wr  call d_write  call LCDLine_2 ;send "RB0 = Exit" to LCD  banksel ptr_pos  movlw .144  movwf ptr_pos  call stan_char_2   btfss select ;wait for RB0 release  goto $-1  call delay_100ms  btfss select ;exit ?  goto menu_clock ;YES, goto main menu  btfsc PIR1, TMR1IF ;2 second overflow occur ??  call write_eeprom ;YES  goto get_temp ;NO, get temperature again
  • 10.