PWM signal to digital?

Discussion in 'The Projects Forum' started by Edmunds, Jul 31, 2014.

  1. Edmunds

    Thread Starter Active Member

    Sep 27, 2010
    85
    0
    Hi all,

    I have a project, where a couple of servos are kept in the middle, turned right or turned left. This is done by a MCU. Easy.

    I also need an optocoupler to switch on per each turn state. So 8 LEDs for 4 servos. It is easy to achieve through the MCU, but "eats" 8 output pins. Is there a way to do it electronically? I mean is there a device or a combination of components, preferably very small footprint, that would be able to interpret the servo signal and switch the right optocoupler of the two on or off depending on the PWM signal?

    Sorry if it makes no sense at all. Just something that crossed my mind.


    Thank you for your time,

    Edmunds
     
  2. KMoffett

    AAC Fanatic!

    Dec 19, 2007
    2,574
    230
    To control multiple LEDs with less than one MCU I/O per LED, Google: Charlieplexing

    Ken
     
  3. crutschow

    Expert

    Mar 14, 2008
    12,969
    3,219
    If you can interrupt the PWM signal momentarily then you could perhaps send a coded signal during the blank time to indicate the direction of the signal for the next train of PWM signal. But that would require some logic at the other end to interpret the signal and latch the direction of the servo for the PWM signal that follows the coded signal.

    Another possibly simpler way is to use slightly different PWM frequencies for each direction and detect the frequency at the output to determine the direction.

    Edit: Thought of a third way. You could reverse the phase of the PWM signal to indicate the motor direction and detect that phase change. Of course this would mean using one additional opto isolator to sent the reference phase signal to compare to the PWM signal.
     
    Last edited: Jul 31, 2014
  4. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,786
    825
    What type of servos are you using?
     
  5. Alberto

    Active Member

    Nov 7, 2008
    169
    36
    If I understand correctly, the optocouplers will act as limit switches activated by the servo position. If this is the case, then the leds on/off state will be autonomous, in other words you do not control the leds they are controlled by your servo position. At least you will need 8 inputs to tell the MCU the actual position of the two servo.

    Alberto
     
  6. Edmunds

    Thread Starter Active Member

    Sep 27, 2010
    85
    0
    No. You could say the LEDs need to correspond to the servo positions. Or indicate servo positions. I just need a LED ON on servo right and another LED ON on servo left. Optocoupler is just LED in that sense.

    Edmunds
     
  7. KMoffett

    AAC Fanatic!

    Dec 19, 2007
    2,574
    230
    The MCU turns on a specific LED/optocoupler if the MCU sends a specific servo in a specific direction? The optocoupler controls something else?


    Ken
     
    Last edited: Jul 31, 2014
  8. Edmunds

    Thread Starter Active Member

    Sep 27, 2010
    85
    0
    The poor thing is controlling loads of things. I will go that route if nothing else comes up. I just thought it maybe there is an electronic way. I'm looking at charlie multiplexing now. Let's see.

    Edmunds
     
  9. Edmunds

    Thread Starter Active Member

    Sep 27, 2010
    85
    0
    Thank you for your reply. Can you elaborate on the third way? I will look into swapping the PWM phase, but how would you use "another opto isolator" for the reference phase signal?

    Edmunds
     
  10. Bernard

    AAC Fanatic!

    Aug 7, 2008
    4,170
    394
    Assuming that a 1.5 ms pulse = center, then use a 4060 IC, clock- counter, to count to 7 in 1.5 ms. Four outputs connect to a 74C85, 4-bit comparator, second set of inputs, execpt # 8- low, hard wired high. At less than 1.5 ms, the les than output with a driver could turn on opto coupler for L, left, 1.5 ms = center, greater than 1.5 ms = R, right. ??
     
    djsfantasi likes this.
  11. Edmunds

    Thread Starter Active Member

    Sep 27, 2010
    85
    0
    Thank you for your input. 1.5 ms is the centre. Can you elaborate on your concept? A bit above my shelf I think at the moment :)

    Edmunds
     
  12. crutschow

    Expert

    Mar 14, 2008
    12,969
    3,219
    You would send a reference clock through the extra opto with a frequency equal to the PWM signal and a fixed phase with respect to the leading (non changing) edge of the PWM signal. One phase would have the two leading edges identical in phase. The other would have the PWM leading edge phase shifted by 180°. Then you could use a digital edge phase-detector, such as used in the CD4046, to give an indication of relative phase of the leading edges.
     
    Last edited: Jul 31, 2014
  13. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Seconded. To drive 8 LEDs with charlieplexing requires just 4 pins.

    Actually 4 pins will drive 12 LEDs;
    LEDs = n * (n-1)
    LEDs = 4 * (4-1) = 12

    Another alternative is a common 74595 serial-in parallel-out shift register IC. That requires 2 pins to drive, and will operate 8 LEDs.
     
  14. Bernard

    AAC Fanatic!

    Aug 7, 2008
    4,170
    394
    Might try a simpler idea depending on accuracy required. Assume that servo signal is amplified to a peak amplitude of 10V & applied to an R C ckt. so that with a 1.5 ms pulse, charge on C would reach 5 V. Two comparators with a ref V of 4.9 V, & other 5.1V, other inputs to C. Outputs each go to R & S of a a R-S flip-flop, reset- set FF. C V low FF reset, C V high FF set. If output is only for visual the short i ms reset blink might not be noticed, otherwise S & R can be averaged for high.
    Comparator can drive opto-coupler.
    S-R latch , something like 4043, 4 in IC.
     
  15. crutschow

    Expert

    Mar 14, 2008
    12,969
    3,219
    Unless I misunderstand, I think the op is passing a PWM signal through 4 of the optos so I don't think any form of multiplexing will work for those signals.
     
  16. KMoffett

    AAC Fanatic!

    Dec 19, 2007
    2,574
    230
    Ya know, I don't think any of us know what the OP is doing!

    Ken
     
  17. Bernard

    AAC Fanatic!

    Aug 7, 2008
    4,170
    394
    My take is tha OP wants a remote indication of position of 4 servos, purpose of opto couplers un known.
     
  18. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    I'm confused too. May I ask;

    (1) are you controlling the four Servos from the microcontroller?
    (2) do you need LEDs to indicate if new_servo_pos is < or > old_servo_pos?

    If you answer yes to both those questions and you're just looking for a way to reduce the amount of pins needed to drive eight LEDs, then I too would recommend using a Charlieplexed matrix of LEDs (four pins) or an eight bit serial-to-parallel IC (one or two pins) for the LEDs.

    Good luck on your project.

    Regards, Mike
     
    Last edited: Jul 31, 2014
  19. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,786
    825
    What are the servo arms operating/connected to? Is it possible to physical mount a sensor to the servo case that can detect the position of the arms? A photodetector, opto interruptor, Hall effect, micro switch, etc…?

    I started to design something based on Bernard's idea, but it quickly became complicated. Perhaps a cheap $2 PIC could be programmed to identify the PWM frequency and control two LEDs.
     
  20. Edmunds

    Thread Starter Active Member

    Sep 27, 2010
    85
    0
    Dear all,

    I think we should call it a day and I should go with another I2C 8 port I/O expander along with 4 that I already have on the project. Thank you for the suggested solutions, but it seems solving it "externally" is far more complicated than just adding more expansion ports.

    Edmunds
     
Loading...