PDA

View Full Version : Question about using ASM interupt with PBP



cncmachineguy
- 3rd December 2010, 14:00
Before all the suggestions about using DT_INT, I have tried them, they work great, but not for my current app.

I see in the book I just need to "DEFINE INTHAND SOMELABEL" to get PBP to place a jump at location 4 in memory.

Then at the SOMELABEL routine, I ASM and write my code. Now my question is do I RETFIE at the end of my routine? then ENDASM.

I don't need to think about how I got to SOMELABEL? It is a true GOTO and not a GOSUB placed at location 4?

Darrel Taylor
- 3rd December 2010, 14:38
Before all the suggestions about using DT_INT, I have tried them, they work great, but not for my current app.
DT_INTS is ASM interrupts. If you can't get them to work in your app, writing your own probably won't help.

Were you using PBP type handlers?
You can use ASM type handlers without having to write the low level stuff yourself.

Why do you think they won't work in your app?

cncmachineguy
- 3rd December 2010, 19:49
Why do you think they won't work in your app?

http://www.picbasic.co.uk/forum/showthread.php?p=96751&page=2#post96731

The link should take you to the top of page 2 in my thread "My project is starting"

They do work, but end up being the only thing to work. I am jumping to the interupt at every line of code. This is not because they don't work, but I am GUESSING just too short of a timer. As My PIC (16F1947) has automatic context saving for the interupt AND I don't need to save any other stuff, I was thinking just do it the built in way.

I would LOVE for you to help me to get DT_INT working for me in this app. I see the beauty in it and will use them when I can.

The @int return in the handler is not really at the end of the comment. In fact the comment doesn't even exist in my program(the part in Red)

BTW, I have no trouble with ASM, I am just determined to do things a little easier and learn PBP. But as I do, I find myself still thinking in terms of ASM.

I am generally a lazy typer, and would rather code this:


LATF = PORTA


then this:


MOVF PORTA,0
MOVWF LATF

Darrel Taylor
- 4th December 2010, 02:50
OK, I can see the difficulty there.
5 uS isn't much to work with.

I have been able to get your program from the other thread to work with just a few changes.

By setting PR2 to 39, TMR2 doesn't have to be reloaded on each interrupt, saving 2 instructions.
A TMR2 = PR2 match will reset the timer value and trigger the interrupt.
The actual period is PR2+1 (40 instructions).


The TOGGLE EN1 can be replaced with LATF = LATF ^ 1 which saves another 2 instructions because TOGGLE also sets the TRIS bit to output everytime.

So after setting PR2 in your initialization ...
PR2 = 39 ; set TMR2 period to 5 uS

The interrupt handler looks like this ...
'---[TMR2 - interrupt handler]--------------------------------------------------
FiveMicroSec:
LATF = LATF ^ 1 ; TOGGLE EN1
CNT =CNT+1
LATC = PORTA
@ INT_RETURN

There's still a couple instruction cycles left ... but to answer your original question, you can get a few more cycles back with straight ASM handlers.
_________________________ _____________________________

To do that, let's take the same handler and remove DT_INTS.
DEFINE the ISR's routine (_FiveMicroSec).
Set the TMR2IE, PEIE and GIE bits.
Clear the INT flag at the end.
And instead of @ INT_RETURN ... use @ RETFIE.


PR2 = 39
PIE1.1 = 1 ; Enable Timer2 interrupts
INTCON.6 = 1 ; enable PEIE
INTCON.7 = 1 ; enable GIE
T2CON = %00000100 ; Start Timer2

DEFINE INTHAND _FiveMicroSec

'---[TMR2 - interrupt handler]--------------------------------------------------
FiveMicroSec:
LATF = LATF ^ 1 ; TOGGLE EN1
CNT =CNT+1
PORTC = PORTA
PIR1.1 = 0 ; clear the interrupt flag
@ RETFIE

That should give another 20 instruction cycles.

Don't go crazy in the ISR.
You can only use PBP statements that DO NOT change PBP's system variables.

___________________________ _________________________________

On a different note ... You shouldn't use LATx.x with HIGH, LOW, TOGGLE or any other PBP commands.

Direct assignments to LATx are OK, but when PBP tries to set the tris bit, referenced to the LAT bit, it overwrites the wrong registers.
PBP commands that accept Pins, only work properly with PORTx.x, not LATx.x.

HTH,

cncmachineguy
- 4th December 2010, 10:54
So much learned here!:)

Now I get what PRx is for. Sort of feel a little Doh over that. I prolly would have gone years without seeing it. And its so much more intuitive. (number of cycles - 1) THANK YOU!

I love the toggle replacement

Not only did you answer my original question, but you also did the work for me. To be sure, I will not be going crazy in the ISR, in fact the only thing it needs to do is PORTC = PORTA. the rest is for debugging and will not be in the final program. I may keep a counter in there for something.
Is it safe to assume DT_INT cost about 20 cycles when not used with PBP handler? This is just good to know.

I must admit, I'm not sure I get the rules for using LATx, but easy enough to just not use it at all. I suppose you are saying LATx=something is fine, but not much else.

I think I am most excited about the PRx knowledge. :)

Darrel Taylor
- 4th December 2010, 17:36
Is it safe to assume DT_INT cost about 20 cycles when not used with PBP handler? This is just good to know.
With the 16F1's that's about what it takes to get IN and OUT of DT_INTS.
I didn't count it to the exact number of cycles. It can change depending on the setup.


I must admit, I'm not sure I get the rules for using LATx, ...
Throughout the manual you'll find this statement frequently ... "Pin is automatically made an input" or output.
So those commands will try to set the TRIS bit each time it executes.

When you give it a PORTx.x pin, PBP finds the TRISx.x bit by adding $80 to the ports address.
Here's the .LST from a LOW PORTA.0

00194 ; C:\ISIS\5US_INTS\ASMCNCGUY5US.PBP 00076 Z0001D LOW PORTA.0
001F 00195 Z0001D
00196 LOW?T _PORTA??0
001F 100C M bcf PORTA, 000h
0020 0021 M movlb (((PORTA) + 80h)) >> 7
00000001 M PREV_BANK = (((PORTA) + 80h)) >> 7
0021 100C M bcf ((PORTA) + 80h), 000h


But if you give it LATA.0, adding $80 makes it point to ANSELA instead of TRISA.
The TRIS bit doesn't get set, and the ANSELA gets changed.

http://www.pbpgroup.com/files/PORTvsLAT.GIF


I think I am most excited about the PRx knowledge. :)
And now you know why not to use LATx.x as a pin.

Knowledge is Power, and Power is intoxicating ...
Please drink responsibly. :)

cncmachineguy
- 4th December 2010, 18:04
Awesome stuff Darrel. THANK YOU!!

BTW, I find it quite inpossible not to Think and drive, so I best check my BAC before going out