Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Resumen
La presente prctica tiene como objetivo implementar un control inalmbrico por
RF utilizando el Flash Starter Kit de Microchip de manera que se obtenga
movilidad de un brazo de robot en el cual se sustituir el mdulo que contiene los
botones de control y programar un algoritmo de control para los cinco grados de
libertad del brazo mediante el transmisor del RFPIC12f675.
Posteriormente se disear y programar un algoritmo para recibir la seal
de control enviada a fin de implementar una interfase lgica y de potencia para
enviar la seal de control recibida.
CD4515B
Marco Terico
Espectro RF
Muchos productos de consumo e industriales hacen uso de la energa electromagntica.
Un tipo de energa electromagntica que est aumentando en importancia a nivel mundial
es la energa de radiofrecuencia (RF), incluyendo ondas de radio y microondas, las cuales
son usadas para proveer comunicaciones y radiodifusin y otros servicios. Las ondas de
radio y microondas son formas de energa electromagntica que son comnmente
descritas por el trmino de radiofrecuencia o RF. Las emisiones de RF y los fenmenos
asociados pueden ser discutidos en trminos de energa, radiacin o campos. La
radiacin es definida como la propagacin de energa a travs del espacio en forma de
ondas o partculas. La radiacin electromagntica puede ser descrita como ondas de
energa elctrica y magntica movindose conjuntamente a travs del espacio. Est
ondas son generadas por el movimiento de cargas elctricas tales como en un objeto
conductor metlico o antena por ejemplo, el movimiento alternante de cargas en una
antena usado para la difusin de radio y televisin o en la antena de una estacin de base
celular generan ondas electromagnticas que son radiadas desde el transmisor y que son
recibidas por una antena tal como una antena de techo, antena de radio de automvil o
una antena de telfono celular. El trmino campo magntico es usado para indicar la
presencia de energa electromagntica en un lugar dado. El campo RF puede ser descrito
en trminos de potencia de campo elctrico y/o magntico en un lugar dado.
Abreviatura
inglesa
Banda
ITU
Frecuencias
Longitud de onda
ELF
Inferior a 3
Hz
3-30 Hz
> 100.000 km
SLF
30-300 Hz
ULF
3003000 Hz
VLF
330 kHz
LF
MF
5
6
10 km 1 km
1 km 100 m
HF
VHF
7
8
30300 kHz
3003000
kHz
330 MHz
30300 MHz
UHF
1 m 100 mm
SHF
10
3003000
MHz
3-30 GHz
EHF
11
30-300 GHz
10 mm 1 mm
Por encima
de los 300
GHz
< 1 mm
100.000 km
10.000 km
10.000 km
1000 km
1000 km 100
km
100 km 10 km
100 m 10 m
10 m 1 m
100 mm 10 mm
El OWI-007 ROBOTIC ARM TRAINER es un kit que muestra los principios bsicos
de mocin y sensado robtico. El kit incluye un control de 5 interruptores conectado al
brazo mediante un cable de 8 hilos.
Como primer paso se desconect el control de la parte trasera y se retir la tapa
de la base inferior, con lo que qued al descubierto el compartimiento de las bateras. En
la figura siguiente se puede observar que la alimentacin proporcionada por las bateras
se conecta con una terminal de 8 pines de color blanco (parte superior) que sirve para
conectar el control.
Visto de frente (con la base apoyada) los pines corresponden a 5 motores, 2 niveles de
voltaje y 1 tierra como se muestra en la siguiente tabla:
PIN
1
2
3
4
5
6
7
8
Control o Voltaje
- 3Vcc (con Pilas)
Motor de los Dedos
Motor del Codo
Motor de la Base
Todos los Motores (Comn 0V)
Motor del Hombro
Motor de la Mueca
+ 3Vcc (con Pilas)
Tabla 2. Relacin de los Pines y los Motores del Brazo de Robot.
Diagramas Esquemticos
Teclado
TX
RX
Control
Etapa de
potencia
Figura 5. Diagrama a bloques del sistema para llevar a cabo el control inalmbrico del brazo.
emisor del TIP por ser npn y entonces existe corriente en el motor la cual genera un
voltaje en l con polaridad + - de arriba hacia abajo, haciendo girar al motor en un sentido.
Cuando la parte positiva es la que recibe el 0 por parte del demultiplexor, hay una
corriente en el LED lo cual enciende al optotransistor y genera una corriente de colector a
emisor del optotransistor, la cual a su vez genera una corriente en la base del TIP115 por
estar conectado a ella, al haber una corriente de base, sta logra que se encienda el TIP
generando corriente de emisor a colector por ser pnp y entonces hay una corriente a
travs del motor polarizndolo con un voltaje - + visto de arriba hacia abajo, entonces al
tener polaridad contraria a la vista cuando se enciende la parte izquierda, el motor girar
en direccin contraria a la primera.
El mismo diagrama se repite otras 4 veces, una vez por cada motor, de modo que
generando las seales de control adecuadas el brazo puede moverse en los 5 grados de
libertad.
Como podr verse si ambas seales de control se activan al mismo tiempo, se
producir un corto circuito en las terminales del emisor. Del mismo modo, dado que la
fuente de alimentacin para todos los motores sera la misma, la corriente disminuir en
cada motor que se active por eso no es recomendable que se active ms de un motor a la
vez.
Consta de un pic soldado, pines de conexin, dos potencimetros GP0 y GP1, y dos
botones GP3 y GP4. Adems contiene un jumper para poder seleccionar alimentacin del
pickit o alimentacin de la bateria que se encuentra en la parte posterior.
A continuacin se muestra el siguiente diagrama esquemtico para ste ltimo mdulo:
continuacin, y se documenta por medio de recuadros que indican las partes modificadas
y agregadas para poder lograr la transmisin tal como se explic.
Algoritmos de TX y RX.
Transmisin.
;---------------------------------------------------------------------;
Software License Agreement
;
; The software supplied herewith by Microchip Technology Incorporated
; (the "Company") for its PICmicro Microcontroller is intended and
; supplied to you, the Companys customer, for use solely and
; exclusively on Microchip PICmicro Microcontroller products.
;
; The software is owned by the Company and/or its supplier, and is
; protected under applicable copyright laws. All rights are reserved.
; Any use in violation of the foregoing restrictions may subject the
; user to criminal sanctions under applicable laws, as well as to
; civil liability for the breach of the terms and conditions of this
; license.
;
; THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
; WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
; TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
; PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
; IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
; CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
;
;---------------------------------------------------------------------;
; Filename:
xmit.asm
; Date:
April 25, 2003
; File Version:
1.0
; Assembled using: MPASM 03.30 Released
; Author:
Steven Bible
; Company:
Microchip Technology Inc.
;---------------------------------------------------------------------; Files required:
p12f675.inc
;---------------------------------------------------------------------;
; Program Description
;
; This program demonstrates simple command & control and analog
; application demonstrations. To see each demonstration the user must
; load the appropriate receiver code examples:
;
; rcvr_demo.asm
;
; When a push button on the transmitter module is depressed, the
; corresponding LED is lit on the PICkit(tm) 1 FLASH Starter Kit.
; Pressing transmitter module push button GP3 lights LED D0 on the
; PICkit(tm) 1. Pressing push button GP4 lights LED D1.
;
; rcvr_analog_display.asm
;
; Pressing transmitter module push button GP3 lights LEDs D0-D7 on
; the PICkit(tm) 1 with the upper 8-bit value read from the
10
__CONFIG _CPD_OFF & _CP_OFF & _BODEN_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF &
_INTRC_OSC_NOCLKOUT
;---------------------------------------------------------------------; Variables (Section 2.2 Data Memory Organization)
;---------------------------------------------------------------------;
;
;
;
cblock 0x20
w_temp
status_temp
TEMP
CSR0
CSR1
CSR2
CSR3
CSR4
CSR5
CSR6
CSR7
CSR8
Count
Count2
BitCount
TimeHi
TimeLo
FuncBits
; Function Bits
endc
;---------------------------------------------------------------------; Defines
;---------------------------------------------------------------------;
;
;
;
;
;
;
;
11
POT0 GPIO, 0
POT1 GPIO, 1
TXD
GPIO, 2
PB3
GPIO, 3
PB4
GPIO, 4
RFENA GPIO, 5
; 46 X TE
; Preamble length = 16 pulses
0x000
; RESET Vector
nop
; for ICD use
goto INITALIZE
; goto INITALIZE
ORG
0x004
; Interrupt Vector
movwf w_temp
; save W register
swapf STATUS, W
; swap status to be saved into W
bcf
STATUS, RP0
; ---- Select Bank 0 ----movwf status_temp
; save STATUS register
;---------------------------------------; Interrupt Service Routine (ISR)
;
; Description:
;
;---------------------------------------;
;
;
;
;
;
;
;
;
; read GPIO
;---------------------------------------swapf
movwf
swapf
swapf
status_temp, W
; swap status_temp into W, sets bank to original state
STATUS
; restore STATUS register
w_temp, F
w_temp, W
; restore W register
12
retfie
;---------------------------------------------------------------------; Subroutine DATA_EEPROM_READ
;
; Description: To read an EEPROM data memory location, the address is
; written to the EEADR register and set control bit RD (EECON1<0>) to
; initiate a read. Data is available in the EEDATA register the next
; clock cycle.
;
; Constants: none
;
; Global Variables: none
;
; Initialization: W contains EEPROM address to be read
;
; Output: W contains EEPROM data
;
;---------------------------------------------------------------------DATA_EEPROM_READ
bsf
STATUS, RP0
movwf EEADR
bsf
EECON1, RD
movf EEDATA, W
bcf
STATUS, RP0
return
;---------------------------------------------------------------------; Subroutine DATA_EEPROM_WRITE
;
; Description: To write an EEPROM data memory location, the address is
; written to the EEADR register, data to the EEDATA register, then
; execute a required sequence of instructions.
;
; CAUTION: Interrupts are disable during this subroutine
;
; Constants: none
;
; Global Variables: none
;
; Initialization: Address = EEADR, Data = EEDATA
;
; Output: none
;
;---------------------------------------------------------------------DATA_EEPROM_WRITE
bsf
STATUS, RP0
bsf
bcf
EECON1, WREN
; EEPROM Write Enable: allow write cycles
INTCON, GIE
; disable global interrupts
; *** required sequence, do not alter ***
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf
EECON1, WR
; initiate EEPROM write
; *** end required sequence ***
bsf
INTCON, GIE
; enable global interrupts
bcf
EECON1, WREN
; EEPROM Write Enable: inhibit write cycles
13
bcf
STATUS, RP0
return
;---------------------------------------------------------------------; Subroutine READ_ANALOG_AN0; READ_ANALOG_AN1
;
; Description: Read analog channel 0 (AN0) or 1 (AN1).
;
; Constants: none
;
; Global Variables: none
;
; Initialization: none
;
; Output: ADRESH and ADRESL contain 10-bit A/D result justified
; according to ADCON0, ADFM bit.
;
;---------------------------------------------------------------------READ_ANALOG_AN0
bcf
ADCON0, CHS1
; select analog channel AN0
bcf
ADCON0, CHS0
goto
READ_ANALOG
** Cuando no se presiona el
botn PB3, se llama esta funcin
para despus ir a
READ_ANALOG
READ_ANALOG_AN1
bcf
bcf
ADCON0, CHS1
ADCON0, CHS0
READ_ANALOG
bsf
ADCON0, ADON
ADCON0, GO
btfsc ADCON0, GO
goto $-1
bcf
ADCON0, ADON
En esta funcin se
configura el modulo
ADC para lograr la
adquisicin por medio
del potencimetro G3.
El valor adquirido se
guarda en ADRESH
return
;---------------------------------------------------------------------; Subroutine: WaitxTE
;
; Description:
;
; Constants:
;
; Global Variables:
;
; Initialization: W x 400us length of delay required
;
; Output: Count, Count2 as decrementing counters
;
14
;---------------------------------------------------------------------WaitxTE
movwf Count2
waitxlp
movlw D'79'
movwf Count
; [1]
; [1]
; [1]
wait400lp
nop
; [1]
nop
; [1]
decfsz Count,F
; [1]
goto wait400lp ; [2]
;
-------;
79 x 5 = 395us
decfsz Count2,F ; [1]
goto waitxlp ; [2]
retlw 0
;
;
;
; [2]
total 2 (call) + W x (395 + 5) + 2 (return)
w = 1 -> 406us @4MHz
w = 2 -> 806us @4MHz
INTCON, GIE
STATUS, RP0
call 0x3FF
movwf OSCCAL
bcf
STATUS, RP0
STATUS, RP0
movlw GPTRIS
movwf TRISIO
bcf
STATUS, RP0
15
;
;
;
;
;
;
;
;
;
;
VRCON, VREN
bcf
VRCON, VRR
;
;
;
;
bcf
bcf
bcf
bcf
VRCON,
VRCON,
VRCON,
VRCON,
;
;
;
;
bcf
VR3
VR2
VR1
VR0
STATUS, RP0
CVref
CVref
CVref
CVref
value
value
value
value
selection
selection
selection
selection
bit
bit
bit
bit
3
2
1
0
ADCON0, ADFM
ADCON0, VCFG
ADCON0, ADON
bsf
STATUS, RP0
STATUS, RP0
;----------------------------------------
16
T1CON, TMR1ON
; TIMER1: stopped
bcf
T1CON, TMR1CS
bcf
T1CON, NOT_T1SYNC ; TIMER1 External Clock Input Sync Control: Syncronize external clock input
STATUS, RP0
STATUS, RP0
STATUS, RP0
bcf
bsf
bcf
bcf
OPTION_REG, T0CS
OPTION_REG, T0SE
bcf
OPTION_REG, PSA
STATUS, RP0
17
STATUS, RP0
STATUS, RP0
STATUS, RP0
bcf
bcf
bcf
bcf
PIE1,
PIE1,
PIE1,
PIE1,
bcf
STATUS, RP0
EEIE
ADIE
CMIE
TMR1IE
bcf
INTCON, PEIE
INTCON, T0IE
INTCON, INTE
INTCON, GPIE
INTCON, GIE
RFENA
; Disable Transmitter
INTCON, GIE
; enable global interrupts
SCANPB
18
movlw 0x00
movwf FuncBits
btfss PB3
; Push Button GP3 pressed?
goto SPB2
movlw 0x23
; Function S0 selected
iorwf FuncBits, F
call READ_ANALOG_AN0 ; read analog channel AN0
;SPB1
;
btfsc PB4
; Push Button GP4 depressed?
;
goto SPB2
; no, jump over
; movlw 0x43
; Function S1 selected
; iorwf FuncBits, F
;call READ_ANALOG_AN1 ; read analog channel AN1
SPB2
movlw 0xFF
andwf FuncBits, W
; Was any switch depressed?
btfss STATUS, Z
goto XMIT
; Yes, transmit buffer
bcf
RFENA
sleep
goto SCANPB
Se checa si se logr
que el botn PB3 no
fuera presionado.
En esta funcin se
Si se adquiri el
habilita el transmisor.
valor analgico
por no presionar
Se enva el valor de la
PB3, se realiza:
adquisicin del
GOTO XMIT ++
potencimetro en CSR1
RFENA
; Enable Transmitter
movlw 0x73
movwf CSR0
movfw FuncBits
movwf CSR1
;
;
;
;
;
Despus checamos si
presionamos el botn
PB4. Si esta
presionado se va a
PRENDIDO. Si no
esta presionado se va a
APAGADO.
;***************************
;
;
;
bsf
STATUS, RP0
CLRF
ADRESL
bcf
STATUS, RP0
BTFSC
GOTO
GOTO
PB4
APAGADO
PRENDIDO
PRENDIDO
;BSF
STATUS,RP0
MOVLW b'10000000'
GOTO
APAGADO
CONTINUA
19
;BSF
STATUS,RP0
MOVLW b'00000000'
;*********************************
CONTINUA
movwf CSR2
movfw ADRESH
movwf CSR3
; ADRESH Result
movlw 0x56
movwf CSR4
movlw 0x34
movwf CSR5
movlw 0x12
movwf CSR6
movlw 0x20
movwf CSR7
movlw 0x55
movwf CSR8
; send Flags
bsf
TXD
movlw 1
call WaitxTE
bcf
TXD
movlw 1
call WaitxTE
decfsz BitCount,F
goto PreL
; sync pause
TXloop
movlw D'10'
call WaitxTE
; Theader = 10 x Te
; lsb first
TXNextByte
movlw D'8'
movwf BitCount
TXNextBit
rrf
INDF,W
; 8 bit rotate
20
rrf
INDF,F
; Carry contain lsb
BC
ONE
ZERO
movlw 2
;
movwf TimeHi
; +---+---+ +-movlw 1
; |
| |
movwf TimeLo
;---+
+---+
goto Trasm_BIT
; | 2Te Te |
ONE
movlw
movwf
movlw
movwf
1
;
TimeHi
; +---+
+-2
; | |
|
TimeLo
;---+ +---+---+
; | Te 2Te |
Trasm_BIT
bsf
TXD
; ON
movf TimeHi,W
call WaitxTE
bcf
TXD
; OFF
movf TimeLo,W
call WaitxTE
decfsz BitCount,F
goto TXNextBit
incf FSR,F
movlw CSR8+1
xorwf FSR,W
andlw 0x1F
BNZ
TXNextByte
; loop on bits
; check if finished
; guard time
movlw TGUARD
call WaitxTE
goto
SCANPB
ORG 0x2100
DE 0x00, 0x01, 0x02, 0x03
21
Recepcin.
;---------------------------------------------------------------------;
;
Software License Agreement
;
; The software supplied herewith by Microchip Technology Incorporated
; (the "Company") for its PICmicro Microcontroller is intended and
; supplied to you, the Companys customer, for use solely and
; exclusively on Microchip PICmicro Microcontroller products.
;
; The software is owned by the Company and/or its supplier, and is
; protected under applicable copyright laws. All rights are reserved.
; Any use in violation of the foregoing restrictions may subject the
; user to criminal sanctions under applicable laws, as well as to
; civil liability for the breach of the terms and conditions of this
; license.
;
; THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
; WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
; TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
; PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
; IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
; CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
;
;---------------------------------------------------------------------;
; Filename:
rcvr_analog_display.asm
; Date:
April 25, 2003
; File Version:
1.0
; Assembled using:
;
; Author:
Steven Bible
; Company:
Microchip Technology Inc.
;
;
;---------------------------------------------------------------------;
; Files required:
;
p16f676.inc
;
;
;---------------------------------------------------------------------;
; Program Description
;
; This program demonstrates a simple command and control application.
; When a push button on the transmitter module is depressed, the
; corresponding LED is lit on the PICkit(tm) 1 FLASH Starter Kit.
;
; Pressing transmitter module push button GP3 lights LEDs D0-D7 on
; the PICkit(tm) 1 with the upper 8-bit value read from the
; transmitter module 10-bit A/D channel 0 connected to potentiometer
; GP0. Pressing push button GP4 lights LEDs D0-D7 with the upper
; 8-bit value read from A/D channel 1 connected to potentiometer GP1.
;
; The protocol is a simplified KeeLoq(r) protocol compatible with
; the HCS101 fixed code products. This receive code was adapted from
; Microchip Technology application note AN740.
22
;
; The 10-bit analog value is placed into the 16-bit counter field of
; the simplified KeeLoq(r) protocol.
;
;---------------------------------------------------------------------list
p=16f676
; list directive to define processor
#include <p16f676.inc> ; processor specific variable definitions
errorlevel -302
23
;
; Register locations 0x20 to 0x5F (64 bytes) are General Purpose
; registers, implemented as static RAM and are mapped across both
; banks.
cblock 0x20
w_temp
status_temp
TEMP
DATA0
DATA1
DATA2
DATA3
ORIGIN
SX1TMR
SX2TMR
TMRLOW
TMRHIGH
HIGHWDTH
LOWWDTH
STATECNTR
BITCNTR
FLAGS
COUNTR
LEDREG
LEDREGBUF
LEDSTATE
endc
ACTUAL
EQU
0x37
PASADO
EQU
0x38
;---------------------------------------------------------------------; Defines
;----------------------------------------------------------------------
Declaracin de registros
ACTUAL y PASADO, los
cuales sern de utilidad para
obtener una salida binaria
estable.
.
PORTA, 0
PORTA, 1
PORTA, 2
PORTA, 3
PORTA, 4
24
#define RA5
PORTA, 5
; (Digital Input/Output)
; (Digital Input/Output)
; (Digital Input/Output)
; (Digital Input/Output)
; (Digital Input/Output)
; (Digital Input) Receive Data
El puerto C (compuesto de 6
bits) es configurado en su bit
1 como entrada (donde recibe
la informacin serial). Los bits
2,3,4 y 5 son configurados
como salida y ah se depositar
la salida binaria. El bit 0 del
puerto
C
tambin
se
configurado como salida y
mandar el valor necesario para
activar el codificador (inhibit)
cuando en el transmisor sea
presionado un switch.
BEGN 0x00
BEGN1 0x01
HEADR 0x02
HEADR1
HIGHP 0x04
LOWP 0x05
RECRD 0x06
WAIT 0x07
VALID 0x08
IMPLMNT
0x03
0x09
; Flags
#define LRNFLG FLAGS, 0
#define TOGFLG FLAGS, 1
#define HLFLG FLAGS, 2
; LEDs
#define LED0
#define LED1
#define LED2
#define LED3
#define LED4
#define LED5
#define LED6
#define LED7
LEDREG, 0
LEDREG, 1
LEDREG, 2
LEDREG, 3
LEDREG, 4
LEDREG, 5
LEDREG, 6
LEDREG, 7
; S0 LED
; S1 LED
; S2 LED
25
#define LED0ON
#define LED1ON
#define LED2ON
#define LED3ON
#define LED4ON
#define LED5ON
#define LED6ON
#define LED7ON
b'00010000'
b'00100000'
b'00010000'
b'00000100'
b'00100000'
b'00000100'
b'00000100'
b'00000010'
0x000
nop
goto
RESET
ORG
0x004
; RESET Vector
; for ICD use
movwf w_temp
swapf STATUS, W
bcf STATUS, RP0
movwf status_temp
; Interrupt Vector
; save W register
; swap status to be saved into W
; ---- Select Bank 0 ----; save STATUS register
status_temp, W
STATUS
w_temp, F
w_temp, W
retfie
;---------------------------------------------------------------------; Subroutine DATA_EEPROM_READ
;
; Description: To read an EEPROM data memory location, the address is
; written to the EEADR register and set control bit RD (EECON1<0>) to
; initiate a read. Data is available in the EEDATA register the next
26
; clock cycle.
;
; Constants: none
;
; Global Variables: none
;
; Initialization: W contains EEPROM address to be read
;
; Output: W contains EEPROM data
;
;---------------------------------------------------------------------DATA_EEPROM_READ
bsf STATUS, RP0
movwf EEADR
bsf EECON1, RD
movf EEDATA, W
bcf STATUS, RP0
return
;---------------------------------------------------------------------; Subroutine DATA_EEPROM_WRITE
;
; Description: To write an EEPROM data memory location, the address is
; written to the EEADR register, data to the EEDATA register, then
; execute a required sequence of instructions.
;
; CAUTION: Interrupts are disable during this subroutine
;
; Constants: none
;
; Global Variables: none
;
; Initialization: Address = EEADR, Data = EEDATA
;
; Output: none
;
;---------------------------------------------------------------------DATA_EEPROM_WRITE
bsf
STATUS, RP0
bsf
bcf
EECON1, WREN
; EEPROM Write Enable: allow write cycles
INTCON, GIE
; disable global interrupts
; *** required sequence, do not alter ***
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1, WR
; initiate EEPROM write
; *** end required sequence ***
btfsc EECON1, WR
goto $-1
bsf
bcf
INTCON, GIE
EECON1, WREN
27
bcf
STATUS, RP0
return
;---------------------------------------------------------------------; Subroutine READ_ANALOG_AN0
;
; Description: Read analog channel 0 (AN0).
;
; Constants: none
;
; Global Variables: none
;
; Initialization: none
;
; Output: ADRESH and ADRESL contain 10-bit A/D result justified
; according to ADCON0, ADFM bit.
;
;---------------------------------------------------------------------READ_ANALOG_AN0
bsf
ADCON0, ADON
bcf
bcf
ADCON0, CHS1
ADCON0, CHS0
; At 4 MHz, a 22 us delay
; (22us = 2us + 6 * 3us + 1us)
ADCON0, GO
btfsc ADCON0, GO
goto $-1
bcf
ADCON0, ADON
return
;---------------------------------------------------------------------; Initialize PICmicro (PIC12F675)
;---------------------------------------------------------------------INITIAL
; Disable global interrupts during initialization
bcf
INTCON, GIE
28
STATUS, RP0
call 0x3FF
movwf OSCCAL
bcf
STATUS, RP0
STATUS, RP0
movlw PORTATRIS
movwf TRISA
movlw PORTCTRIS
movwf TRISC
bcf
STATUS, RP0
VRCON, VREN
bcf
VRCON, VRR
;
;
;
;
bcf
bcf
bcf
bcf
VRCON, VR3
VRCON, VR2
VRCON, VR1
VRCON, VR0
29
bcf
STATUS, RP0
ADCON0, ADFM
ADCON0, VCFG
bcf
ADCON0, ADON
bsf
STATUS, RP0
STATUS, RP0
T1CON, TMR1ON
; TIMER1: stopped
bcf
T1CON, TMR1CS
bcf
T1CON, NOT_T1SYNC ; TIMER1 External Clock Input Sync Control: Syncronize external clock input
30
STATUS, RP0
STATUS, RP0
STATUS, RP0
bsf
bsf
bcf
bcf
bcf
OPTION_REG, PSA
STATUS, RP0
31
bsf
STATUS, RP0
clrf IOCA
bcf
STATUS, RP0
STATUS, RP0
bcf
bcf
bcf
bcf
PIE1, EEIE
PIE1, ADIE
PIE1, CMIE
PIE1, TMR1IE
bcf
STATUS, RP0
INTCON, PEIE
INTCON, T0IE
INTCON, INTE
INTCON, RAIE
bcf
INTCON, GIE
retlw 0
; exit INITIAL
32
movlw B'01111111'
addwf TMR0, W
; TOGGLE toggles back and forth to a
btfss STATUS, C
; one the rate TMR0 overflows.
retlw 0
; TMR0 overflow ~= 1ms (2^8*4us)
bcf TOGFLG
incfsz SX1TMR, F
; SX1TMR resolution ~= 1ms
retlw 0
; SX1TMR overflow ~= 0.25sec (2^8*1ms)
incf SX2TMR, F
; SX2TMR resolution ~= 0.25sec
retlw 0
; SX2TMR overflw ~= 1min (2^8*0.23sec)
TIMER1
movlw B'01111111'
addwf TMR0, W
btfsc STATUS, C
retlw 0
bsf TOGFLG
retlw 0
;---------------------------------------------------------------------; Subroutine: CLOCK
;
; Description: Continually updates TMRLOW and TMRHIGH.
;
; Constants: none
;
; Global Variables: ORIGIN
;
; Initialization: ORIGIN
;
; Output: TMRLOW, TMRHIGH
;
;---------------------------------------------------------------------CLOCK
movf ORIGIN, W
subwf TMR0, W
addwf TMRLOW, F
btfsc STATUS, C
incf TMRHIGH, F
nop
nop
nop
movlw 2
subwf TMR0, W
movwf ORIGIN
;
retlw 0
33
bsf
LRNFLG
bsf
LRNLED
clrf SX1TMR
clrf SX2TMR
retlw 0
;---------------------------------------------------------------------; Subroutine: LEARN
;
; Description: This routine learns the first two bytes of data received
; from the transmitter by storing these bytes in its internal EEPROM.
;
; Constants:
;
; Global Variables:
;
; Initialization: none
;
; Output: none
;
;---------------------------------------------------------------------LEARN
btfss SX2TMR, 5
goto LEARN1
bcf
bcf
LRNFLG
LRNLED
retlw 0
LEARN1
movlw VALID
; If the State Counter currently holds
xorwf STATECNTR, W
; the value for exectuting the
btfss STATUS, Z
; VALIDATE function, then a successretlw 0
; ful reception has occurred.
bsf
STATUS, RP0
34
movlw 0x00
movwf EEADR
movfw DATA0
movwf EEDATA
bcf
STATUS, RP0
STATUS, RP0
movlw 0x01
movwf EEADR
movfw DATA1
movwf EEDATA
bcf
STATUS, RP0
LRNLED
LRNFLG
movlw BEGN
movwf STATECNTR
retlw 0
35
; Constants: none
;
; Global Variables: LEDREG
;
; Initialization: SX2TMR
;
; Output: none
;
;---------------------------------------------------------------------SXON
btfss SX2TMR, 0
retlw 0
clrf
LEDREG
retlw 0
;---------------------------------------------------------------------; Subroutine: LEDSTATEMACHINE
;
; Description: This is the state machine that cycles through the LED's
; Atates are incremented in the interrupt routine after an overflow on TMR0
;
; Constants:
;
; Global Variables:
;
; Initialization:
;
; Output:
;
;---------------------------------------------------------------------LEDStateMachine
movlw HIGH LEDStateMachineStart
movwf PCLATH
movf LEDSTATE, W
; Mask bits (should be only 8 states)
andlw B'00000111'
addwf PCL, F
LEDStateMachineStart
goto LEDSTATE0
goto LEDSTATE1
goto LEDSTATE2
goto LEDSTATE3
goto LEDSTATE4
goto LEDSTATE5
goto LEDSTATE6
goto LEDSTATE7
LEDSTATE0
call LITELED0
goto EndLEDStateMachine
LEDSTATE1
36
call LITELED1
goto EndLEDStateMachine
LEDSTATE2
call LITELED2
goto EndLEDStateMachine
LEDSTATE3
call LITELED3
goto EndLEDStateMachine
LEDSTATE4
call LITELED4
goto EndLEDStateMachine
LEDSTATE5
call LITELED5
goto EndLEDStateMachine
LEDSTATE6
call LITELED6
goto EndLEDStateMachine
LEDSTATE7
call LITELED7
EndLEDStateMachine
return
;----------------------------------------------------------------LITELED0
bsf STATUS, RP0
movlw LED0TRIS
movwf TRISA
bcf STATUS, RP0
movlw LED0ON
movwf PORTA
;**********************************************************
BTFSC
PORTA,4
GOTO
SALIDA_BINARIA_0
REGRESO_0
;**********************************************************
return
LITELED1
bsf STATUS, RP0
movlw LED1TRIS
movwf TRISA
bcf STATUS, RP0
movlw LED1ON
En la matriz de leds el
valor a la salida no es
constante, se encuentra
oscilando, por lo que
despus de cada rutina que
verifica si se debe
encender cada led, se
comprueba que en dicho
led se tenga en una
terminal el valor adecuado
para encenderlo. En las
subrutinas
SALIDA_BINARIA_X se
verifica la otra terminal y
si se cumplen los
requisitos se manda un 1
binario en el bit
correspondiente de los
cuatro disponibles (Puerto
A en los pines 2, 3, 4 y 5).
Se aplica lo mismo para
cuatro leds, en cada
recuadro con el smbolo:
*
37
movwf PORTA
;*************
BTFSS PORTA,4
GOTO SALIDA_BINARIA_1
REGRESO_1
;************
return
LITELED2
bsf STATUS, RP0
movlw LED2TRIS
movwf TRISA
bcf STATUS, RP0
movlw LED2ON
movwf PORTA
;*************************************
BTFSC PORTA,4
GOTO SALIDA_BINARIA_2
REGRESO_2
;*************************************
return
LITELED3
bsf STATUS, RP0
; ---- Select Bank 1 ----movlw LED3TRIS
movwf TRISA
bcf STATUS, RP0
; ---- Select Bank 0 ----movlw LED3ON
movwf PORTA
BSF
PORTC,5
;***********************************
BTFSS PORTA,4
GOTO SALIDA_BINARIA_2
REGRESO_3
;***********************************
return
LITELED4
bsf STATUS, RP0
movlw LED4TRIS
movwf TRISA
bcf STATUS, RP0
movlw LED4ON
movwf PORTA
return
LITELED5
bsf STATUS, RP0
movlw LED5TRIS
movwf TRISA
bcf STATUS, RP0
movlw LED5ON
movwf PORTA
return
LITELED6
38
MOVF PASADO,W
SUBWF ACTUAL,W
BTFSS STATUS,Z
CLRF PORTC
BCF
STATUS,Z
MOVF ACTUAL,W
MOVWF PASADO
CLRF ACTUAL
return
;************************
; Subrutine: Salida binaria para cada led
;************
;************************
SALIDA_BINARIA_0
BTFSC PORTA,5
GOTO REGRESO_0
;*******************************
BSF
PORTC,2
BSF
ACTUAL,0
GOTO REGRESO_0
;*******************************
SALIDA_BINARIA_1
BTFSS PORTA,5
GOTO REGRESO_1
;************************
BSF
PORTC,3
BSF
ACTUAL,1
GOTO REGRESO_1
;**********************
SALIDA_BINARIA_2
BTFSC PORTA,2
GOTO REGRESO_2
;*************************
BSF
PORTC,4
BSF
ACTUAL,2
GOTO REGRESO_2
;*************************
SALIDA_BINARIA_3
**
Para el bit 1.
**
Para el bit 2.
39
BTFSS PORTA,2
GOTO REGRESO_3
;************************
BSF
PORTC,5
BSF
ACTUAL,3
Para
GOTO REGRESO_3
;*************************
;************
;---------------------------------------------------------------------; Subroutine: Display
;
; Description: Displays Value Stored In LEDREGBUF On LED Array
; 1 bit is displayed during each call
; LEDREGBUF is reloaded with LEDREG after 8 calls of DISPLAY()
; D7..D4 LED'S show most significant nibble
; D3..D0 LED'S show least significant nibble
;
; Constants:
;
; Global Variables: LEDREG, LEDREGBUF
;
; Initialization:
;
; Output:
;
;---------------------------------------------------------------------DISPLAY
movf
btfsc
goto
btfss
goto
**
el bit 3.
LEDSTATE, W
STATUS, Z
; Are we at state 0?
BUFFERRESET
; Yes
LEDSTATE, 3
; No, did we pass the last state?
BUFFERLOADED
; No
BUFFERRESET
; Yes
movf LEDREG, W
btfss STATUS, Z
; is LEDREG = 0?
goto BUFFERRESET1
; no, jump over
; yes, turn off LEDs
bsf STATUS, RP0
; ---- Select Bank 1 ----movlw LEDOFFTRIS
movwf TRISA
bcf STATUS, RP0
; ---- Select Bank 0 ----clrf PORTA
BUFFERRESET1
movf LEDREG, W
movwf LEDREGBUF
; Reload with the current value in LEDREGISTER
clrf LEDSTATE
; Ensure State Zero
BUFFERLOADED
bcf STATUS, C
; Ensure Carry Is Clear
rrf LEDREGBUF, F
btfsc STATUS, C
; Is The Next Bit a '1'
goto UPDATELED
; Yes, Update The LED Array
goto CONTINUE
; No
UPDATELED
call LEDStateMachine
CONTINUE
40
incf LEDSTATE, F
return
;----------------------------------------------------------------------
41
; RECEIVE SEQUENCE
;---------------------------------------------------------------------;*********************** CODE WORD FORMAT ****************************
; _ _ _ _
_ __ _
__ _
_
; ||||||||
|| | ||| | |||
|
; | |_| |_| |_| |_____________| |__| |_| |_/ /_| |_| |_________|
;
/ /
; |--PREAMBLE---|---HEADER----|---------DATA------------|--GUARD--|
;
TIME
;*********************************************************************
;******************** RECEIVED DATA BREAKDOWN ************************
;
;bytes |
DATA1
|
DATA0
|
;bits | 7| 6| 5| 4| 3| 2| 1| 0| 7| 6| 5| 4| 3| 2| 1| 0|
;desc. |S2|S1|S0|S3| 0| 0| SERIAL NUMBER 3
|
;
;bytes |
DATA3
|
DATA2
|
;bits | 7| 6| 5| 4| 3| 2| 1| 0| 7| 6| 5| 4| 3| 2| 1| 0|
;desc. |
COUNTER
|
;
;* S3 Not used
;
;*********************************************************************
;---------------------------------------; BEGIN
;
This function looks for a possible start to the data stream.
;
;
Input Variables:
;
RXDATA
;
Output Variables:
;
none
BEGIN
btfsc RXDATA
incf STATECNTR, F
goto MAIN
BEGIN1
btfsc RXDATA
goto MAIN
call SETWATCH
incf STATECNTR, F
goto
MAIN
;---------------------------------------; HEADER
;
Detects a valid header.
;
;
Input Variables:
;
RXDATA
;
Output Variables:
;
none
HEADER
btfsc RXDATA
goto RESTART
42
btfss TMRHIGH, 0
; low. If both hold true -> HEADER1.
goto MAIN
; 1.25ms occurs when:
movlw D'64'
; TMRHIGH = 1 ~= 2^8*4us = 1ms
andwf TMRLOW, W
; TMRLOW = 64 ~= 64*4us = 0.25ms
btfsc STATUS, Z
goto MAIN
incf STATECNTR, F
goto
MAIN
HEADER1
movlw D'6'
; If the data goes high before 6ms
subwf TMRHIGH, W
; then the header is valid, else
btfss STATUS, C
; restart.
goto HEADER2
; TMRHIGH = 6 = 6*1ms = 6ms
goto
RESTART
HEADER2
btfss RXDATA
goto MAIN
call SETWATCH
movlw D'32'
; Initiate BITCNTR to 32 in order to
movwf BITCNTR
; receive 32 bits of the data stream.
incf STATECNTR, F
; Make state HIGHPLSE
goto
MAIN
;---------------------------------------; HIGHPLSE
;
Times the width of high pulses.
;
;
Input Variables:
;
RXDATA
;
Output Variables:
;
none
HIGHPLSE
btfsc TMRHIGH, 0
goto RESTART
btfsc RXDATA
goto MAIN
movf TMRLOW, W
movwf HIGHWDTH
call SETWATCH
incf STATECNTR, F
goto
MAIN
;---------------------------------------; LOWPULSE
;
Times the width of low pulses.
;
;
Input Variables:
43
;
;
;
none
Output Variables:
none
LOWPULSE
btfsc TMRHIGH, 0
goto LOW2
btfss RXDATA
goto MAIN
movf TMRLOW, W
movwf LOWWDTH
call SETWATCH
incf STATECNTR, F
goto
MAIN
LOW2
movlw HEADR
movwf STATECNTR
; Make state HEADER if lowpulse is
; too long.
goto MAIN
;---------------------------------------; RECORD
;
Records each bit as it comes in from the data stream.
;
;
Input Variables:
;
RXDATA
;
Output Variables:
;
DATA0
;
DATA1
;
DATA2
;
DATA3
RECORD
movf HIGHWDTH, W
subwf LOWWDTH, W
; The state of the carry bit after
rrf DATA3, F
; this operation reflects the data
rrf DATA2, F
; logic. This is then rotated
rrf DATA1, F
; into the storage bytes.
rrf DATA0, F
movlw HIGHP
movwf STATECNTR
decfsz BITCNTR, F
goto MAIN
movlw D'4'
movwf COUNTR
movlw DATA0
movwf FSR
RECORD1
movlw 0xFF
xorwf INDF, W
btfss STATUS, Z
goto RECORD2
44
incf FSR, F
decfsz COUNTR, F
goto RECORD1
goto
RESTART
RECORD2
movlw WAIT
movwf STATECNTR
goto
MAIN
;---------------------------------------; WAIT4END
;
Wait for the guard time at the end of the code word before
;
attempting to receive another code word.
;
;
Input Variables:
;
RXDATA
;
Output Variables:
;
none
WAIT4END
btfsc HLFLG
goto WAIT1
btfsc RXDATA
goto MAIN
call
bsf
WAIT1
btfss
goto
SETWATCH
HLFLG
RXDATA
WAIT2
bcf
HLFLG
goto
MAIN
WAIT2
btfss TMRHIGH, 3
goto MAIN
bcf HLFLG
; has been reached.
incf STATECNTR, F
; Make state VALIDATE
goto
MAIN
;---------------------------------------; VALIDATE
;
Checks that the transmission received is from the valid
;
transmitter.
;
;
Input Variables:
;
DATA0
;
DATA1
;
Output Variables:
;
none
45
VALIDATE
movlw 0x00
; EEPROM Address = 0x00
call DATA_EEPROM_READ ; Get stored DATA0, EEDATA -> W
xorwf DATA0, W
btfss STATUS, Z
goto RESTART
movlw 0x01
; EEPROM Address = 0x01
call DATA_EEPROM_READ ; Get stored DATA1, EEDATA -> W
movwf TEMP
bsf STATUS, RP0
movf EEDATA, W
bcf STATUS, RP0
xorwf TEMP, F
btfsc TEMP, 0
goto RESTART
btfsc TEMP, 1
goto RESTART
incf STATECNTR, F
goto
MAIN
;---------------------------------------; IMPLEMNT
;
Implements the outputs specified by the received code word.
;
;
Input Variables:
;
DATA1
;
Output Variables:
;
S0
;
S1
;
S2
IMPLEMNT
;************************************************************************************voy a poner esto
; btfsc DATA1, 7
; bsf LED2
;
;
btfss DATA1, 7
bcf LED2
; btfsc DATA1, 6
; bsf LED1
; btfss DATA1, 6
; bcf LED1
;
; btfsc DATA1, 5
bsf LED0
; btfss DATA1, 5
; bcf LED0
46
;********************************************************************************************
movf DATA3,W
;************************************************************************
BTFSC DATA2,7
GOTO ENCENDIDO
En el registro
GOTO APAGADO
ENCENDIDO
BCF
GOTO
PORTC,0
CONTINUA
APAGADO
BSF
CONTINUA
movwf LEDREG
clrf SX1TMR
clrf SX2TMR
goto
PORTC,0
; save to LEDREG
; initialize the timers for the
; outputs
RESTART
;---------------------------------------; RESTART
;
Sets the State Counter to BEGIN so that the receive sequence
;
is restarted.
;
;
Input Variables:
;
none
;
Output Variables:
;
none
RESTART
movlw BEGN
movwf STATECNTR
goto
DATA2 en su bit
ms significativo (7) se es
enviada a partir del transmisor la
informacin de si el switch es
presionado. Si se lee un 1
lgico en dicho bit, quiere decir
que el switch ha sido presionado
y entonces se manda un 1
lgico en el bit 0 del puerto C,
dicha salida ir al inhibit del
codificador 4 a 16 y entonces
ste mandar una salida nica
para cada combinacin. Si el bit
7 del registro DATA2 tiene un
0 lgico quiere decir que el
switch 1 no fue presionado en el
transmisor y por lo tanto se
coloca un 0 lgico en el bit 0
del puerto C y al ir al inhibit del
codificador por lo que no lo
activar y no se tendr una salida
nica
para
diferentes
combinaciones.
MAIN
47
;
; The programmer (PICkit or PROMATE II) will save the actual OSCCAL
; value in the device and restore it. The value below WILL NOT be
; programmed into the device.
org 0x3ff
retlw 0x40
;---------------------------------------------------------------------end
; end of program directive
;----------------------------------------------------------------------
Resultados.
Se logr realizar las modificaciones adecuadas para el control del brazo robtico, lo cual
se considera como un xito, pues los objetivos planteados por la prctica se alcanzaron y
se logr controlar de forma satisfactoria todos los movimientos del brazo. El alcance que
se calcul que exista entre el transmisor y el receptor es de aproximadamente 8 metros,
lo cual se considera bastante bueno ya que la potencia con la que se transmite no es
mucha.
La tabla No. 3 nos indica el valor de la salida digital del Pic del receptor y el
movimiento que se realiza cuando se activa:
48
49
Figura 10. Al frente: Transmisor y etapa de recepcin y potencia. Atrs Brazo y Pic Kit 1.
Conclusin y Comentarios.
Esta es una prctica con un mayor grado de dificultad en su desarrollo ya que es
necesario dedicarle mucho tiempo a entender el funcionamiento del programa de control y
realizar las modificaciones necesarias. La etapa de potencia no present dificultad alguna
ya que el diseo del circuito es muy bsico.
A esta prctica se podra agregar un teclado, en un trabajo extra a futuro, para
eliminar la necesidad de calibrar el potencimetro para la seleccin del movimiento
deseado.
Esta prctica permiti que se lograra una mejor interpretacin del lenguaje
ensamblador, lo cual resulta de gran utilidad ya que existen muchas cosas que ya estn
hechas y que simplemente es necesario adaptarlas a nuestras necesidades.
Bibliografa.
50
http://www.southwest.com.au/~jfuller/robotarm/arm.htm
http://www.super-science-fair-projects.com/owi007-robotic-armtrainer.html
http://www.datasheetcatalog.com
http://www.microchip.com
51