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.

Clear Timer on Compare Match(CTC) Mode problem

Status
Not open for further replies.

Razu Ahmmed

Newbie level 3
Joined
Jan 13, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Khulna,Bangladesh
Activity points
1,307
I have faced problems in working with CTC in atmega. I can not produce interrupt after 1 second using CTC. I observed that the value of OCR1AH is not compared with with TCNT1H .What can be done?
Suggest needed.My code is following........

#include <built_in.h>

int a=0;

void Timer1compa_ISR() org IVT_ADDR_TIMER1_COMPA
{
PORTB=~PORTB;
PORTD=0xFF;
}


void main()
{
int i;
DDRB=0xFF;
DDRD=0xFF;
DDRC=0xFF;

SREG_I_bit=1;

TIMSK |= (1<<OCIE1A);

TCNT1L=0;
TCNT1H=0
i=4870;
OCR1AL=Lo(i);
OCR1AH=Hi(i);
TCCR1B |= (1<<WGM12);

TCCR1B=0x0D; /*start timer with presscaler of clk/1024*/
/*Timer/Counter1, Output Compare A Match Interrupt Enable*/


while(1)
{
PORTB=0x0F;
}
}
 

You are missing

// timer1 compare match A ISR on
TIMSK=0x10;

I also don't know why you use TCCR1B |= (1<<WGM12); when in the next line you write a new value TCCR1B=0x0D;

Alex

P.S. actually the TIMSK exists in your code.
I an not familiar with your compiler but maybe the value is the problem, can you use OCR1A=i ?
There should also be somewhere a global enable interrupt (for example it is sei() in avrgcc)
 

Here i have a problem like i am using mikroC as compiler , in it the following code is not accepted ....
OCR1A=i;
when i declare such as......
OCR1AL=i;
then it is accepted but it is only possible when ( i<255 )
if i>255
then i have to declare it like
OCR1AL=Lo(i);
OCR1AH=Hi(i);
but in this case the OCR1AH value is not compared with the value of TCNT1H only the value of OCR1L value is compared as a result i could not able to compare a large time.
I can not understand actually what i have to do. Help needed..
 

CTC problem in atmega with mikroC compiler

I need a normal code of Timer1 CTC for atmega in mikroC. I have made a simple code but i can not understand where is my error i can not compare time when i>255.
Help needed.
#include<built_in.h>

unsigned int i;

void inerrupt_ISP() org IVT_ADDR_TIMER1_COMPA
{
PORTB = ~PORTB ;
}

void square_wave_init(void)
{
DDRB = 0xFF;
TIMSK |= (1<<OCIE1A);
TCNT1L=0;
i=4870;
OCR1AL = i;
OCR1AH=Hi(i);
TCCR1B |= (1<<WGM12);
TCCR1B |= (1<<CS10) | (1<<CS12);
//TCCR1A=0b01010000;
}
void main()
{
square_wave_init();
SREG_I_bit=1;
while(1){ ;
}

}
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top