eltoroit / eltoroit.github.io

Diary of a Salesforce developer on the magical world of electronics. Join me as I share my experiences. Let's learn together!
2 stars 0 forks source link

Raspberry Pi PWM has 4 pins, but only 2 channels #2

Closed utterances-bot closed 3 years ago

utterances-bot commented 3 years ago

Hardware-based PWM with RPIO | ELTOROIT’s Journey

This project builds a simple circuit that uses Hardware-based Pulse-Width Modulation (PWM) with RPIO.

https://eltoroit.github.io/2021/05/30/HardwarePWM-RPIO.html

kempny commented 3 years ago

BCM28(7)xx peripheral chips used in Raspberry have only 2 PWM channels. The PWM0 channel is derived on GPIO12, 18, 40 and 52, PWM1 on GPIO13, 19, 41, 45 and 53 (GPIO numbering according to Broadcom)

Not all BCM2xxx signals are connected to GPIO pins of Raspberry, so we have: Two signals (channels) PWM Four pins on connectors on which these signals can appear On the GPIO12 and GPIO18 pins, the identical signal will appear from the channel 0 The identical signal will appear on the GPIO13 and GPIO19 pins, from channel 1

eltoroit commented 3 years ago

Thanks @kempny, I was not aware of this fact. I thought we only had 4 different signals and I was concerned about how limited that would be for some projects. I actually wrote the code to test it out (please see the full code here).

this._leds = [
    { pin: new LedRPIO(12), value: .4 }, { pin: new LedRPIO(18), value: .2 },
    { pin: new LedRPIO(13), value: .6 }, { pin: new LedRPIO(19), value: .8 }
];

I send a different duty cycle percentage to each of the PWM pins and with an oscilloscope, I check their values. To my surprise, pins GPIO12 and GPIO18 have the same value (20%), and pins GPIO13 and GPIO19 have the same value (80%).

I guess this is another reason to use Software-based PWM with PIGPIO!

kempny commented 3 years ago

Software based PWM in Raspberry is not reliable, due to multitasking operating system, you can use it for lighting control for example, but using it for servomotors control is generally bad idea.

I discussed it in my articeles: http://www.kempny.stanpol/pwm/pwm_en.php and http://www.kempny.stanpol/sg90/sg90_en.php

In the second one you will find my idea, how to control 4 PWM devices with 2 Raspberry PWM channels.


http://kempny.stanpol.com.pl

On Wed, 9 Jun 2021, Andres Perez wrote:

Thanks @kempny, I was not aware of this fact. I thought we only had 4 different signals and I was concerned about how limited that would be for some projects. I actually wrote the code to test it out (please see the full code here).

this._leds = [ { pin: new LedRPIO(12), value: .4 }, { pin: new LedRP IO(18), value: .2 }, { pin: new LedRPIO(13), value: .6 }, { pin: new LedRP IO(19), value: .8 } ];

I send a different duty cycle percentage to each of the PWM pins and with an oscilloscope, I check their values. To my surprise, pins GPIO12 and GPIO18 have the same value (20%), and pins GPIO13 and GPIO19 have the same value (80%).

I guess this is another reason to use Software-based PWM with PIGPIO!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, orunsubscribe.[ALCENR6EKLN26FRCKNYXZNDTR5XNNA5CNFSM46MBM76KYY3PNVWWK3TUL52HS4 DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGMP3TDA.gif]

eltoroit commented 3 years ago

I would like to take a look at your articles, but the links are broken

kempny commented 3 years ago

Sorry, by mistake i sent You my internal links.

The correct are:

http://kempny.stanpol.com.pl/pwm/pwm_en.php

and

http://kempny.stanpol.com.pl/sg90/sg90_en.php


http://kempny.stanpol.com.pl

On Thu, 10 Jun 2021, Andres Perez wrote:

I would like to take a look at your articles, but the links are broken

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, orunsubscribe.[ALCENRZZQLWXSQDAA5QPBJ3TSCHXFA5CNFSM46MBM76KYY3PNVWWK3TUL52HS4 DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGMV4N4A.gif]

eltoroit commented 3 years ago

So, basically, you turn off one pin and generate a signal. Then turn on the other pin and generate a signal. I guess this is fine for servos because you could alternate the pins and it may appear to be turning simultaneously. But does this also work for LEDs or will you see the LEDs blink?

If you need more hardware PWM pins, you could use something like this: https://www.adafruit.com/product/815

jlpoolen commented 6 months ago

Sorry, by mistake i sent You my internal links. The correct are: http://www.kempny.stanpol.com.pl/pwm/pwm_en.php and http://www.kempny.stanpol.com.pl/sg90/sg90_en.php ----------------------------------------------------------- http://kempny.stanpol.com.pl On Thu, 10 Jun 2021, Andres Perez wrote: I would like to take a look at your articles, but the links are broken — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, orunsubscribe.[ALCENRZZQLWXSQDAA5QPBJ3TSCHXFA5CNFSM46MBM76KYY3PNVWWK3TUL52HS4 DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGMV4N4A.gif]

The URLs with "www" in front do not resolve. Remove "www." and then they work. I have confirmed both of the URLs below resolve to something fascinating:

http://kempny.stanpol.com.pl/pwm/pwm_en.php

http://kempny.stanpol.com.pl/sg90/sg90_en.php

Thank you, @kempny ; I look forward to reading the pages on your web site!