PDA

View Full Version : 12F675 and interrupt



perides
- 23rd September 2008, 11:28
At first, sorry for borring you with my dumb ass question. Totally newbie trying to do a simple thing and canīt figure it out.

When a 12f675 pin goes low, another pin goes high (to turn on a lamp). Done.
When the same pin goes high (by the internall pull-up resistor) the pin with a lamp delay for 5 seconds and fade out (with pwm) to zero. Done.

But thatīs drive me crazy:

Iīve need some kind of stuff (code of course) that when:

If a third ping goes high and if the first pin changes to low or if lamp is in delay, delay was cancelled (but yet fade off)

Try to do with picbasic interrupt, Darrelīs interrupt and nothing. Can anyone show me some directions, code samples, anything :-)

Thanks and sorry for the bad English.

skimask
- 23rd September 2008, 12:13
Try to do with picbasic interrupt, Darrelīs interrupt and nothing. Can anyone show me some directions, code samples, anything :-)

Let's see your code that doesn't work...

Acetronics2
- 23rd September 2008, 12:22
Hi, Pericles



"If a third ping goes high and if the first pin changes to low or if lamp is in delay, delay was cancelled (but yet fade off)"


The simple way ...

instead of " PAUSE 5000" for the delay ...

just use




...
' Conditionnal DELAY - tests "Pincancel" pin every 10 ms

FOR I = 1 to 500
IF Pincancel = 1 THEN jumpover
PAUSE 10
NEXT I

jumpover :
' Fading sequence
...



That's all !

Interrupts ... Interrupts ??? What's that for ???

Alain

perides
- 23rd September 2008, 15:20
Thank you all.

I followed your directions Acetronics but and coded above. Maybe it work, maybe they need some fixes.

Simulating (no development board in class yet) in proteus, an strange behavior occurs on GPIO.0 they always stays up, even Iīve (I think at least) disabled pullup for them. Other pins appears ok.

What Iīve missed??

BTW, Perides, not Pericles. But no problem, common misspelling. :-)




' Pinout *
' 1 vdd vss 8 *
' 2 gp5/t1cki/osc1/clkin gp0/an0/cin+/icspdat 7 *
' 3 gp4/an3/t1g/osc2/clkout gp1/an1/cin-/vref/icspclk 6 *
' 4 gp3/mclr/vpp gp2/an2/tockin/int/cout 5 *
' *
'************************************************* ***************
@ device pic12F675, WDT_OFF, PWRT_ON, MCLR_OFF, INTRC_OSC_NOCLKOUT
define osc 4

CMCON = 7 'comparator off
ANSEL = 0 'all digital
'VRCON = 0 'comparator off

TRISIO= %000011 '1=in 0=out

'Enable PULL-UPS
OPTION_REG.7 = 0 'enable pullu-ps (0 enable/1 disable)
WPU = %000010 '1=on/0=off each pullup - enable pull-up only TK


L15 var GPIO.0 'line 15
TK VAR GPIO.1 'door sensor
LAMP VAR GPIO.2 'bulb
myPWM VAR word

main:
If TK = 0 Then LAMP = 1 'if TK goes down so LAMP goes UP

IF TK = 1 and LAMP = 1 then 'if TK goes down and LAMP is yet on
IF L15 = 1 THEN 'and we have canceled delay
goto justfade 'so go to fade lamp
else
GOTO delay 'and if delay was not canceled go to delay+fade
endif
ENDIF
GoTo main

delay:
FOR myPWM = 1 to 500 '500 loops for 5 second of 10ms delay
if L15 = 1 then justfade 'if L15 goes up so end delay
pause 10 'wait 10ms
next myPWM

justfade:
for mypwm = 255 to 1 step -1
PWM LAMP, myPWM, 255 'pwm bulp
if TK = 0 then GOTO main 'if TK goes down
NEXT myPWM
goto main

Acetronics2
- 23rd September 2008, 16:12
Hi,

Sorry, but simulator behaviour is something making me laugh too much ...

my last program didn't want to run on MPSIM ... but has been working more than fine for two weeks now ... ( Was a periodic signal generator, interrupt driven ...)

sooo, I can't help you further in the virtual world ...

Alain

BTW ... Periclčs was for joke ...

perides
- 23rd September 2008, 17:47
Hi Alain

I agree with you about sims.
The code appears to be in the right way at least?

Acetronics2
- 23rd September 2008, 18:24
Hi,

I never use pullups ...

you should try to add external resistors ... even on the sim' ...

you also should avoid PWM command for such uses ... this outputs an awful garbage ( just usable with a RC filter to make a basic D/A converter. )

as you have written the program ...

it is easy to do it like that :



for mypwm = 1000 to 0 step -1
High LAMP
PAUSEUS myPWM,
LOW Lamp
PAUSEUS (1000 -myPWM)
Next myPWM



note PAUSEUS has a minimum duration ... but it is not a problem here !!!

Alain

sayzer
- 23rd September 2008, 18:39
The code seems to be ok;
To make it even easier to see, drop the red part.




IF TK = 1 and LAMP = 1 then 'if TK goes down and LAMP is yet on
IF L15 = 1 THEN 'and we have canceled delay
goto justfade 'so go to fade lamp
else
GOTO delay 'and if delay was not canceled go to delay+fade
endif
ENDIF

and, just use this:

IF TK = 1 and LAMP = 1 then delay





Also, your PWM routine happens so fast that your eyes will not catch the fade effect.
Have a timer loop, say 5ms, in your pwm loop, like "while : wend" and put your pwm pulse inside this "while : wend". Thus, you have a smooth fade effect.

None of these modifications will make your GPIO pin work though.
Just some ideas to make your code better.