# PWM and digital logic

Discussion in 'The Projects Forum' started by Georacer, Oct 8, 2012.

1. ### Georacer Thread Starter Moderator

Nov 25, 2009
5,173
1,284
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%.

2. ### Sensacell Moderator

Jun 19, 2012
2,016
632
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?

3. ### Georacer Thread Starter Moderator

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

4. ### t06afre AAC Fanatic!

May 11, 2009
5,939
1,227
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.

Georacer likes this.
5. ### Sensacell Moderator

Jun 19, 2012
2,016
632
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?

6. ### Georacer Thread Starter Moderator

Nov 25, 2009
5,173
1,284
@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.

7. ### Markd77 Senior Member

Sep 7, 2009
2,803
596
I'd be tempted to use a small micro to buffer the signal and move to a neutral postion if the signal is lost.
Depending on the servo, if it has power but no signal, it will either stop or move fully to one side.
Or get one of these, which is prebuilt.
http://www.active-robots.com/servosafe-servo-failsafe.html

8. ### Georacer Thread Starter Moderator

Nov 25, 2009
5,173
1,284
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...

9. ### Markd77 Senior Member

Sep 7, 2009
2,803
596
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.

10. ### Georacer Thread Starter Moderator

Nov 25, 2009
5,173
1,284
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?

11. ### Georacer Thread Starter Moderator

Nov 25, 2009
5,173
1,284
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.

12. ### Georacer Thread Starter Moderator

Nov 25, 2009
5,173
1,284
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.

13. ### t06afre AAC Fanatic!

May 11, 2009
5,939
1,227
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

14. ### Georacer Thread Starter Moderator

Nov 25, 2009
5,173
1,284
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.

15. ### Georacer Thread Starter Moderator

Nov 25, 2009
5,173
1,284
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.

16. ### Markd77 Senior Member

Sep 7, 2009
2,803
596
Yes, once it's set up it doesn't use any resources. They are pretty small, available in SOT 23-6 package.

17. ### Georacer Thread Starter Moderator

Nov 25, 2009
5,173
1,284
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.

18. ### ScottWang Moderator

Aug 23, 2012
6,411
991
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.

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

19. ### THE_RB AAC Fanatic!

Feb 11, 2008
5,432
1,312
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?

20. ### Georacer Thread Starter Moderator

Nov 25, 2009
5,173
1,284
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.