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.

Timer 1 capture mode problem

Status
Not open for further replies.

Navid T

Full Member level 3
Joined
Jan 21, 2005
Messages
186
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,296
Location
Iran
Activity points
1,385
Hi friends
I wrote this program for timer 1 capture mode (mega32), i want to see ICR1 high byte on portA and low byte on portB, but when i run this program isee low byte on porta and highbyte on portb !!!
Whats wrong in my Program??!!!
----------------------------------------------
#include "m32def.inc"
.ORG $0
RJMP SETUP
.ORG $C
RJMP TIMER_CAP
.ORG $14
SETUP:
LDI R16,HIGH(RAMEND)
OUT SPH,R16
LDI R16,LOW(RAMEND)
OUT SPL,R16
LDI R16,$FF
OUT DDRA,R16
OUT DDRB,R16
CBI DDRD,6
SBI PORTD,6
LDI R16,$0
OUT TCNT1H,R16
OUT TCNT1L,R16
LDI R16,0B00000101
OUT TCCR1B,R16
LDI R16,0B00100000
OUT TIMSK,R16
SEI
LOOP: RJMP LOOP
TIMER_CAP:
IN R17,ICR1H
IN R18,ICR1L
OUT PORTA,R17
OUT PORTB,R18
RETI
--------------------------------------------
Best regards
 

Hi,
If you have an endianness setting in your compiler, set it to 'little' endian to get the high byte to high address and low byte to low address.

Regards,
Laktronics
 

Hi and thanks
I dont use any compiler, i wrote this program in assembly and then i assembled it with avrstudio.
 

Accessing 16-bit Register

"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."

Try the program after exchanging the first and second line of TIMER_CAP

TIMER_CAP:
IN R18,ICR1L
IN R17,ICR1H
OUT PORTA,R17
OUT PORTB,R18
RETI
 

thanks svicent
i wrote a code like your code first time and it has same problem tooT then i changed it to this program that you see here, but it was wrong too, i mean if i read high byte first and show on port a, it shows high byte on port b and if i read low byte first and show on port a it shows low byte in port b again !!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top