PDA

View Full Version : interrupt trouble @.1ms



mehmetOzdemir
- 24th March 2009, 13:17
i tried to get an interrupt at .1ms using dt-ints.

i used 16f877a at 4MHz and timer1 1:1 prescaler , want to toggle a led that connected to portb.7 to test interrupt.

timer1 pre-load value is 65437. The signal must be 5KHz , but it is about 2.4KHz.

The code is below.What am i missing or what is the mistake?



INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts


LED VAR PORTB.7

OUTPUT LED

ADCON1 = 7





ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _TMR1_INT, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts


T1CON = %00000101 ; Prescaler = 1, TMR1ON

TMR1L = $9D ; TMR1 = 65437
TMR1H = $FF


MAIN :

PAUSE 50

GOTO MAIN


TMR1_INT :

TMR1L = $9D
TMR1H = $FF

TOGGLE LED
@ INT_RETURN

Charles Linquis
- 24th March 2009, 13:37
When you load the timer, you have to load the High Byte first, then Low Byte.

mehmetOzdemir
- 24th March 2009, 14:05
When you load the timer, you have to load the High Byte first, then Low Byte.

thanks charles for your quick reply.

i tried to load highbyte of timer1 first , but it is not the aid.

Acetronics2
- 24th March 2009, 16:16
Hi,

You forgot to take the reload time into account ...

from MrE calc. I get 65443 ...

Why not use a 8 bits timer w/ preload = 63 ???

Alain

mehmetOzdemir
- 24th March 2009, 16:33
Hi,

Why not use a 8 bits timer w/ preload = 63 ???

Alain

i used timer0 , the problem is the same.

i used darrel taylor's intterrupt system before , but the interrupt durations was so long about 20ms there was no problem.

but when i want to use it 100 microseconds this problem occurred.

thanks for your advice.

sayzer
- 24th March 2009, 17:09
1. I would remove "PAUSE 50" from main loop.
2. To load the timer, have a word variable like timex.
For example:



TimeX VAR WORD

TimeX = 65437

TMR1L = TimeX.LowByte
TMR1H = TimeX.HighByte


3. Why not use TMR0 ?


----------------

mehmetOzdemir
- 24th March 2009, 17:23
1. I would remove "PAUSE 50" from main loop.
----------------

I CHANGED IT TO "PAUSEUS 5" THE FREQUENCY OF SIGNAL IS SAME.



3. Why not use TMR0 ?
----------------

I usually do this with tmr1 , there is not a special reason.
i used tmr0 too , but the problem is going on.

İLGİN İÇİN ÇOK TEŞEKKÜR EDERİM SAYZER.

Bruce
- 24th March 2009, 17:38
Using a PBP interrupt eats hundreds of instruction cycles just saving & restoring PBP system
variables.

You can get much more accurate timing, and save hundreds of instruction cycles with a
CCP Compare interrupt & .asm interrupt handler.

Try something like this;


INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts

LED VAR PORTB.7
OUTPUT LED
LED = 1
ADCON1 = 7

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler CCP1_INT, CCP_INT, ASM, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE CCP1_INT ; enable Compare interrupt

T1CON = %00000001 ; Prescaler = 1, TMR1ON
CCP1CON = %00001011 ; compare mode, int when TMR1 = CCPR1
CCPR1L = 100 ; interrupt every 100 instruction cycles
CCPR1H = 0

MAIN:
PAUSE 50
GOTO MAIN

ASM
CCP_INT
MOVLW 0x80 ; W = %10000000
XORWF PORTB,F ; toggle RB7 on each interrupt
INT_RETURN
ENDASM
This should give you a 5kHz signal on RB7, with Timer1 reset by hardware. To change the
frequency, just change the value in CCPR1 high & low registers.

See analyzer screen capture attached.

mehmetOzdemir
- 24th March 2009, 18:02
it is realy great bruce.

I HAVE TO USE ASM INTERRUPTS AFTER THAT.

The frequency is 5KHz.

And where can i find some sample codes to use asm interrupt routines in PBP.

thank you very much..

Bruce
- 24th March 2009, 18:12
For examples of using assembler interrupts look at some of Darell Taylors code, and look
through a few of the examples on MeLabs website.