Translate, Traductor

Mostrando entradas con la etiqueta AD. Mostrar todas las entradas
Mostrando entradas con la etiqueta AD. Mostrar todas las entradas

jueves, 14 de junio de 2012

Conversor Analogo Adigital con PIC 16F886

En una entrada anterior usamos el conversor análogo a digital del microcontrolador PIC 12f675 ( http://xorwf.blogspot.com/2012/06/conversor-analogo-digital-con-pic.html ), esta es para usar el conversor del microcontrolador PIC 16F886.
El programa mide el voltaje entregado por el potenciometro, si es menor a un voltio, activa el pin RC0 y desactiva el pin RC7, si es mayor a un voltio activa el RC7 y desactiva el RC0.


Circuito



En el caso de querer trabajar con algún sensor análogo, como una fotoresistencia, un fotodiodo(infrarojo), entre otros, simplemente cambiamos el potenciometro por el sensor que elegimos y cambiamos el valor de la comparación, que para este caso es .51 (decimal) que equivale a un voltio medido por el AD.


QR para el celular


Código fuente


LIST P=16F886

    INCLUDE P16F886.INC
ERRORLEVEL -302

    __CONFIG _CONFIG1, _INTOSCIO & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _IESO_OFF & _FCMEN_OFF & _LVP_OFF & _DEBUG_OFF
    __CONFIG _CONFIG2, _BOR40V & _WRT_OFF

CBLOCK 0X20
PDel0, VALORAD
ENDC


      ORG 00
      GOTO CONFIGURA
   
RETAD  movlw     .123      ; 1 set number of repetitions
        movwf     PDel0     ; 1 |
PLoop0  clrwdt              ; 1 clear watchdog
        decfsz    PDel0, 1  ; 1 + (1) is the time over?
        goto      PLoop0    ; 2 no, loop
PDelL1  goto PDelL2         ; 2 cycles delay
PDelL2  clrwdt              ; 1 cycle delay
        return              ; 2+2 Done
   
   
CONFIGURA CLRF     PORTB
BANKSEL OSCCON
      MOVLW B'01101100'
      MOVWF OSCCON
BANKSEL ADCON1
MOVLW B'00000000' ; 7 justifica a la izq, 5 Vss ref, 4 Vdd ref
MOVWF ADCON1
BANKSEL TRISA
      MOVLW B'00000001'
      MOVWF TRISA
      MOVLW B'00000000'
      MOVWF TRISB
      MOVLW B'00000000'
      MOVWF TRISC
BANKSEL ANSEL
MOVLW B'00000001'
      MOVWF ANSEL
CLRF     ANSELH
      BANKSEL ADCON0
      MOVLW B'11000001' ;7:6 FCR clock, 5:2 canal, 1 go, 0 AD ON
      MOVWF ADCON0
      CLRF PORTC
       

INICIO   BSF ADCON0,GO
CALL RETAD
END_AD BTFSC ADCON0,GO
GOTO END_AD
MOVF ADRESH,W
MOVWF VALORAD

MOVLW .51 ;Pregunto si el valor medido por el AD es menor a 1 V
SUBWF VALORAD,W
BTFSS STATUS,C
GOTO MENOR
GOTO MAYOR

       

MAYOR BCF PORTC,0
BSF PORTC,7
GOTO INICIO


MENOR BCF PORTC,7
BSF PORTC,0  
        GOTO     INICIO
        END


Copyright 2012  edwtron
       
Este DOCUMENTO es un DOCUMENTO LIBRE, usted puede redistribuirlo y/o modificarlo bajo los terminos de la GNU FDL tal y como es publicada por la fundacion de software libre; bajo la version 1.3 de la licencia, o  una version superior.
     Leer la licencia GNU gpl para mas detalles. 

    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 1.3
    or any later version published by the Free Software Foundation;
    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
    A copy of the license is included in the section entitled "GNU
    Free Documentation License".  


martes, 12 de junio de 2012

Conversor Análogo a Digital con PIC 12F675

El conversor análogo a digital es un dispositivo que me permite digitalizar señales, en este caso vamos a medir el voltaje por el pin AN1 y si es mayor a 2.5 voltios activamos el LED conectado en GP2.

Circuito



QR para el celular


Código fuente



LIST P=12F675
INCLUDE P12F675.INC

ERRORLEVEL -302

; Trabajamos con un oscilador interno a 4Mhz
__CONFIG _CPD_OFF & _CP_OFF & _BODEN_ON & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT

CBLOCK 0X20
d1, d2, VALOR
ENDC


ORG 00

GOTO INICIO

RET10MS ;9998 cycles
movlw 0xCF
movwf d1
movlw 0x08
movwf d2
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0

;2 cycles
goto $+1
RETURN


INICIO NOP
CLRF GPIO
MOVLW B'00000111' ; 07H Configuro GP1, GP2, GP3 como pines
MOVWF CMCON ; digitales y no del comparador del micro
BANKSEL OSCCAL
CALL 3FFH ; Obtengo el valor de calibracion del oscilador
MOVWF OSCCAL ; y lo calibro con el OSCCAL
BANKSEL ADCON0 ; Configuro el AD
MOVLW B'00000101' ;          7          6        5      4     3 2       1    0
MOVWF ADCON0 ; justifico derecha, no uso, no uso, Vdd, canal AN1, GO, ad ON
BANKSEL ANSEL
MOVLW .2
MOVWF ANSEL ;CONFIGURO GP1/AN1 COMO ENTRADA ANALOGA
MOVLW .2
MOVWF TRISIO
BANKSEL GPIO


CICLO CALL RET10MS
BSF ADCON0,GO ; Inicio conversion
BTFSS ADCON0,GO ; Espero a que finalice la conversion
GOTO $-1
; Conversion finalizada
BANKSEL ADRESH
MOVF ADRESH,W ; Paso el dato tomado por el conversor a W
BANKSEL VALOR
MOVWF VALOR ; Almaceno el dato
MOVLW .128 ; pregunto si el dato es mayor a .128
SUBWF VALOR,W
BTFSS STATUS,C
GOTO MENOR ; Si el dato es Menor
GOTO MAYOR ; Si el dato es Mayor

MENOR BCF GPIO,2
BSF GPIO,0
GOTO CICLO
MAYOR BSF GPIO,2
BCF GPIO,0
GOTO CICLO

END


Copyright 2012  edwtron
       
Este DOCUMENTO es un DOCUMENTO LIBRE, usted puede redistribuirlo y/o modificarlo bajo los terminos de la GNU FDL tal y como es publicada por la fundacion de software libre; bajo la version 1.3 de la licencia, o  una version superior.
     Leer la licencia GNU gpl para mas detalles. 

    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 1.3
    or any later version published by the Free Software Foundation;
    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
    A copy of the license is included in the section entitled "GNU
    Free Documentation License".