Really slow digital input


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2006
    Posts
    76

    Default Really slow digital input

    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

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mbw123 View Post
    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).

  3. #3
    Join Date
    Jul 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    Thanks for the response.

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

    -Mike

  4. #4
    Join Date
    Jul 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    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

  5. #5
    Join Date
    Jul 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    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

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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.
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Jul 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    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

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mbw123 View Post
    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!

Similar Threads

  1. Sony LanC Program
    By l_gaminde in forum Code Examples
    Replies: 2
    Last Post: - 25th September 2009, 18:51
  2. How do I get 18f452 pin 10 set as digital input?
    By jessey in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 26th May 2007, 18:32
  3. 18F4550 digital input
    By mbw123 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 29th March 2007, 02:43
  4. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50
  5. Analog pins for digital input
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th September 2005, 00:32

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts