-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PWM control for Vibro Motor #33
Comments
I created a separate branch for you called Hopefully that helps you to explore. |
Edit: I corrected a few statements I made in my original post to reflect that PWM is still useful, but the frequencies available are too fast to match those that the Open Trickler uses today. All this means is that PWM can't be a drop-in replacement to achieve the same ON/OFF cycles that I coded by hand. Instead, PWM could potentially be used to speed up and slow down the motor more smoothly. I just did a deep-dive to investigate PWM a bit more, hoping that I could incorporate it and close this out. There's a problem: PWM control runs too fast to match the current ON/OFF frequencies. I'll provide an explanation w/ the simplest math I can provide, but first, some facts upfront:
Let's run through an example using PWM to make the motor run as fast as it can. Put another way, the shortest possible ON pulse.
Regardless of what we do next, a 50% duty cycle here would turn the motor ON for half of this total pulse width, in this case Let's look at the slowest possible setting, to use PWM to make the motor run as slow as it can. Put another way, the longest OFF cycle. The highest possible value we can use to set the refresh rate is
We'll continue with the other functions in a moment, but realize that with this pulse width (the slowest we can get), a 50% duty cycle would turn the motor ON for This is still way way way too fast. Regardless, let's keep learning about the other two functions. The usual next step would be to set the Range with
For a simple example, let's do 100:
What you use to set the range is meaningless on it's own, but it is useful with the next function. You can use Carrying on with our example:
So, I hope this helps others to understand what I just learned, which is that PWM probably isn't a great drop-in fit because (as far as I can tell) it's not capable of running at as as slow of a frequency as it runs now. References: |
One more clarification here: The clock division setting seems to define the actual PWM frequency, which isn't affected by other settings. e.g. If you divide the 19.2MHz clock by 512, the result is a PWM frequency of 37.5kHz. No matter what Range you use (10, 100, or 1000), and no matter what Data you use to set a duty cycle, there will only be one ON and one OFF setting for each waveform. That means that the frequency doesn't really change with the Range and Data functions. Changing the Range gives you more or less resolution for the Data setting. I need to conduct some actual tests, but based on a little Googling, the ideal frequency for these motors should be in the range of 3-30kHz, though it may depend on the motor used. That limits the clock division options to the following:
I don't know how much the Range actually matters. It seems like using 100 would make the duty cycle % math pretty easy to understand so I'll probably start there. |
With the motors I'm using, the clock divisions of 256 and 512 seemed to give the best results at a 10% duty cycle. They were barely audible, but perhaps enough to slowly trickle single kernels. Anything higher than that (1024 +) seemed to be too fast to even activate the motor with a 10% duty cycle. |
PWM motor control is now fully supported! |
Wonder if anyone has worked on using pwm to control the vibration motor. A few weeks back someone mentioned it in a post they made, but I cant seem to find it now, and @erichiggins has mention it a time or two. I am trying a rewrite of motor.js to use pwm as implemented in rpio. This doc is what i'm using https://www.npmjs.com/package/rpio reference. I have got the program to not throw any errors when loading but not to actually run the vibro motor. I am unsure what numbers to use for .pwmSetClockDivider (), I used 4096 which is the max allowed and gives the minimum freq of 4.7 kHz. And for .pwmSetRange I used 100, then a point you select in .pwmSetData becomes the On Time (duty cycle)
The text was updated successfully, but these errors were encountered: