Author Topic: Raspberry Pi and PWM  (Read 1415 times)

0 Members and 1 Guest are viewing this topic.

Offline XaviPachecoTopic starter

  • Regular Contributor
  • *
  • Posts: 243
  • Country: do
Raspberry Pi and PWM
« on: August 23, 2018, 12:24:40 am »
Hello,

I've heard that PWM from raspberry is not so "good". I really don't know if it's true or not. Is the Pi good for controlling the speed of a small DC motor? I would like to control the speed a 20V DC motor. I can do all the research by myself. This question is basically to know what you think about it, or if you have done this before. I've always used PWM from other microcontrollers, never from the Pi.
 

Online moffy

  • Super Contributor
  • ***
  • Posts: 2106
  • Country: au
Re: Raspberry Pi and PWM
« Reply #1 on: August 23, 2018, 12:44:07 am »
They have done some extremely high frequency PWM on the PI, they built an FM tramsmitter. So PWM on the PI is OK, but cheaper and easier alternatives are the Arduino UNO/Nano. Dollars vs 10's of dollars and the Arduino programming environment is very easy to use.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13121
Re: Raspberry Pi and PWM
« Reply #2 on: August 23, 2018, 12:48:27 am »
It depends how you handle the PWM.   

Assuming you are using Python, the native GPIO module's GPIO.PWM() function is software PWM.   Anyone who's ever scoped a  GPIO.PWM signal or even set the frequency to within the audio range and listened to it on a speaker, will be aware how rough the result is, as other threads vary the CPU load and thus the latency of the PWM thread.  Basically, it sucks and any motor you control with it will twitch worse than a hyperactive kid on a sugar and caffeine high!

Personally I've moved away from using the native GPIO module and switched to using the pigpio library, which is much much better at generating low-jitter PWM (and other waveforms) as it uses hardware timer interrupts.  http://abyz.me.uk/rpi/pigpio/python.html

If you are using C and don't want to have to delve into the depths of the Linux kernal, priority levels and BCM283x register level programming, then the pigpio library is still (IMHO) the best bet.
 

Offline frozenfrogz

  • Frequent Contributor
  • **
  • Posts: 936
  • Country: de
  • Having fun with Arduino and Raspberry Pi
Re: Raspberry Pi and PWM
« Reply #3 on: August 23, 2018, 12:57:51 am »
For PWM on the RasPi I would recommend checking out the pigpio library. It is far superior to RPI.GPIO and WiringPi. Also software timed PWM in pigpio seems to be quite accurate.
The board has only a couple hardware timed PWM pins available, software timed PWM can occasionally be quite a struggle.
He’s like a trained ape. Without the training.
 

Offline XaviPachecoTopic starter

  • Regular Contributor
  • *
  • Posts: 243
  • Country: do
Re: Raspberry Pi and PWM
« Reply #4 on: August 23, 2018, 12:58:56 pm »
Thanks for your comments.  I will try the pigpio library. I guess I will have to use a logic-level FET for this purpose, due to the Pi GPIO voltage (3.3V)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf