PDA

View Full Version : Buttons are driving me nuts



Doormatt
- 21st May 2007, 22:25
Don't you hate when you got the complicated thing to work, but the simple things just seem beyond you?

I'm building a IR Camera trigger using a PIC 16F648A, and I spent all last night getting the 38.5Khz modulated carrier to work perfectly. I was testing it on a timer, so that every 5 seconds, it would send the pulse out. I now want to try triggering it from a button press, but I don't seem to be having ANY luck getting the PIC to see the press.

Code is as follows:


@ device pic16F648A, wdt_off, intrc_osc_noclkout, mclr_off, protect_off
DEFINE OSC 4
CMCON = 7 ' Turn all comparators to fully digital (needed??)
TRISB.3 = 0 ' IR Output Pin
TRISB.4 = 1 ' Shutter Input Pin
HPWM 1,127,38500 ' Configure HPWM for 50% duty cycle PWM signal at 38.5kHz
CCP1CON = 0 'PWM OFF

start:
while TRISB.4 = 1 : WEND
gosub shutter
pause 250
goto start


I've tried using "While TRISB.4 = 0 : WEND", and that (if memory serves) just fires the subroutine constantly (which makes sense).

I've attached the "schematic" for how the button is attached, just in case I've mangled that somehow. The button is a normally open momentary contact. I've checked with a logic probe that B4 on the PIC sits low normally, and goes high with the button press.

Sadly enough, I'm pretty sure this is going to be one of those simple "you missed..." answers.

Thanks in advance!

mister_e
- 21st May 2007, 22:43
TRISB configure i/o as input or output while PORTB is the place to read/write from/to.

try...

<font color="#000000"> @ device pic16F648A, wdt_off, intrc_osc_noclkout, mclr_off, protect_off
<font color="#000080">DEFINE </font>OSC 4
CMCON = 7 <font color="#008000">' Turn all comparators to fully digital (needed??)
</font>TRISB.3 = 0 <font color="#008000">' IR Output Pin
</font>TRISB.4 = 1 <font color="#008000">' Shutter Input Pin

</font>start:
<font color="#000080">WHILE </font>PORTB.4 = 0 : <font color="#000080">WEND
GOSUB </font>Shutter
<font color="#000080">PAUSE </font>250
<font color="#000080">GOTO </font>start

Shutter:
<font color="#000080">HPWM </font>1,127,38500 <font color="#008000">' Configure HPWM for 50% duty cycle PWM signal at 38.5kHz
</font><font color="#000080">PAUSE </font>500
CCP1CON = 0 <font color="#008000">' PWM OFF
</font><font color="#000080">RETURN
</font>

Doormatt
- 21st May 2007, 22:47
Thank you SO much!

I feel like an utter idiot for making that mistake.

mister_e
- 21st May 2007, 23:09
I guess you will never do it again :D

Don't worry about that, take your time, understand what you do, and enjoy the result.

We are here to help anyway.