Icr v/s ocr of atmega16

Discussion in 'Embedded Systems and Microcontrollers' started by jordan_dear, Jun 2, 2013.

  1. jordan_dear

    Thread Starter New Member

    Apr 29, 2013
    6
    0
    :)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


    Code ( (Unknown Language)):
    1.  
    2. PROGRAMME:-
    3.  
    4. .INCLUDE "M16DEF.INC"
    5.  
    6. .DEF R_E=R18
    7. .DEF L_E=R21
    8.  
    9.  
    10. .MACRO INITSTACK                                    
    11.  
    12. LDI R16,HIGH(RAMEND)
    13. OUT SPH,R16
    14. LDI R16,LOW(RAMEND)
    15. OUT SPL,R16
    16. .ENDMACRO
    17. ;=====================
    18.  
    19.  
    20. GAME:
    21.  
    22. CBI DDRD,6              ;pd6 initialise as a i/p pin for i/p capture
    23. SBI PORTD,6
    24.  
    25. SBI DDRD,5             ;pd5 initialise as a o/p pin for wave generation
    26. RJMP MAIN
    27. ;=====================
    28.  
    29. MAIN:
    30. INITSTACK
    31. LDI R20,$00
    32. OUT TCCR1A,R20
    33. LDI R20,$41                                   ;i/p capture for rising edge signal
    34. OUT TCCR1B,R20
    35.  
    36. F1:
    37. IN R19,TIFR                                  ;here first i captur i/p signal at  rising edge
    38. SBRS R19,ICF1
    39. RJMP F1
    40.  
    41. IN L_E,ICR1L
    42. IN R_E,ICR1H
    43. OUT TIFR,R19
    44.  
    45. LDI R20,$01
    46. OUT TCCR1B,R20
    47.  
    48. F2:IN R19,TIFR                          ;here first i captur i/p signal at  falling edge
    49. SBRS R19,ICF1
    50. RJMP F2
    51.  
    52. IN R22,ICR1L                           ;then i got the pulse width
    53. SUB R22,L_E
    54. OUT OCR1AL,R22
    55. IN R22,ICR1H
    56. SBC R22,R_E
    57. OUT OCR1AH,R22
    58. RJMP WA_VE
    59. ;===================
    60.  
    61. WA_VE:
    62.                                                            ;this programme is use to generate wave at oc1a pin of atmega 16
    63. LDI R16,$41
    64. OUT TCCR1A,R16
    65. LDI R16,$09
    66. OUT TCCR1B,R16
    67.  
    68. HERE:RJMP HERE
    69.  
    70. ;========================
    71. ;=======================
    72.  
     
    Last edited by a moderator: Jun 2, 2013
  2. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,687
    805
    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.
     
  3. Papabravo

    Expert

    Feb 24, 2006
    10,338
    1,850
    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.
     
  4. jordan_dear

    Thread Starter New Member

    Apr 29, 2013
    6
    0
    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.
     
  5. Papabravo

    Expert

    Feb 24, 2006
    10,338
    1,850
    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?"
     
  6. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,687
    805
    Well if he wants to sample the input frequency once, and then keep producing it on output, then one timer will be enough.
     
  7. Papabravo

    Expert

    Feb 24, 2006
    10,338
    1,850
    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.
     
  8. jordan_dear

    Thread Starter New Member

    Apr 29, 2013
    6
    0
    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!!!
     
  9. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,687
    805
    where in your code do you set the modes and initialize the clock etc.?
     
Loading...