Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Pulse time measurement in ATMEGA16

Status
Not open for further replies.

nareshbhar

Newbie level 5
Joined
Jan 16, 2009
Messages
10
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,283
Activity points
1,353
timer atmega 16

Hi all,
actually I want to measure the time between two successive pulse.
and signal is supposed to be between 0.4-2 seconds.
I am using ATMEGA16,and codevision compiler for programming.
I tried to write the code using timer1,but somehow i didnt got the output as desired.
so,if anyone can help.
Thanks.
 

pulse width time atmega

Which is the exact problem?
Please give us a little more information.

Did you see this in page 92 of the datasheet: To do a 16-bit write, the High byte must be written before the Low byte. For a 16-bit read, the
Low byte must be read before the High byte.

This is for TCNT1, OCR1A/B, and ICR1 registers, they are 16-bit wide.

(Some time ago, I've been some hours searching for a problem with one peripheral (I don't remember wich one), when I see a note like this. I learned the lesson: Read the datasheet carefully)

Regards.
Diego
 

measure pulse width atmega

i have written my program in codevision, and with this i am getting width=132 on lcd,when my input to the INT0 pin is pilses with 1s time period.so ,for T1 clock source of 7.813khz, which is incorrect.
please point out the mistakes or additions in the program attached below.or if you have any sample program for time period measurement,then pls upload it.
thanks
 

pulse width measurement atmega

I've been reading your code, and you are reading and writing 16 bits registers in a wrong way. Like I say in my previous post, when you read or write a 16 bits register, you must do in a particular order (Page 92 of the ATmega16 datasheet).

1) If you write a 16 bits register, you must first write the higher 8 bits, and then write the lower 8 bits.
2) If you read a 16 bits register, you first read the lower 8 bits, and then read the higher 8 bits.

TCNT1 is a 16 bits register, so you must follow this procedure to read and write in it. This, when you write C code, in most cases is solved by the compiler. You have two choices, read the hexa code produced and find if they do in the proper way, and/or change your code to make two 8 bits read/write operations.

Here, you are reading the TCNT1 register in a wrong way:
Code:
width=TCNT1H;
width=(width<<8);
width=width|TCNT1L;
You must, first read the lower 8 bits, and then the higher 8 bits.

Here, you write the CNNT1 register in a proper way:
Code:
TCNT1H=0x00;
TCNT1L=0x00;

Correct, and try again.
Regards
 
  • Like
Reactions: gigigi

    gigigi

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top