PWM switch - autonomous boat with Raspberry Pi

Hello everyone! This is my first post.

I am building an autonomous boat. As a master steering system I wanted to use RC's radio, as a secondary I wanted to use Raspberry Pi. To choose the steering source I wanted to use one of the channels from the radio receiver - 1 would mean radio as a source, 0 - Raspberry Pi. To choose which system is in use I need electronic element to choose which PWM signal is forwarded. Is there already built electronic part to do such thing? I was thinking about preparing something by myself, with 2 AND gates and one XOR (as presented on the diagram below). The question is, if I indeed have to build it myself, will the gates be the good choice? I don't know if the PWM can be forwarded through a gate because of its high speed of changes (of the frequency)? I assume that it is relevant. Maybe there is a different, better solution?








I will be grateful for your help!

PWM Gates

Couple of comments:

  • This is something that can be simulated on a PC prior to building.
  • I think you want an OR gate. Might be simpler with open collector and pullup resistor.
  • PWW for motors is in the KHz range while gate switching is in the high MHz range. If it really is a concern you might want to consider adding 2 enables such that both signals can be OFF.


Good luck and keep us posted.


Thank you ggallant for your quick answer!

  • I will prepare a simulation, thank you for this notice.
  • XOR was intentional, as I would like to exclude situation where I have two 1 as input - this would be an error and the engine should be shut off)
  • Thank you for this information about the frequency range. I will carry on with the simulation. Could you only explain what did you mean by “adding 2 enables”?


As drawn, the only time both AND gates could have high outputs is during the inverter gate switch (10 nsec) time. Since your are driving motors not not logic, I don’t see this as a problem. If you had 2 steering signals you could first disable both AND gates and then select the active one.


Hello again,

I was not writing for so long as I was thinking about switching the output between autonomous (RPi) and manual (RC) directly from Raspberry Pi, but as it is not the best safety measure I’ve gone back to the external switch solution. I have found a convenient unit - SN74HC157, quad 2:1 mux.

Manual -> SN74HC157

The problem is that it is difficult to steer it with PWM (pin 1 on the unit) as it is not a DC current but would rather switch the unit constantly from one state to the other  (if I am thinking correctly)… Do you have any idea how to get the current from PWM which could be recognised as 1 or 0? I have measured the voltage and it’s 209 mV on channel PWM signal output and 372 mV with the other position of the switch. I know that it is possible to be done with Arduino but I would rather avoid it as its only function would be to convert PWM signal. Maybe there is something simple I didn’t hear about.

PWM Switching

I am somewhat confused. 

  1. Can you post a schematic drawing of what you circuit is?
  2. Most logic (SN74HC157 etc) can supply milli amps.
  3. What are you using to measure the PWM signals with?



PWM switching


So basically I just wanted to connect the output from receiver to "Select A/B" pin on SN74HC157 to select the steering source for the boat. The thing is, I assume to flaten the signal and put it above and below the tresholds for high and low state, which are as presented here.


The voltage ratio between the two PWM signals from receiver (372 mV and 209 mV) is quite small but I hope there is a way to make the signal from receiver visible as high and low state because the usual amplification wouldn't solve the issue (the gap would be too small).

PWM -> high/low state

I will simply use the Atmega microprocessor to get high and low state from it. I will post the code soon, maybe it will be helpful for someone :slight_smile:


I use the term PWM for two slightly different purposes. First is when controlling a DC motor via an h-bridge type driver. In this mode the duty cycle is the percentage of ON time during the period frequency is in the 10KHz range. Second is when driving hobby servo motors where the pulse width is centered around 1500usec and repeats approx every 20 msec.

You have 2 signals, motor and servo. Is the motor an ON/OFF and the servo a hobby drive? Or is the motor a high speed PWM?



It is high speed PWM I assume. It has the frame of 20 msec and with one position of the switch I get 1ms singal and in the other 2ms in the frame. The thing is to check if the high signal is for more or less than 1,5 ms I guess. I’ll see what I can do :slight_smile:


That is typical for servos. What does the motor signal look like?