Connect with us

Revised inputs from optocouplers

Discussion in 'Microcontrollers, Programming and IoT' started by abuhafss, Oct 7, 2014.

Scroll to continue with content
  1. abuhafss

    abuhafss

    348
    11
    Aug 3, 2010
    I am absolutely a newbie in PIC programming. Only have experience of playing with LEDs.

    For a new project, I am considering to incorporate PIC16F887 or something similar.

    Following is the flow of the process:
    1) Power ON
    2) Analog section sends outputs from 6 optocouplers to the PIC
    3) Depending upon the state (High/Low) of these inputs from the optocouplers, the PIC processes and sends output to some, LEDs and 3 relays via transistors.
    4) The relays revise the outputs of the optocouplers
    5) Again the PIC processes and sends the final output to LEDs

    How the outputs from the optocouplers be interfaced with the PIC?
    I shall be using PICBasicPro.
     
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    10,609
    2,370
    Nov 17, 2011
    It depends on the type of optocoupler you use.
    If you use on with a logic output (active), you connect it directly to the PIC's inputs as you would connect a logic gate.
    If you use an optocoupler with an open collector output, use a pull-up resistor to generate a logic level signal.

    Read this ressource.
     
  3. abuhafss

    abuhafss

    348
    11
    Aug 3, 2010
    Perhaps, my question is not clear.

    I wanted to know how to handle those inputs in programming, do I have to use interrupts?
     
  4. Harald Kapp

    Harald Kapp Moderator Moderator

    10,609
    2,370
    Nov 17, 2011
    Sorry, this wasn't really obvious from your 1st post.

    You can, but you don't necessarily have to use interrupts. You can also poll the inputs.It al depends on the circumstances like:
    - do you have enough inputs on the µc that are capable of generating an interrupt at all. If not, you will require extra logic.
    - how often do you expect the inputs to change? If they change often, polling may have an advantage over interrupt handling.
    - how long is the allowed latency from a changed input to recognition within the program? Interrupts may provide less latency than polling.
    - how much processing time can you spend on polling the inputs? Polling will take up more processing time than handling interrupts.
     
    KrisBlueNZ likes this.
  5. abuhafss

    abuhafss

    348
    11
    Aug 3, 2010
    Could you please elaborate? This would be my first project with such inputs. And I have very little programming experience.

    The µC can be selected according to the requirement. I have 6 inputs and 14 outputs.

    Only once.
     
  6. Harald Kapp

    Harald Kapp Moderator Moderator

    10,609
    2,370
    Nov 17, 2011
    follow the link, polling is described there. In addition, heres's a discussion of polling vs. interrupts.
    But often not all inputs are capable of generating an interrupt. In this case you will need external logic to create an interrupt whenever an input changes and then read the status of the input pins into a variable for further evaluation.
    Once per second, per minute, ...?
     
  7. abuhafss

    abuhafss

    348
    11
    Aug 3, 2010
    It is quite clear in the first post. Here is the flow of the process:

    1) Start - Power ON
    2) Analog section sends outputs from 6 optocouplers to the PIC
    3) Depending upon the state (High/Low) of these inputs from the optocouplers, the PIC processes and sends output to some, LEDs and 3 relays via transistors.
    4) The relays revise the outputs of the optocouplers
    5) Again the PIC processes and sends the final output to LEDs
    6) Stop - Power OFF

    On receiving the first set of inputs, the µC generates output, which is locked.
    After receiving the revised inputs, the µC generates further/additional output, which is final.
     
  8. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    How does the microcontroller know when these signals from the analogue section are valid and should be actioned? Are they valid immediately on power-up? Or after a short time? Or something else?

    Is there a time constraint between when the micro reads these states and when it sends the appropriate states to the relays and LEDs?

    How does the micro know when the new input values from the optocouplers are valid? Does it just wait a fixed amount of time?

    Is there a time constraint on the microcontroller calculating and outputting the new states?

    If there is no particular time constraint, there's no need for interrupts.
     
    Last edited: Oct 8, 2014
  9. abuhafss

    abuhafss

    348
    11
    Aug 3, 2010
    After a very short time, almost immediately.
    Lets suppose the six inputs' states are 1, 1, 1, 0, 1, 1

    The µC sends output within few microseconds.

    As soon as the relays receive output from the PIC, the states of the six inputs change something like 0, 1, 0, 0, 1, 0

    There is no calculation/processing involved. Just decision making, read the inputs and send the outputs.
     
    Harald Kapp likes this.
  10. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    Is that important? The relays will take typically 2~3 ms to activate...
    If that's controlled by the relays, they won't update immediately. The micro will need to wait a few ms to be sure the relays have activated and the inputs are valid.
    So the outputs are a direct copy of the inputs? In that case you could just use 74HC374 or similar latch.

    We could go back and forth for a few dozen more posts trying to figure out the best way to do what you want. But how about describing the whole project to us, so we know exactly what you want to do, and why. That generally saves a lot of time.
     
  11. abuhafss

    abuhafss

    348
    11
    Aug 3, 2010
    Well, please visit this site
    I want to use this circuit + PIC to have an LED-based result. Here is my idea:
    BJT pin identifier.gif I simply want to replace the LEDs with optocouplers and the switches with relays.
    The outputs from the optocouplers will be fed into the PIC which will:

    a) illuminate a green LED if the transistor is PNP or a yellow LED if the transistor is NPN
    b) illuminate a red LED if the base is connected to red wire OR a blue LED if connected to blue OR green if connected to green wire

    c) after a short delay (if required) energizes the coil of the relay connected to base lead. This will change the states of inputs from the couplers. The PIC will now

    d) illuminate the specific color LED, corresponding to the lead color, connected to the collector
    e) and similarly another LED for emitter

    OPTIONALLY
    f) illuminate an additional LED to indicate ----> darlington
     
  12. Harald Kapp

    Harald Kapp Moderator Moderator

    10,609
    2,370
    Nov 17, 2011
    Use Polling - your µC seems to have nothing else to do, so it can as well spend its time in a polling loop.
    Add debouncing - the relay contacts will bounce (give multiple contact events for one switch event. This site shows you how to do it in hardware or software.
     
  13. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    abuhafss likes this.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-