PWM signal to digital?

Thread Starter

Edmunds

Joined Sep 27, 2010
85
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
 

crutschow

Joined Mar 14, 2008
34,409
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:

Alberto

Joined Nov 7, 2008
169
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
 

Thread Starter

Edmunds

Joined Sep 27, 2010
85
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
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
 

KMoffett

Joined Dec 19, 2007
2,918
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
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:

Thread Starter

Edmunds

Joined Sep 27, 2010
85
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
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
 

Thread Starter

Edmunds

Joined Sep 27, 2010
85
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.
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
 

Bernard

Joined Aug 7, 2008
5,784
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. ??
 

Thread Starter

Edmunds

Joined Sep 27, 2010
85
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. ??
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
 

crutschow

Joined Mar 14, 2008
34,409
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?
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:

THE_RB

Joined Feb 11, 2008
5,438
To control multiple LEDs with less than one MCU I/O per LED, Google: Charlieplexing
...
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.
 

Bernard

Joined Aug 7, 2008
5,784
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.
 

crutschow

Joined Mar 14, 2008
34,409
Seconded. To drive 8 LEDs with charlieplexing requires just 4 pins.

...........................
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.
 

MMcLaren

Joined Feb 14, 2010
861
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:

djsfantasi

Joined Apr 11, 2010
9,160
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.
 

Thread Starter

Edmunds

Joined Sep 27, 2010
85
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
 
Top