Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

atmega103 timer1

atmega103 timer1

2006-03-04 by kishor lalu bande

hi freinds!
i had written programm for timer1
which is not working
can anybody tell me what is wrong in this?
subroutine "delayMs" is written to get delay using timer1.



#include
#include


#define posel PORTD
#define rdsel1 0x00
#define rdsel2 0x20
#define rdsel3 0x40
#define rdsel4 0x60
#define rdsel5 0x80
#define rdsel6 0xa0
#define rdsel7 0xc0
#define rdsel8 0xe0



unsigned long ulTick;


void port_init(void)
{
DDRA=0xFF;
PORTA=0x00;
//DDRB=0xf7;
//PORTB=0x08;
//DDRC=0xff;
//PORTC=0x00;
DDRD=0xe0;
PORTD=0x1f;
DDRE=0xee;
PORTE=0x11;
}

//TIMER1 initialize - prescale:1 desired value: 1mSec actual value:
//1.000mSec (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xF0; //setup
TCNT1L = 0x60;
OCR1AH = 0x0F;
OCR1AL = 0xA0;
OCR1BH = 0x0F;
OCR1BL = 0xA0;
TCCR1A = 0x00;
TCCR1B = 0x01; //start Timer
}
#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void)
{

TCNT1H = 0xF0; //reload counter high value
TCNT1L = 0x60; //reload counter low value
if (ulTick > 0)
ulTick--;
}

void delayMs(unsigned long mSec)
{
CLI(); // disable all interrupts
ulTick = mSec;
SEI(); // re-enable interrupts
while (ulTick>0);
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
XDIV = 0x00; //xtal divider
XMCRA = 0x00; //external memory
port_init();
timer1_init();


MCUCR = 0x00;
//EICRA = 0x00; //extended ext ints
//EICRB = 0x00; //extended ext ints
EIMSK = 0x00;
TIMSK = 0x04;
TIFR = 0x04 //timer interrupt sources
//ETIMSK = 0x00; //extended timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized

}



void main(void){
int i,j;
ulTick = 0;
init_devices();

while(1){

PORTA=0b00000000;
posel=0x00;
LOW_HIGH();
delayMs(10);
PORTA=0b11111111;
posel=0x00;
LOW_HIGH();
delayMs(10);
}


}

void LOW_HIGH(void)
{ PORTE=0b01000000;
PORTE=0b00000000;
}



Re: [AVR-Chat] atmega103 timer1

2006-03-04 by James Hatley

I believe that ulTick must be declared volatile .
Jim
Show quoted textHide quoted text
----- Original Message -----
Sent: Friday, March 03, 2006 8:46 PM
Subject: [AVR-Chat] atmega103 timer1

hi freinds!
i had written programm for timer1
which is not working
can anybody tell me what is wrong in this?
subroutine "delayMs" is written to get delay using timer1.



#include
#include


#define posel PORTD
#define rdsel1 0x00
#define rdsel2 0x20
#define rdsel3 0x40
#define rdsel4 0x60
#define rdsel5 0x80
#define rdsel6 0xa0
#define rdsel7 0xc0
#define rdsel8 0xe0



unsigned long ulTick;


void port_init(void)
{
DDRA=0xFF;
PORTA=0x00;
//DDRB=0xf7;
//PORTB=0x08;
//DDRC=0xff;
//PORTC=0x00;
DDRD=0xe0;
PORTD=0x1f;
DDRE=0xee;
PORTE=0x11;
}

//TIMER1 initialize - prescale:1 desired value: 1mSec actual value:
//1.000mSec (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xF0; //setup
TCNT1L = 0x60;
OCR1AH = 0x0F;
OCR1AL = 0xA0;
OCR1BH = 0x0F;
OCR1BL = 0xA0;
TCCR1A = 0x00;
TCCR1B = 0x01; //start Timer
}
#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void)
{

TCNT1H = 0xF0; //reload counter high value
TCNT1L = 0x60; //reload counter low value
if (ulTick > 0)
ulTick--;
}

void delayMs(unsigned long mSec)
{
CLI(); // disable all interrupts
ulTick = mSec;
SEI(); // re-enable interrupts
; while (ulTick>0);
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
XDIV = 0x00; //xtal divider
XMCRA = 0x00; //external memory
port_init();
timer1_init();


MCUCR = 0x00;
//EICRA = 0x00; //extended ext ints
//EICRB = 0x00; //extended ext ints
EIMSK = 0x00;
TIMSK = 0x04;
TIFR = 0x04 //timer interrupt sources
//ETIMSK = 0x00; //extended timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized

}



void main(void){
int i,j;
ulTick = 0;
init_devices();

while(1){

PORTA=0b00000000;
posel=0x00;
LOW_HIGH();
delayMs(10);
PORTA=0b11111111;
posel=0x00;
LOW_HIGH();
delayMs(10);
}


}

void LOW_HIGH(void)
{ PORTE=0b01000000;
PORTE=0b00000000;
}



Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.