-
Notifications
You must be signed in to change notification settings - Fork 14
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
Implement PWM #39
Draft
CobaltCause
wants to merge
5
commits into
sipeed:main
Choose a base branch
from
CobaltCause:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Implement PWM #39
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It works though, vaguely.
PwmPin doesn't map that well either, since it assumes each pin has a unique PWM instance, but it's presumably possible to share PWM channels on multiple pins on the BL602
This works around the limitation of embedded-hal's Pwm trait not supporting the controlling of periods per channel, which the BL602 allows.
I'm not sure what to do about periods where `period >= 1s` or `period % 1s == 0`. The `get_period` function is still unimplemented because of this, I think any fix for the former would probably have a large effect on the latter, so it's less work for now to just put it off.
Tiggilyboo
pushed a commit
to Tiggilyboo/bl602-hal
that referenced
this pull request
Apr 23, 2023
Tiggilyboo
pushed a commit
to Tiggilyboo/bl602-hal
that referenced
this pull request
May 1, 2023
This reverts commit af816ce.
Trying to use it now using the adapted example code: #![no_std]
#![no_main]
use bl602_hal::{pwm, prelude::_bl602_hal_gpio_GlbExt};
use embedded_time::duration::Milliseconds;
#[riscv_rt::entry]
fn main() -> ! {
let dp = bl602_hal::pac::Peripherals::take().unwrap();
let clocks = bl602_hal::clock::Clocks::new();
let mut parts = dp.GLB.split();
let mut channels = pwm::Channels::from((dp.PWM, clocks));
pwm.channel2.enable(&()).unwrap();
pwm.channel2.set_period(Milliseconds::new(20)).unwrap();
let duty = 5 * (pwm.channel2.get_max_duty().unwrap() / 100);
pwm.channel2.set_duty(duty).unwrap();
parts.pin17.into_pull_down_pwm();
loop { }
} And I get E0423: expected value, found module |
IIRC I stopped working this and then forgot about it because I encountered a bug somewhere wherein the observed PWM was half or double (can't remember) the specified PWM and couldn't figure out why this was happening. Tbh, not sure if I'll pick it back up, though it would be nice to finish this... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pwm::get_period
)