PDA

View Full Version : do I need an interrupt?



peterdeco1
- 20th July 2006, 18:10
Hello Everyone. I think I am in need of using an interrupt but can't get one to work. While constantly monitoring my inputs, I need another port to go high for approximately 1/2 second, go low for about 3 seconds and continue this until all of my inputs = 0. I can't use HIGH and PAUSE commands because it will miss the action on the inputs during the pause. I am also using both of the HPWM ports so I can't use them for this function either. If anyone can add some simple snippets in my code and briefly explain what is happening to accomplish this, I would greatly appreciate it.


'COMPILED FOR 16F73
adcon1 = 7 ' set inputs to digital
@ DEVICE WDT_ON, BOD_ON, PWRT_ON, PROTECT_ON
TRISA = %00100100 'RA2 & RA5 ARE INPUTS
TRISB = %01111001 'RB0, 3, 4, 5, 6 ARE INPUTS
TRISC = %00000001 'RC0 IS INPUT

START:
(MAKE THE MYSTERY PORT LOW)
IF PORTB.0 = 0 THEN START

WORK:
(MAKE THE MYSTERY PORT HIGH FOR 500 AND LOW FOR 3000 MS WITHOUT MISSING ACTION ON INPUTS)
DO SOMETHING HERE & THERE
IF PORTB.0 = 0 THEN START
GOTO WORK

Acetronics2
- 20th July 2006, 20:23
Just drive pin 4 from the Mystery slave circuit ( 8 pins ooooooold timer , cmos version available, its generic number is 3 times 10 halves ... )

Alain

mister_e
- 20th July 2006, 21:15
OK, do a search for Timer interrupt first. in the interrupt routine you'll have to determine:
1. i'm i on the HIGH pulse?... since how may time? enough? if so do the low pulse
2. same as 1 for low pulse

try it. If there's any other problem, i see some method.

OR do a short pause loop, check the pin state in the loop.

peterdeco1
- 21st July 2006, 14:29
what I did was

START:
IF PORTB.0 = 0 THEN START

WORK:
DO SOMETHING HERE & THERE 'this takes 250ms to complete
LET X = X + 1
IF X > 333 THEN GOSUB GOHIGH
IF PORTB.0 = 0 THEN START
GOTO WORK

GOHIGH:
HIGH PORTC.3
PAUSE 500
LOW PORTC.3
LET X = 0
RETURN

So, after about 3 seconds my port goes high for 500ms but I still have a 500ms + 250ms = 750ms gap where my inputs are ignored. A 555 one-shot would work fine but I want to avoid adding more circuitry if possible.

Acetronics2
- 21st July 2006, 15:13
Hi,

As all your inputs are on PortB ... why not use the simple feature " interrupt on PortB change " ???

you just have to check which input caused the interrupt and do what needed ...

That would not disturb your PWM sections nor make great changes to your tempo's, even if a basic interrupt used.

( note it's an Excellent excercise for trying Darrel's Instant interrupts, too ... )

just change PAUSE 500 to

For i = 1 to 500
PAUSE 1
Next i

... as stated in the MANUAL, Basic interrupts section ....


Alain