PWM noise on Raspberry Pi - Page 1
Forum section: electronics / beginners

author: sugarfree90
author_rank: Newbie
timestamp: July 29, 2015, 08:23:14 am
content: Hello!I think this is PWM noise...I am building a robot, i have two tracks which are controlled with two H bridges (or i think so - off the shelf solution), everything is working beautifully, but recently i have added a cheap chinese servomechanism (SG90 Tower Pro) to pivot the camera. The pivot works reasonably well (Raspberry Pi + PWM =) but when i am sending any command to move and engage track motors, the servo is going crazy.To power this thing i am using a 2A switching voltage regulator (and 7.2V Li-Ion battery)My command to move servo looks like that (python):pwm = GPIO.PWM(18, 200) <-initializing servo on pin 18 with 200Hz PWM modulationpwm.start(25) <- setting in% value of PWM signaltime.sleep(0.3) <-time for servo to movepwm.stop() <-switching off the signal and leaving the servo in previously defined positionI am initializing servo for each swing and deactivating it after that in order to prevent the shaking which occurs due to poor Raspberry Pi PWM capabilitiesAnd this works as a charm (well... almost...)I am powering this servo directly from the Raspberry Pi pins and thourgh that the voltage drops at RPi are making this interference so i have installed 10V 1000uF cap on servo power wires - servo is still crazy...My solution will be to controll power of the servo with a transistor, or add an arduino...But for now, any ideas what to or why is this happening?

author: piranha32
author_rank: Unknown
timestamp: July 29, 2015, 06:03:25 pm
content: I don't know Raspi, but my guess is that the PWM signal is generated by software. Since the OS is not real time, and the CPU is rather lousy, there will be many random delays in toggling the I/O pin, which will affect the timings. If you have more tasks which require hard-RT timings, using a dedicated micro for handling them will be a good idea, however, if you only need to drive servos, take a look at one of the PWM LED driver chips. E.g. PCA9685 will give you 16 servo channels, controlled via I2C bus.Another issue is the repetition frequency. Most modern servos should handle 200Hz quite well, but it may be too much for some. Try to lower it to 20-25Hz and see what happens.

author: Chris C
author_rank: Frequent Contributor
timestamp: July 30, 2015, 09:19:59 pm
content: A small servo can easily use 100mA when moving just itself and its horn. When moving weight (like that of your camera), it can consume many times more.I looked up the maximum current a Raspberry Pi GPIO pin can source. Saw a few different figures, from 16mA to 33mA. Not enough to power a servo, even in a best-case scenario.Attaching a capacitor and allowing it to charge up before movement is requested, will allow for a brief burst of motion. But you'd need a very large cap. 1,000uF is only enough for perhaps a few tens of milliseconds at best, probably much less. Your servo is "rebooting" over and over.You *might* be able to get this working without any additional parts by using several GPIO pins in parallel to supply power, with each supplying a portion of the needed current. But that's iffy, and on a robot, you'll probably need those pins for other things.So personally, I wouldn't bother with that, and would use a transistor instead. Or use an alternate method to generate higher-quality PWM, so that switching the power off to the servo when it's not supposed to be moving isn't necessary; like an Arduino or the PCA9685  mentioned.

author: piranha32
author_rank: Unknown
timestamp: July 30, 2015, 09:32:28 pm
content: Quote from: Chris C on July 30, 2015, 09:19:59 pmGPIOs are not used to power the servo. Typical servo has 3 wires. Two are connected directly to power supply and provide power for the motor. The third wire is connected to the control circuit and should pose a negligible load. The reasons why I would use a buffer on the control line are: isolate the CPU output from external circuit as a form of protection (which by itself is a very good reason to add a buffer), or to provide level translation if servo requires higher voltage signal.

author: Chris C
author_rank: Frequent Contributor
timestamp: July 30, 2015, 10:09:37 pm
content: Quote from: piranha32 on July 30, 2015, 09:32:28 pmGiven the "I am powering this servo directly from the Raspberry Pi pin...my solution will be to controll power of the servo with a transistor" part, it looked as if he might currently be attempting to power the servo from a GPIO. If so, that's a separate problem than the irregular PWM from the Pi, which you covered well.

author: sugarfree90
author_rank: Newbie
timestamp: July 31, 2015, 10:25:27 am
content: Yest the PWM is generated with software, but i am initializing the PWM only to move servo, when i am moving the tracks this problem occurs and during that, no PWM for this servo is generated, i am initializing PWM to move servo then i am cutting off the servo signal.I am connecting the servo to the power 5V pin in raspbbery and i can get as much amperage as usb can provide so this is not an issue, besides of that the camera is on a well ballanced hinge so the torque required to pivot here is minimalI will install arduino then... Why i2c? Why is this better than com port?

author: Chris C
author_rank: Frequent Contributor
timestamp: July 31, 2015, 02:08:57 pm
content: The Pi is restricted in the amount of current it can supply from its USB power lines, compared to a regular computer/laptop. As little as 100mA on an unmodified Pi, depending on exact model and configuration. I'm not a Pi user and don't recall the exact details, but this may be of help:http://raspberrypi.stackexchange.com/questions/340/how-much-power-can-be-provided-through-usbI2C is a two-wire interface, much like a basic com port. But unlike a com port, it allows multiple devices to share those two wires. Each device has an address, and when you send out a command, you prefix it with the address of the device you want to communicate with. Only the addressed device listens, the rest ignore. Good for reducing the amount of wires and hardware resources to control the multiple systems on a robot.

author: Bob F.
author_rank: Regular Contributor
timestamp: July 31, 2015, 05:35:51 pm
content: Simplest solution:http://www.adafruit.com/products/2327

author: piranha32
author_rank: Unknown
timestamp: July 31, 2015, 06:18:15 pm
content: Quote from: sugarfree90 on July 31, 2015, 10:25:27 amIf you're not driving the servo, weird things can happen. Most likely it will not hold position, but can also move on its own.Quote from: sugarfree90 on July 31, 2015, 10:25:27 amHigh current is required not only to move the load, but also there is a surge when the servo starts. You can try to add a big electrolytic capacitor, but it has to be charged at some point, and the power lines may have problem to deliver enough current. Better connect the power leads directly to the power supply.Quote from: sugarfree90 on July 31, 2015, 10:25:27 amI mentioned I2C because PCA9685 uses it. For arduino serial port will be much better (and easier) choice.Also, did you try to lower repetition rate? I had problems with position holding when the pulse frequency was too high.