Raady Here
Full Member level 5
- Joined
- Jun 8, 2013
- Messages
- 242
- Helped
- 26
- Reputation
- 52
- Reaction score
- 26
- Trophy points
- 28
- Location
- India
- Activity points
- 1,571
PIC18F4520,
MPLAB 8.88
Hi,
I am using Timer1 and configured timer for 1 ms delay.
to check my configuration I am running a clock, for this I need to raise a flag every 1000 times it overflows to make it a second. but i need to do every 30th time.
so I am getting 33 ms instead of 1ms.
so I tried assigning TMR values to 0, even then it doesnt show any difference.
if I cant load the necessary values where should I load those else where my configuration gone wrong ?
Actually I am need of 200us delay.
calculations used for timer
Fosc = 8 Mhz internal
Fcy = 2 Mhz
Tcy = 0.5us
Tcy scalar = 0.5us x 1 (used 1:1)
T = 1ms/0.5us = 2000 = 07D0h
TMR1L = 0xD0;
TMR1H = 0x07;
Here is my timer configuration
ISR used
MPLAB 8.88
Hi,
I am using Timer1 and configured timer for 1 ms delay.
to check my configuration I am running a clock, for this I need to raise a flag every 1000 times it overflows to make it a second. but i need to do every 30th time.
so I am getting 33 ms instead of 1ms.
so I tried assigning TMR values to 0, even then it doesnt show any difference.
if I cant load the necessary values where should I load those else where my configuration gone wrong ?
Actually I am need of 200us delay.
calculations used for timer
Fosc = 8 Mhz internal
Fcy = 2 Mhz
Tcy = 0.5us
Tcy scalar = 0.5us x 1 (used 1:1)
T = 1ms/0.5us = 2000 = 07D0h
TMR1L = 0xD0;
TMR1H = 0x07;
Here is my timer configuration
Code:
void INIT_TIMER(void)
{
RCONbits.IPEN = 1; // Enable priority levels on interrupts
INTCONbits.GIEH = 1; // Enables all high priority interrupts
INTCONbits.GIEL = 0; // Enables all Low priority interrupts
PIR1bits.TMR1IF = 0; // TMR1 register overflow is cleared
PIE1bits.TMR1IE = 1; // Enables overflow interrupt
IPR1bits.TMR1IP = 1; // High priority
T1CONbits.RD16 = 1; // Enables register Read/Write of Timer1 in one 16-bit operation
T1CONbits.T1RUN = 0; // Device clock is derived from other oscillator
T1CONbits.T1CKPS1 = 0;
T1CONbits.T1CKPS0 = 0; // Prescalar 1:1
T1CONbits.T1OSCEN = 1; // Timer 1 osc on.
T1CONbits.TMR1CS = 0; // Internal Clock Fosc /4.
T1CONbits.TMR1ON = 1; // Enables Timer1
TMR1L = 0xD0;
TMR1H = 0x07;
}
ISR used
Code:
#pragma code high_vector = 0x08
void interrupt_at_high_vector(void)
{
_asm
goto high_isr
_endasm
}
#pragma code // return to the default code section
#pragma interrupt high_isr
void high_isr(void)
{
if(PIR1bits.TMR1IF) // TMR1 register overflowed
{
PIR1bits.TMR1IF = 0; //clear interrupt flag
count++;
if(count > 29) // 29 approximated by trail and error
{
count = 0;
flag_clock = 1; // flags for every sec
Clock();
}
}
}