Input


Closed Thread
Results 1 to 21 of 21

Thread: Input

  1. #1
    ECaro03's Avatar
    ECaro03 Guest

    Post Input

    I am a beginner at this, so bare with me please.

    I am trying to write code that when I receive an input of roughly around 5 volts into porta.0 in a PIC16F684 that it will blink an LED.

    this is what I got:

    define osc 4

    trisa = %11111111
    trisc = %00000000

    portc = %00000000

    left var byte
    left = 0

    loop:
    left = porta.0
    if left = 1 then
    portc.0 = 1
    pause 2500
    portc.0 = 0
    endif
    goto loop

    end

    Please help me correct the problem.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    welcome to the forum ECaro03!

    Your code is not to far but you must know the followings...

    1. PIC16F684 use several oscillator config. Default setting is suppose to be 4MHZ. but it's safe to use this line at the top of your code.

    OSCCON=%01100000 'define internal oscillator to 4MHZ


    2. you must turn off a/d converter to read digital signal from PORTA by using

    ANSEL=0 'turn off a/d


    3. you also must turn off analog comparator by using

    CMCON0=%00000111


    now i sugest the following modify code.

    Code:
    OSCCON=%01100000 'define internal oscillator to 4MHZ
    ANSEL=0 'turn off a/d
    CMCON0=%00000111
    
    trisa = %11111111
    trisc = %00000000
    
    portc = %00000000
    
    left     VAR     PORTA.0 'define left as PORTA.0 status
    
    
    loop:
         if left then
              portc.0 = 1
              pause 2500
              portc.0 = 0
         endif
    
         goto loop
    what about now?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    ECaro03's Avatar
    ECaro03 Guest


    Did you find this post helpful? Yes | No

    Smile

    Thanks for your help...It's getting late here so I will try it first thing tomorrow morning and let you know how it goes.

  4. #4
    ECaro03's Avatar
    ECaro03 Guest


    Did you find this post helpful? Yes | No

    Question help again

    Thank you for your help with the code. I went a little further and added a right to my code to go along with my left, so now I have two LEDs.

    I tried the following code:
    -------------------------------------------------------------------
    osccon = %01100000
    ansel = 0
    cmcon0 = %00000111

    trisa = %11111111
    trisc = %00000000

    portc = %00000000

    left var porta.0
    right var porta.1

    loop:
    if left then
    portc.0 = 1
    pause 2500
    portc.0 = 0
    porta.0 = 0
    left = 0
    endif

    if right then
    portc.1 = 1
    pause 2500
    portc.1 = 0
    porta.1 = 0
    right = 0
    endif

    portc.3 = 1
    pause 120
    portc.3 = 0
    pause 120

    goto loop

    end
    -------------------------------------------------------------------

    The Result:
    when porta.0 is triggered, portc.0 turns on 5 times

    when porta.1 is triggered, portc.0 turns on 1 and then portc.1 turns on 4 times

    Questions:
    1. why is it doing that? I just want it to light up once.

    2. is there a way I can have two ports light up at the same time? (i.e. porta.0 and porta.2 turn on at the same time if I add more LEDs) what I get when that happens is only one turns on at a time.

    I look forward to your reply and thanks for your help again.

  5. #5
    ECaro03's Avatar
    ECaro03 Guest


    Did you find this post helpful? Yes | No

    Post

    the portc.3 part is just flashing another led so I know when it is going through the loop

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    The Result:
    when porta.0 is triggered, portc.0 turns on 5 times

    when porta.1 is triggered, portc.0 turns on 1 and then portc.1 turns on 4 times

    Questions:
    1. why is it doing that? I just want it to light up once.
    what do the trigger??? push button, jumper ? The reason is because you have to wait untill the trigger is release. so the following will resolve the problem.


    Code:
    osccon = %01100000
    ansel = 0
    cmcon0 = %00000111
    
    trisa = %11111111
    trisc = %00000000
    portc = %00000000
    
    left var porta.0
    right var porta.1
    
    loop:
         if left then
              portc.0 = 1
              While left 'wait until left is release to 0V
              Wend
              pause 2500
              portc.0 = 0
              porta.0 = 0
         endif
    
         if right then
              portc.1 = 1
              While right 'wait untill right is release to 0V
              Wend
              pause 2500
              portc.1 = 0
              porta.1 = 0
         endif
    
         portc.3 = 1
         pause 120
         portc.3 = 0
         pause 120
    
    goto loop

    2. is there a way I can have two ports light up at the same time? (i.e. porta.0 and porta.2 turn on at the same time
    Sure...

    let's say you want to turn Porta.0 and Porta.2 at the same time
    PORTA=%00000101

    that's it
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    ECaro03's Avatar
    ECaro03 Guest


    Did you find this post helpful? Yes | No

    Unhappy

    The triggering mechanism is a motion sensor. It sends a 5v trigger to the microchip when it is activated.

    What is happening with the current code that you just sent me is that when the left sensor sends a pulse to the microchip, the LED at portc.0 turns on for about 8 seconds and then shuts off. When the right sensor sends a pulse to the microchip, the LED at portc.0 flashes, then the LED at portc.1 turns on for about 8 seconds and then the LEDs flash ramdomly a couple times.

    Is there a way to reduce the eight second delay? I tried shortening the pause, but that did not have much effect.

    The plan is to replace the LEDs and have them lead to an H-bridge that controls a motor. Basically a type of camera tracking system.

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    which motion sensor are you using?

    what about now if you remove those lines

    portc.3 = 1
    pause 120
    portc.3 = 0
    pause 120

    is this motion sensor is a rotary encoder??? can you add an simple pulldown resistor on input pin let's say 10K or lower???

    let me know
    ¸
    regards
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #9
    ECaro03's Avatar
    ECaro03 Guest


    Did you find this post helpful? Yes | No

    Default

    it's a PIR sensor.

    after playing around with the microchip....it seems that the input channel is super sensitive.

    when I tried putting in the resistor with my hand it activated the code

    what's going on there?

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    it's because you PIC input is floating when there's no 5volts from PIR at the input. You need to tie it to ground with resistor. This way PIC will see high level and low level(produce by resistor).
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  11. #11
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Default Motion sensors

    Hi ECaro03,

    When a motion sensor is triggered it must wait until the movement it has detected has gone and the logic circuits stabilize and return the output to an off state. This would probably explain why you circuit (LED) remains on for the eight seconds.

    The micro triggering from you putting the resistor in place could be static from you body or perhaps you put the resistor to +v instead of ground.

    BobK

  12. #12
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Default Motion sensors

    Hi ECaro03,

    When a motion sensor is triggered it must wait until the movement it has detected has gone and the logic circuits stabilize and return the output to an off state. This would probably explain why your circuit (LED) remains on for the eight seconds.

    The micro triggering from you putting the resistor in place could be static from you body or perhaps you put the resistor to +v instead of ground.

    BobK

  13. #13
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    i do not agree with the resistor to V+.... trigger works when activated... we detect high level... so in this case when there's no trigger PIR is floating, resistor must be put to ground.

    AND the above code i post is already waiting for trigger release.

    regards
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  14. #14
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    If you're using (left var porta.0), and have this pin set to an input, why are you trying to clear the pin with (porta.0 = 0)..?

    Just let your sensor handle the logic level transitions.

    Some sensors have a certain amount of hysteresis so it may take a while for the sensor to initially trigger or for the output to settle & return to the idle state once the trigger condition is removed.

    The PIC input pin will see a logic 1 until the sensor outputs falls below the PIC +V input threshold level.

    If you need to speed up the process of returning to the idle state, you can probably add a 10K or more pull-down resistor to help discharge the sensors output, but I would check the datasheet for the sensor you're using first. If the sensors output doesn't hold the PIC input at ground when idle, you'll need the pull-down anyhow.

    Using mister_e's WHILE WEND suggestion works really well, but the sensor output needs to fall below the PIC +V input threshold before it will exit the WHILE WEND. That could explain the delay.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  15. #15
    ECaro03's Avatar
    ECaro03 Guest


    Did you find this post helpful? Yes | No

    Default

    I took out the sensor all together and now I am just manually plugging in 5v. I touch the pin for a split second and I am still having problems.

    I feel as if I am missing something.

    The pin is so sensitive that I can touch a wire to it and it senses input. Figure that one out...I sure don't know. Since digital 1 is 5v.

    And the spazzing out of the LEDs is confusing me as well. Why when the right = 1 it runs through the if statement of the left once then goes through the right if statement.

  16. #16
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Thanks Bruce, simple suggestion here to avoid long delay from PIR

    place RC circuit to produce short pulse from PIR output.


    if you do it manually... also put pull down resistor.... it's working on my bench here

    Last edited by mister_e; - 2nd December 2004 at 02:33.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  17. #17
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Since digital 1 is 5v.
    It doesn't necessarily take 5V on an input to register as a logic 1. Only a +V above the PIC logic 1 input threshold level.

    If you touch an input pin or wire connected to the input, depending on the voltage level present on the input pin, your environment, body capacitance, static charge, etc,, you may be introducing a signal of sufficient magnitude to allow the input to see a certain voltage level or a brief change in voltage level.

    Try something like this;

    10K
    input pin -------/\/\/\/\-----+5V
    |
    |
    |---o___o---- gnd
    switch

    If you leave the input floating, then touch the wire or pin, it will definitely spazz-out.

    If you hold the input at a certain logic level through a pull-up or pull-down, then the signal or discharge from touching the pin will need to be of sufficient magnitude to over-ride the pull-up or pull-down for the input to see the change.

    Even a very fast spike on an input may register since the PIC is operating (and testing input logic) very fast. Even at a lowly 4MHz your PIC is executing single-cycle instructions at 1 million per second.

    If you connect a sensor to an input, and the sensor has a high impedance output, it may be allowing the PIC input to float when the sensor output is not actively pulling the PIC input to ground or +V.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  18. #18
    ECaro03's Avatar
    ECaro03 Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks guys for all your help.

    I looked over my circuit again and saw that I wasn't using the pull down resistor properly so it was left floating....ugh I feel so stupid now...lol

    Anyways I appreciate your help.

    ONE LAST THING.....

    I am trying to have multiple ports on at the same time....

    portc.2 to turn on along with portc.0
    portc.3 to turn on along with portc.1

    what's the code for that? and can you explain the binary code with it?

  19. #19
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    >>And the spazzing out of the LEDs is confusing me as well. Why when the right = 1 it runs through the if statement of the left once then goes through the right if statement.<<<

    Are you programming your chip with MCLR=OFF?

    If you are programming with MCLR=ON, make sure you have the MCLR pin tied high to 5 volts.

    I know this sounds "Odd", but I have ran into spazzing chips, and found I forgot to put MCLR=OFF. Thus the chip was floating on and off.

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  20. #20
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Hi ECaro03

    I looked over my circuit again and saw that I wasn't using the pull down resistor properly so it was left floating....ugh I feel so stupid now...lol
    Hehe it happen to me one but i was using correctly... my sh... breadboard was the trouble. Some of those have supply line who break at the middle... when i discover it... AAARRGH!!!

    am trying to have multiple ports on at the same time....

    portc.2 to turn on along with portc.0
    portc.3 to turn on along with portc.1

    what's the code for that? and can you explain the binary code with it?
    that's simple when you know how.
    PORTC=%00000101 'turn on C.2 and C.0
    PORTC=%00001010 'turn on C.3 and C.1
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  21. #21
    ECaro03's Avatar
    ECaro03 Guest


    Did you find this post helpful? Yes | No

    Talking IT'S DONE

    Wohoo!!!

    Everything is working great now!!!

    I have been stressing out so bad over this project.

    This project was for a senior electrical engineering design lab that takes a semester.

    There are four of us (two electrical engineering majors and two computer engineering majors) in the group.

    What our project is:
    A PIR sensing camera that keeps a figure within the boundaries of the sensors using a motor. The camera is also hooked up to a computer that records in a video format.

    Uses:
    1. Recording a speaker at conferences
    2. Security

    We demo this system on Monday for the student body in the engineering building here on campus.

    Our final report (approx. 100 pages) is due on Wednesday and we should have a website up showing our project. I will make sure to post that link once it comes available.

    Thanks for eveybody's help, it was greatly appreciated!!!

    Esteban
    Computer Engineer '05
    Texas A&M University

Similar Threads

  1. Sony LanC Program
    By l_gaminde in forum Code Examples
    Replies: 2
    Last Post: - 25th September 2009, 18:51
  2. problem with input and output (18F452)
    By turkuaz in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th March 2008, 23:21
  3. LED "capacitance" won't get lower
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 3rd May 2007, 20:31
  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. Using LEDs as light sensors
    By skimask in forum Code Examples
    Replies: 3
    Last Post: - 30th December 2006, 22:19

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