PDA

View Full Version : Really slow digital input



mbw123
- 29th March 2007, 22:14
Hello,
I am using an 18F4550 and I am trying to get it to read a digital input and turn on a LED when it is on. For some reason there is a five second pause when I trigger the pin. When I reset the PIC and plug it back in, there is no pause. The pause only occurs when I trigger the pin. The code I am using is below.

It may be important to note that I am using about 10V with a 22K resistor for input, if that has anything to do with it.

Code:
-----------------

rts var porta.2
cts var portd.3
led var portd.2

input rts
output cts
output led

ADCON1 = %00001111

low led : low cts

main:

while rts = 1
high led
wend

low led

goto main

--------------------

Can anyone help?...skimask?

Thanks,

-Mike

skimask
- 29th March 2007, 22:28
Hello, I am using an 18F4550 and I am trying to get it to read a digital input and turn on a LED when it is on. For some reason there is a five second pause when I trigger the pin. When I reset the PIC and plug it back in, there is no pause. The pause only occurs when I trigger the pin. The code I am using is below.
It may be important to note that I am using about 10V with a 22K resistor for input, if that has anything to do with it.
Code:
-----------------
rts var porta.2 : cts var portd.3 : led var portd.2 : input rts : output cts
output led : ADCON1 = %00001111 : low led : low cts
main:
while rts = 1
high led
wend
low led : goto main
--------------------
Can anyone help?...skimask?
Thanks,
-Mike

Is the 22K resistor in series with the pin or is it across Vdd or Vss or what?
Also, write a quick program that turns the LED on and off for 1 second each. This will make sure your PIC isn't running on the internal/backup/failsafe 37khz oscillator for some silly reason.
(4mhz / 62.5khz (desired freq vs actual freq) = 64............64 x 72ms (power up timer) = 4.6 seconds...the math adds up fairly well).

mbw123
- 29th March 2007, 23:31
Thanks for the response.

The resistor is in series with the pin. And I'll try to test the LED program right now.

-Mike

mbw123
- 30th March 2007, 00:47
OK, this is really weird. I made a LED blink program but it takes like 5 seconds to turn on and then it doesn't blink, it just stays on. How do I turn off the 37khz oscillator? Thanks.

-Mike

mbw123
- 30th March 2007, 01:05
Alright, I got it working by changing adding "DEFINE OSC 4." So it works fine now. However, when I tried the original program there is still a pause. When I turn the pin off there is no pause, only when I turn it on is there a pause. Also, when I leave the pin on but reset the PIC it recognizes it immediately.

I am almost positive it has something to do with my input. I am using a serial port (with RTS as the input) and when the RTS is off it says that it is -10 volts. Should I put a diode there or something? I really have no idea how this works, so even a little help understanding this would be greatly appreciated.

-Mike

mackrackit
- 30th March 2007, 01:46
Questions:

1. Does it take 5 seconds for the LED to come on or does the LED stay on for 5 seconds.

2. Have you tried not using serial input to turn on the LED. Not just make it blink like Skimask had you do, but re-write so when PIN? is high LED on. (simple switch )

I am getting at, if the above #2 works fine you may want to look at the signal duty cycle coming in from the serial.

mbw123
- 30th March 2007, 02:20
It takes five seconds for the LED to come on.

I tried to turn it on without using the RTS and it works fine.

Just now, I tried putting a diode on the pin and it actually seems to be working now. I put the diode in because I thought that the -10V when the RTS was off, was a problem (because it worked when not using RTS from the serial port) and therefore a diode might help. I guess I did something right for once. There is no longer a pause and it works just as programmed, finally ;)

Thanks for all the help everyone!

-Mike

skimask
- 30th March 2007, 04:06
It takes five seconds for the LED to come on.

I tried to turn it on without using the RTS and it works fine.

Just now, I tried putting a diode on the pin and it actually seems to be working now. I put the diode in because I thought that the -10V when the RTS was off, was a problem (because it worked when not using RTS from the serial port) and therefore a diode might help. I guess I did something right for once. There is no longer a pause and it works just as programmed, finally ;)

Thanks for all the help everyone!

-Mike

Good deal...
Maybe that negative voltage was screwing with the guts of the PIC somewhere causing it to latch up somehow, WDT kicks in, resets the PIC, and the sequences starts over...
who cares why...it works now...that's all that matters...
Next time you might want to think about a MAX232 or equivalent circuit... Also helps keep you from blowing up pins on a PIC! :)