PWM and digital logic

Thread Starter

Georacer

Joined Nov 25, 2009
5,182
I 'm building the computer for my UAV and I want to implement some failsafe.

As many of you know, the receiver of RC models outputs a PWM signal that drives the servos. I have an extra channel and I want to use it as a digital ON-OFF, in order to operate a MUX that will insert/isolate the uC from the control loop.
Thus I can choose whether I want to fly on manual or aided. I don't want to let this duty to the same uC, as I fear software bugs and crashes.

So the question is: how can a PWM control a digital IC input?

At first I thought about simple rectification, but unfortunately, the range of the PWM signal isn't full. It goes at about as high as 10%.

Thanks in advance.
 

Sensacell

Joined Jun 19, 2012
3,453
If I understand your question correctly, you want to have the output of one RC PWM channel converted to a clean on-off TTL signal, correct?

How about using a charge pump to convert the duty cycle into a voltage, then put in through a comparator with some hysteresis to generate a logic level output?
 

Thread Starter

Georacer

Joined Nov 25, 2009
5,182
I may have it wrong in my head, but wouldn't a charge pump reach maximum voltage if unloaded? Regardless of the duty cycle.
 

t06afre

Joined May 11, 2009
5,934
If you want something to happen then a pulse-train signal is lost. You can in its simplest form use a 74xx122 retriggable one shot. Or program one of those 8 pins MCU to do the job.
 

Sensacell

Joined Jun 19, 2012
3,453
Yes- you are correct.

Put a load resistor on the output cap - RC time constant of 10 X the PWM frequency and it will output a voltage proportional to the duty cycle. I think the frequency of those RC signals is about 50 hz? Can you deal with a 0.5 second response time?
 

Thread Starter

Georacer

Joined Nov 25, 2009
5,182
@Sensascell

Yes, 0.5s is doable. I 'll give it a shot.

@t06afre

Yeah, a second mini MCU may be the solution at the end. But I 'd like to view it as a last resort.

A trigger would be a nice idea. I just need to find if I can produce a sufficiently low DC so that it doesn't trigger in the "OFF" mode.

Thanks!

P.S. Of course, other opinions are always welcome.
 

Thread Starter

Georacer

Joined Nov 25, 2009
5,182
The said unit must operate the MUX, which in turn will select the signal source for the servos: either the onboard uC or directly for the RX unit. False signals aren't an issue for the servo driving.

I hope the switching won't produce any problems...
 

Markd77

Joined Sep 7, 2009
2,806
Sorry, I misread the question.
If you do decide to use a micro, the PIC10F320 has a pretty handy feature, the configurable logic cell. If I'm reading the datasheet correctly you should be able to route the signal from either of two pins to another pin and the code to detect if the other pin has a regular pulse should take no time.
 

Thread Starter

Georacer

Joined Nov 25, 2009
5,182
So you 're saying that I can use the PIC for both the MUX and the condition evaluation? If so, that's very handy indeed.

Not that it's crucial, but is this "hardwired" in the setup, allowing for other code to run in the same time?
 

Thread Starter

Georacer

Joined Nov 25, 2009
5,182
Hm... on a second thought, I need 3 or 4 data channels, so that leaves me needing 3 or 4 PICs. Not that space-economical.

Maybe I 'll go with the IC solution. 1 MUX (large-ish) and 1 IC/circuit to make the condition evaluation.
 

Thread Starter

Georacer

Joined Nov 25, 2009
5,182
If you want something to happen then a pulse-train signal is lost. You can in its simplest form use a 74xx122 retriggable one shot. Or program one of those 8 pins MCU to do the job.
Do I have any reason to prefer the 74122 to a smaller 555 if I want only one control signal? The 74122 has 4 input signals and is DIP14.
 

t06afre

Joined May 11, 2009
5,934
Do I have any reason to prefer the 74122 to a smaller 555 if I want only one control signal? The 74122 has 4 input signals and is DIP14.
Not else that I am not 555 person ;) I have little tradition for using the 555 chip. If the 555 do the job just use it
 

Thread Starter

Georacer

Joined Nov 25, 2009
5,182
Tough luck. The PWM signals can have a maximum range from 979 to 2020us each. The pulse detection can't work because there is always a pulse, albeit of variable length.

I 'll try the PWM-to-analog approach now.
 

Thread Starter

Georacer

Joined Nov 25, 2009
5,182
I 've run some simulations, and my impression so far is that either with a charge pump or without it, effectively any RC filter circuit cannot serve the purpose I intend it to. At least with a low order filter.

The problem is that the PWM has a period of 20ms and its HIGH time is from 870 to 2020us. This is a very small change, in contrast to the period and a very small HIGH time in contrast to the period. This prevents any RC circuit from giving out a significant DC value and any resolution between the big and small value.
It's a no go.

Onwards to the mini microcontrollers. I think I 'll give a shot to the PICAXE tomorrow.
 

Markd77

Joined Sep 7, 2009
2,806
So you 're saying that I can use the PIC for both the MUX and the condition evaluation? If so, that's very handy indeed.

Not that it's crucial, but is this "hardwired" in the setup, allowing for other code to run in the same time?
Yes, once it's set up it doesn't use any resources. They are pretty small, available in SOT 23-6 package.
 

Thread Starter

Georacer

Joined Nov 25, 2009
5,182
I read the datasheet and it's pretty handy but it does basic logic functions and FF services. I would need to use two back to back to make a MUX. Plus I 'd need 4 ICs, as I said, and that ruins it for me.

I 'll go for a PICAXE+74157 circuit tomorrow.
 

ScottWang

Joined Aug 23, 2012
7,409
Many years ago, I met a scan pulse should be change to the control signal as your needed, the difference is that your pulse isn't fixed.

I haven't try your PWM pulse yet, if you want then you can try it.
1N4148x1, Rx2 , Cap x3, calculating the values to match your need.

╨────╨────╨────
─┬─|>|───┬─./\/\/\,─┬─
..└./\/\/\/'─┤.............│
...............〒............〒
...............▽.............▽
 

THE_RB

Joined Feb 11, 2008
5,438
As there are 50 pulses per second, you can get the PIC to analyse the length of one pulse at a time and still test all 4 signals in 4/50ths of a second.

That should be fast enough for things that need a "digital on/off" under RC control?
 

Thread Starter

Georacer

Joined Nov 25, 2009
5,182
As there are 50 pulses per second, you can get the PIC to analyse the length of one pulse at a time and still test all 4 signals in 4/50ths of a second.

That should be fast enough for things that need a "digital on/off" under RC control?
I could use an interrupt to capture the rise of the PWM pulse and trigger a measurement loop.
BUT I would need to do the same for the four other servo control channels. The interrupt channels come short. There may be a way, but I don't want to delve into it right now. Maybe towards the end on the optimizations stage.

The arduino bootloader has a routine for measuring the HIGH time of a PWM signal, but it needs a mean time of 10-15ms. My loop has a 40ms delay so far because of this function. I don't want to enlarge it right now and that's why I go parallel.
 
Top