Skip to content
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
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Implement PWM #39

wants to merge 5 commits into from

Conversation

CobaltCause
Copy link

@CobaltCause CobaltCause commented Nov 14, 2021

  • Initial attempt
  • A silly/clever workaround for embedded-hal's Pwm trait not mapping super well to the BL602
  • Cleanup/actual usable MVP (minus Pwm::get_period)
  • Extra functions for messing with BL602 specific things

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.
@tpimh
Copy link

tpimh commented Jul 18, 2023

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 pwm.

@CobaltCause
Copy link
Author

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants