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.

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
 

option -h must not be defined more than once

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

^
+----- what ?
 

timer0_ovf_interrupt

hi .. i am using delay routine based on topis described here:
**broken link removed**
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
 

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

tcnt0 in avr

use :

volatile unsigned int g_usec;
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top