logical control of led with sensors

Discussion in 'Embedded Systems and Microcontrollers' started by varunme, Jan 9, 2012.

  1. varunme

    Thread Starter Member

    Sep 29, 2011
    59
    0
    In a series of sensors, with corresponding LEDs of which if the corresponding sensor got intercepted the LED goes 100%, other wise its 50%, it goes on 100% till the adjescent sensor is intercepted, how can we implement this idea ?, i used various codes with bit shifting, gates etc , none is working, anyone have a better idea ?
     
  2. praondevou

    AAC Fanatic!

    Jul 9, 2011
    2,936
    488
    Your description is lacking a lot of information. For example voltages from the sensors, how many sensors, LED current etc.

    Doesn't sound to difficult. Could be done with simple FFs, one for each sensor.
    Using the SET inputs to activate the outputs , the outputs would then reset the adjacent FFs via their RESET inputs.

    You then need an oscillator which is simply enabled/disabled by the output of the FF. Could be a CMOS oscillator with a toggle FF after it to achieve 50%.

    100% is always on, that would be the /Q output of the toggle FF. e.g. a 4013.
    You then need driver for the LED, transistor etc.
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    100% and 50% of what?

    If brightness, take sample LED, drive with current to get desired 100% brightness. Record current. Repeat for 50% and also record current.

    Based on supplied voltage and LED ON voltage calculate resistor to yield 100% current.

    To get 50%, compute ratio of current to give 50% over current to give 100%. Use this ratio as a pulse width control ratio to get LED average current to match 50% current.
     
  4. praondevou

    AAC Fanatic!

    Jul 9, 2011
    2,936
    488
    Somehow I got confused :D:D:D


    When I saw 50% I automatically thought "50% duty cycle PWM"... Let's see what the OP says... If he comes back
     
  5. varunme

    Thread Starter Member

    Sep 29, 2011
    59
    0
    yes, by PWM
    I want to attain these through an uC.
    The sensors are photodiode/phototransistor.
     
  6. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    Then first you need to get PWM working. Have you done this? Bit banging should be pretty easy. For 100% on you could simply make the port high always. For 50% toggle the pin off and on.
     
  7. varunme

    Thread Starter Member

    Sep 29, 2011
    59
    0
    yes, i have done that
     
  8. varunme

    Thread Starter Member

    Sep 29, 2011
    59
    0
    XOR ing the portc input to portd is making the conditions except the one which , the LED has to be at 100% till the adjescent sensor is intercepted.
     
  9. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Code around that special case with a conditional test to provide 100%
     
  10. varunme

    Thread Starter Member

    Sep 29, 2011
    59
    0
    i used

    Code ( (Unknown Language)):
    1.  
    2. input_state = portc; // store the input value
    3. portd |= input_state  // set to high the outputs that represent an input that has 1
    4.  
    5. portd ^= ~input_state;   // invert the portd bits when the same bit in input_state is 0 , leaves bits with 1 in input_state unchanged
    6. delay_ms(a);
    7. portd ^= ~input_state;  // invert the portd bits when the same bit in input_state is 0
    8. delay_ms(b);
    9.  
    10.  
    can you suggest to implement the idea i said, that is to hold on 100% till an adjescent sensor is intercepted ? My code goes to 50% as soon as the obstacle from the sensor is removed
     
    Last edited: Jan 10, 2012
  11. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    How often are the signals changing, and what are the contents of PORTC?

    What is the "problem bit" with that direct approach?
     
Loading...