ejercicos en atmega 164p uso de modo fast pwm cambio tiempo en alto y medir delta
Click here to load reader
-
Upload
wilmer-villegas-codena -
Category
Documents
-
view
135 -
download
17
Transcript of ejercicos en atmega 164p uso de modo fast pwm cambio tiempo en alto y medir delta
ESCUELA POLITECNICA NACIONALSISTEMAS MICROPROCESADOS
NOMBRES: Wilmer VillegasFECHA: 08 – 05 – 2012
1. Realizar un programa que genere una señal PWM (modo a usar “FAST
PWM”). Con un cristal de 1MHz en donde variamos el δ=t aT
, para lo cual
usamos INT0 con un δ=0.3 y INT1 con un δ=0.7. Cuando no presiono ninguna interrupción debo tener un delta normal igual a 0.5, usamos cualquier frecuencia.
PROGRAMA EN AVR:
. include"m164pdef.inc"
.def tempo=r17
.def aux=r18
.def aux1=r19
.def aux2=r20; coloco los vectores de interrupcion.org 0x00
jmp inicio.org 0x02
jmp delta1.org 0x04
jmp delta2.org 0x06
jmp delta3
inicio:; declaro como salida el pin correspondiente al OC0A
ldi tempo,0b00001000out ddrb,tempo
; declaro como entradas las interrupciones
ldi tempo,0b00000000out ddrd,tempo
; habil i tación de pull - upldi tempo,0b00001100out portd,tempoldi tempo,0b00000100out portb,tempo
; garantizo pull - upin tempo,mcucrandi tempo,0b11101111out mcucr,tempo
;habil i tación del SPldi r16,high(ramend)out sph,r16ldi r16,low(ramend)out spl ,r16
; habil i tacion de interrupcionesldi tempo,0b00000111out eimsk,tempo
;desencademaniento de mis interrupciones
ldi tempo,0b00101010sts eicra,tempo
;comparación y modoldi tempo,0b10000011out tccr0a,tempo
;preescaler 8 y modoldi tempo,0b00000010out tccr0b,tempo
; habil i tacion global de interrupciones
sei
lazo:rjmp lazo
delta1:
push tempoin tempo,sregpush tempo
; cambio mi delta = 0.3ldi aux,77out ocr0a,aux
rjmp salir
delta2:
push tempoin tempo,sregpush tempo
; cambio mi delta = 0.7ldi aux1,179out ocr0a,aux1rjmp salir
delta3:
push tempoin tempo,sregpush tempo
; cambio mi delta = 0.5ldi aux2,128out ocr0a,aux2
salir:
pop tempoout sreg,tempopop temporeti
SIMULACION EN PROTEUS:
δ=0.5
δ=0.3
δ=0.7
DIAGRAMA DE FUJO:
2. Realizar un programa el cual se ingrese una señal de entrada externa y medir el t iempo en delta (%).
δ=t aT
∗100 %
PROGRAMA EN AVR:
. include"m164pdef.inc"
.def t iempoh=r17
.def t iempol=r18
.def TH=r19
.def TL=r20
.def tempo=r21
.def aux=r23
.def taux=r24
.org 0x00jmp inicio
.org 0x0Ejmp timer
.org 0x18jmp captura
.org 0x24
jmp desborde
inicio:
ldi tempo,0b01000000out ddrd,tempo
ldi r16,high(ramend)out sph,r16ldi r16,low(ramend)out spl,r16
ldi tempo,0b00001000sts PCICR,tempoldi tempo,0b01000000sts PCMSK3,tempo
ldi tempo,0b00000000sts TCCR1A,tempoldi tempo,0b01000000sts TCCR1B,tempoldi tempo,0b00100000sts TIMSK1,tempo
ldi tempo,0b0000000out TCCR0A,tempoout TCCR0B,tempo
ldi tempo,0b00000001sts TIMSK0,tempo
seiclr tempoclr aux
lazo:rjmp lazo
timer:
push tempoin tempo,SREGpush tempo
sbrc aux,0rjmp detener0clr r22out TCCR0B,r22out TCNT0,r22sts TCCR1B,r22sts TCNT1H,r22sts TCNT1L,r22
ldi r22,0b00000001out TCCR0B,r22
ldi r22,0b01000001sts TCCR1B,r22ldi aux,1rjmp salir
detener0:
clr r22out TCCR0B,r22in tiempol,TCNT0mov tiempoh,tauxclr aux
salir:pop tempoout SREG,tempopop tempo
reti
desborde:
push tempoin tempo,SREGpush tempo
inc taux
pop tempoout SREG,tempopop temporeti
captura:
push tempoin tempo,SREGpush tempo
lds TH,ICR1Hlds TL,ICR1Lclr r22sts TCCR1B,r22sts TCNT1H,r22sts TCNT1L,r22
pop tempoout SREG,tempopop temporeti