Icr v/s ocr of atmega16

Thread Starter

jordan_dear

Joined Apr 29, 2013
6
:)hey friend's,there is a one problem to me for input capture and o/p compare match in atmega 16,those both belong's to timer1 and i wanted to use both at the same time.
basically i want to measure the i/p frequency and wanted to produce same frequency at oc1a/oc1b,i do this several times but nothing positive o/p i got!!

the logic for it is that-first i capture the i/p freq. by configuring tccr1a,tccr1b register's, after doing this i stop capturing and again configure the tccr1a,tccr1b and produce squre wave at oc1a pin,but still i didn't get desired o/p,so wht i do plz give me some suggestion's,i post my sample(rescent) code here,plz reply me


Rich (BB code):
PROGRAMME:-

.INCLUDE "M16DEF.INC"

.DEF R_E=R18
.DEF L_E=R21


.MACRO INITSTACK                                    

LDI R16,HIGH(RAMEND)
OUT SPH,R16
LDI R16,LOW(RAMEND)
OUT SPL,R16
.ENDMACRO
;=====================


GAME:

CBI DDRD,6              ;pd6 initialise as a i/p pin for i/p capture
SBI PORTD,6

SBI DDRD,5             ;pd5 initialise as a o/p pin for wave generation
RJMP MAIN
;=====================

MAIN:
INITSTACK
LDI R20,$00
OUT TCCR1A,R20
LDI R20,$41                                   ;i/p capture for rising edge signal
OUT TCCR1B,R20

F1:
IN R19,TIFR                                  ;here first i captur i/p signal at  rising edge 
SBRS R19,ICF1
RJMP F1

IN L_E,ICR1L
IN R_E,ICR1H
OUT TIFR,R19

LDI R20,$01
OUT TCCR1B,R20

F2:IN R19,TIFR                          ;here first i captur i/p signal at  falling edge 
SBRS R19,ICF1
RJMP F2

IN R22,ICR1L                           ;then i got the pulse width
SUB R22,L_E
OUT OCR1AL,R22
IN R22,ICR1H
SBC R22,R_E
OUT OCR1AH,R22
RJMP WA_VE
;===================

WA_VE:
                                                           ;this programme is use to generate wave at oc1a pin of atmega 16
LDI R16,$41
OUT TCCR1A,R16
LDI R16,$09
OUT TCCR1B,R16

HERE:RJMP HERE

;========================
;=======================
 
Last edited by a moderator:

kubeek

Joined Sep 20, 2005
5,796
Why don´t you use C? Even without comments, like your code is, it would be much easier to read.
So if I understand you correctly, you want the atmega to capture the input frequency and duty cycle once, and then keep outputting it? I don´t see the timer initialization anywhere in the code.
 

Papabravo

Joined Feb 24, 2006
22,111
What is it in the datasheet that convinces you that this is a possible mode of operation? You must have some justification for your opinion.
 

Thread Starter

jordan_dear

Joined Apr 29, 2013
6
the basic function that i want do is that i just want to measure the i/p frequency from rotary encoder(pulse width) and reproduce it at the o/p (oc1a pin)by changing it's frequency.i am sorry but i am not familiar with embedded c.
the task given to me is that
in some machine their is a rotary encoder,the pulses from it is given to the cpu,so it have some pulse width,my task is to measure this pulse width(means freq.of it)and change the pulse width(freq) and reproduce it at the o/p.i am going to make an such intermediate circuit using atmega 16 for doing this task.
 

Papabravo

Joined Feb 24, 2006
22,111
I did not ask for a restatement of what you wanted to do. I already understood your requirement. My question was: "Why do you think the ATmega16 will allow you to do what you wanted to do in the particular way you want to do it?"

My next question is: "Can't you use one timer (eg Timer1) to do input capture, and another timer (eg Timer3) to do output waveform generation?"
 

kubeek

Joined Sep 20, 2005
5,796
Well if he wants to sample the input frequency once, and then keep producing it on output, then one timer will be enough.
 

Papabravo

Joined Feb 24, 2006
22,111
Well if he wants to sample the input frequency once, and then keep producing it on output, then one timer will be enough.
That seems correct but pointless. There is nothing wrong with changing modes of operation on a timer. If the original sample is wrong the successive outputs will also be wrong. That is a pretty brittle algorithm which lacks robustness.
 

Thread Starter

jordan_dear

Joined Apr 29, 2013
6
correct!! i just use a one timer i.e timer1 for i/p capture nd for the wave generation,i capture i/p once and reproduce the wave continuously.
i think same way that use one 16 bit timer for i/p capture and another for wave generation,but after studying the modes for timer 1,i realized that the thing what i wanted to do is possible using mode 12 of timer 1. and upto certain limit i am succeed to reproduce the wave by this way,but still their is some problem!!!
 
Top