Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

EW AVR and interrupt ? - Didn't operat...

Status
Not open for further replies.

elcielo

Full Member level 6
Joined
Jun 13, 2002
Messages
383
Helped
15
Reputation
30
Reaction score
8
Trophy points
1,298
Activity points
3,250
timer0_ovf_vect

unsigned int g_usec;

void TimerInit(void)
{
TCCR0 = 0x00; //stop
ASSR = 0x00; //set async mode
TCNT0 = 0xC6; //set count
OCR0 = 0x3A;
TCCR0 = 0x01; //start timer

TIMSK = 0x01;
}

void delay(unsigned int us)
{
g_usec = 0;
if (us>0) while(g_usec<us){;}
}

#pragma vector = TIMER0_OVF_vect
__interrupt void TIMER0_OVF_interrupt (void)
{
TCNT0 = 0xC6; //reload counter value

g_usec++;// 1 uSec/one
}

void main(void)
{
delay(255); <-operate
delay(10000); <-didn't oprate
}

Didn't operat...

How I do check option ?

Atmega 128
 

elcielo

Full Member level 6
Joined
Jun 13, 2002
Messages
383
Helped
15
Reputation
30
Reaction score
8
Trophy points
1,298
Activity points
3,250
option -h must not be defined more than once

Option -H must not be defined more than once: -H1895

^
+----- what ?
 

cancel

Full Member level 5
Joined
May 27, 2001
Messages
251
Helped
15
Reputation
30
Reaction score
4
Trophy points
1,298
Activity points
1,878
timer0_ovf_interrupt

hi .. i am using delay routine based on topis described here:
http://www.elektroda.pl/eboard/viewtopic.php?t=43802&highlight=avr+delay
Works fine for me and does not require timer ... in my app i am using timers for other purposes ...
mine looks like:
void delayus(unsigned int us)
{
while(us--) __delay_cycles(10) ;
}
you have to calculate delay constant (10 in my case) to match you hw .. iow osc freq. you need to include inavr.h

for your code .. first of all ... i would start timer by delay routine. in your code timer is running all the time and you are wasting mcu time by executing not neccessary interrupt. other thing ... your g_usec is not safe ... it overflow over int value(0xffff) after some time ... this can cause strange behavior

regards

cancel
 

elcielo

Full Member level 6
Joined
Jun 13, 2002
Messages
383
Helped
15
Reputation
30
Reaction score
8
Trophy points
1,298
Activity points
3,250
avr interrupt tcnt0

elcielo said:
unsigned int g_usec;

void TimerInit(void)
{
TCCR0 = 0x00; //stop
ASSR = 0x00; //set async mode
TCNT0 = 0xC6; //set count
OCR0 = 0x3A;
TCCR0 = 0x01; //start timer

TIMSK = 0x01;
}

void delay(unsigned int us)
{
g_usec = 0;
if (us>0) while(g_usec<us){;}
}

#pragma vector = TIMER0_OVF_vect
__interrupt void TIMER0_OVF_interrupt (void)
{
TCNT0 = 0xC6; //reload counter value

g_usec++;// 1 uSec/one
}

void main(void)
{
delay(255); <-operate
delay(10000); <-didn't oprate
}

Didn't operat...

How I do check option ?

Atmega 128
Imagecraft C compiler operate good.
Maybe
#pragma vector = TIMER0_OVF_vect
__interrupt void TIMER0_OVF_interrupt (void)
{
TCNT0 = 0xC6; //reload counter value

g_usec++;// 1 uSec/one <--It's overflow...
}
 

002

Member level 1
Joined
Nov 12, 2001
Messages
32
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Italia
Activity points
162
tcnt0 in avr

use :

volatile unsigned int g_usec;
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top