PDA

View Full Version : how to return to a specific location after dt_ints



dorro1971
- 7th June 2009, 20:14
hi all,

firstly i would like to thank mr. Darrel Taylor for his brilliant dt_ints..!

and secondly....

I think i have read about it somwhere on this forum but cannot find it again!

could anyone tell me if there is a way to return to a specific label after a dt_int interrupt rather than the point at which the it occurred??

kindest regards in advance

ian.

Darrel Taylor
- 8th June 2009, 01:19
Hi ian,

If you're using an 18F, there's this ...

http://www.picbasic.co.uk/forum/showthread.php?p=67719#post67719

Although I still don't recommend it.
<br>

tenaja
- 8th June 2009, 13:29
Modifying the stack like that is an advanced programming technique, and can be used with great success. However, since most PBP programmers find it difficult enough just to successfully author a rudimentary interrupt routine, newbies should avoid it.

A better way for the inexperienced is to sit in a loop and wait for a flag that is set in your interrupt. (A flag is typically a bit variable, changed between 0 and 1.) When the loop detects the flag, jump to your target.

dorro1971
- 9th June 2009, 21:19
thanks alot guys,

i can't sit in a loop and wait...looks like i got some experimenting to do..
.....better crack open a can or two..three....four...

best regards

ian

tenaja
- 10th June 2009, 14:09
Just remember that sometimes a loop has lots of code in it. Just because you are sitting in a loop and waiting does not mean you are doing nothing.

dorro1971
- 21st January 2010, 21:08
Hi all,

Thank you for a great forum....i mean REALLY great!

I don't post very often, usually only when i need help..i know it's a little selfish but....

any way! i am designing a controller for a plastic film winding machine,

all my code works very well, i am using darrel's brilliant dt_ints for ccp1 ,portb change, serial usart and tmr0.

ok, now for my "issue" :
i am using ccp2 for hpwm and also 2 off sofware pwm's

when i have high rpm's you can hear the software rpm signal being "coloured" by the ccp1 interrupts, it is not a problem as the pwm works very well, it is more of a niggle than anything.


i would like to include the rpm calculation in the ccp1 interrupt but there is no way i can at the moment.

i know dt_ints saves data before and restores data after the interrupt, would it be any quicker to use assembly ?..well i suppose it would but i don't know where to start with interrupts in assembly


i already run the tacho through a flip flop to reduce the freq and due to responce times i don't really want to capture *4 or 16 rising edges.

if any one could start me off with an assembly call to a ccp1 int handler and how to return from it i would be really gratefull!


thanks in advance and p.s. here are my code snippetts..(please don't laugh at my code,,, i am still learning!)









'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 1/21/2010 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
''device=18f2620

osccon.0=1 ' internal osc
osccon.4=1 ' int oscillator
osccon.5=1 ' scaling for
osccon.6=1 ' 8 MHZ

DEFINE ADC_BITS 8 'Set number of bits in result
DEFINE ADC_CLOCK 3 'Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 5 'Set sampling time in microseconds

CCP1CON = %00000100 'capture timer0 every falling edge portc.2

t0con.0=0 'timer0 on
t0con.1=1
t0con.2=0
t0con.3=0
t0con.5=0
t0con.6=0
t0con.7=1
'yadda yadda yadda! etc






ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?

int_handler rx_int, _read_usart, pbp, yes
INT_Handler CCP1_INT, _get_pulsewidth, PBP, yes
int_handler int0_int, _feed_request, pbp, yes
int_handler int1_int, _heat_request, pbp, yes
int_handler int2_int, _get_position, pbp, yes
int_handler tmr0_int, _no_pulse, pbp, yes


endm
INT_CREATE ; Creates the interrupt processor
ENDASM















'------------------------------------------[tacho pulse interrupt routine]---------------------------------------------------
get_pulsewidth:

t1con.7=0 'stop the timer
pulsewidth.lowbyte=tmr0l 'get the low byte timer result
pulsewidth.highbyte=tmr0h 'get the high byte timer result
tmr0h=0 'zero the
tmr0l=0 'timer
pulse_ok=1
t1con.7=1 'restart the timer

@ int_return

'--------------------------------------[no valid rpm signal, timer1 overflow]-----------------------------------------------
no_pulse:
pulse_ok=0
rpm=0
@ int_return

Darrel Taylor
- 21st January 2010, 21:34
Capture mode of CCP1 works with Timer1 or Timer3, and it captures pulses on the CCP1 pin not from Timer0.
The captured value is stored in the CCPR1L,CCPR1H registers.

But your CCP int handler stops Timer1, Reads Timer0, clears Timer0 then restarts Timer1.

I think you need to take a closer look at what's really happening.
<br>

dorro1971
- 21st January 2010, 23:09
in the immotal words of Homer Simpson

DOH!

thankyou D.T.

sometimes the wood does get in the way of the trees