Comments (8)
Well, I just found the examples/
dir at the root... I'll check out :)
from phpi.
Nice work. If anything needs clarification, let me know
from phpi.
Yep, thank you, I'm actually trying this library.
from phpi.
Well, I'm experiencing some issues.
I have this script:
include __DIR__.'/vendor/autoload.php';
use Calcinai\PHPi\Pin\PinFunction;
$loop = \React\EventLoop\Factory::create();
$board = \Calcinai\PHPi\Factory::create($loop);
$board->getPin(12)->setFunction(PinFunction::PWM0);
$pwm0 = $board->getPWM(\Calcinai\PHPi\Peripheral\PWM::PWM0)
->setRange(512)
->setEnableMS(true)
->start();
$dc = intval($argv[1]);
var_dump($dc);
$pwm0->setDutyCycle($dc);
$loop->run();
Then I run it with sudo php pwm.php 50
, where 50
is the duty cycle I set from 0 to 100. The effect is that my robot moves as I want, but I could not vary motor speed.
- First, using
sudo php pwm.php 50
seems to set the duty cycle at 100%. So I tried to change range with->setRange(256)
, and run it, but it does nothing, 50 is still setting 100% dc.
Btw I can do with wiringPi in command line: gpio pwm 26 350
, then it works, and 512 seems to be the 100% duty cycle value.
-
Also, I don't find how to use software PWM, for example if I want to run PWM in an other pin, not handled by hardware PWM.
-
Finally, I have seen in some forum that I could use MSMODE for PWM, so can I use
->setEnableMS(true)
to do the trick ?
from phpi.
I can't see any reason that what you've got won't work. Out of curiosity, have you tried omitting ->setRange()
and -> setEnableMS()
?
I had implemented the soft pwm, but it was quite CPU heavy. I'll dig out the example code for that in a sec.
I don't have my test hardware on me at the moment, but I can have a look this afternoon if you can hold on!
from phpi.
Yes I started my tests without setRange
and setEnableMS
.
I don't find any difference with setEnableMS
, just tried.
And I tried setRange(512)
and setRange(256)
to try to fix the setDutyCycle(50)
case, and because I've seen the default one in the library is 1024
. But setDutyCycle(50)
always results in a 100% dc.
I don't need a high frequency PWM (100hz is suffisant as I tried it with python), so I guess software PWM could also be suffisant with PHP.
But in fact I don't really need software PWM for now, I can do without.
from phpi.
@alcalyn - sorry it's taken me so long to get back to you on this one. I've just tested equivalent code:
<?php
include __DIR__.'/vendor/autoload.php';
use Calcinai\PHPi\Peripheral\PWM;
use Calcinai\PHPi\Pin\PinFunction;
$board = \Calcinai\PHPi\Factory::create();
$board->getPin(12)->setFunction(PinFunction::PWM0);
$pwm0 = $board->getPWM(PWM::PWM0)
->setRange(512)
->setEnableMS(true)
->start();
$dc = intval($argv[1]);
var_dump($dc);
$pwm0->setDutyCycle($dc);
And it works as expected. Looking at the range function, it appears to me that that only sets the resolution in the steps - i.e. the setDutyCycle()
will still accept 0-100, but will only respect a resolution specified by the range.
The MS function is supported and working in my case too. Are you sure that the motor driver supports the switching speed? What happens if you connect an LED to BCM 12?
from phpi.
Hi, you're right, I tried your snippet replacing dc motor with a LED, it works as expected !
Also, with your code snippet, setting a duty cycle at 7 or less results as no rotation (but the led is a little on), and setting it from 8 to 100 results as full power (whereas the led light on as expected).
So I thought that my DC motor can't handle PWM, but I think that it's only because the clock has a too high frequency. I think that because I made it work with a software PWM on python (which means low frequency PWM). Then I tried a "software" PWM with:
while (true) {
$pwm0->setDutyCycle(100);
usleep($dc - 10);
$pwm0->setDutyCycle(0);
usleep((100 - $dc) - 10);
}
And I could get some interesting result. But I'm limited because of this line:
phpi/src/PHPi/Peripheral/PWM.php
Line 88 in a44234f
That's why I added - 10
in my usleeps.
Then I also tried to change usleep from this library from 10 to 1, and set a duty cycle at 1, which worked a little better.
So I think that either a software PWM or $pwm->setFrequency
could do the trick. (But I couldn't find how to use setFrequency
).
By the way, PWM works so I close the issue.
from phpi.
Related Issues (11)
- Update board detection logic
- raspbian stretch lite 2018-04-18 freeze HOT 33
- Find another way for event detection ? This lib can crash the OS. HOT 3
- Support for Board revision [b03114/BCM2711] HOT 3
- Fix debounce on digital inputs
- HD44780 LCD Compatibility
- SPI Display Functionality
- Support for Matrix LED display
- Fix I2C HOT 6
- Support board revision 900093/BCM2708 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpi.