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

Add more methods to Pwm<T> #140

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

usbalbin
Copy link

@usbalbin usbalbin commented Apr 19, 2023

Hi :)

I have a use case where I need to update the frequency of several pwm outputs very often, therefore I need access to directly setting the period and/or prescaler registers. This PR does that plus some extra methods like start/pause, and access to setting the prescaler.

src/timer/pwm.rs Outdated
$(
self.tim.arr.modify(|_, w| w.$arr_h().bits((arr >> 16) as u16));
self.tim.arr.modify(|_, w| w.$arr_h().bits((period >> 16) as u16));
Copy link
Author

@usbalbin usbalbin Apr 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pwm! {
    TIM1: (tim1, arr),
    TIM3: (tim3, arr_l, arr_h), // should this really have a `arr_h`?
    TIM14: (tim14, arr),
    TIM16: (tim16, arr),
    TIM17: (tim17, arr),
}

I must say that I am a bit confused about the 16/32bit for TIM3. From what I understand from the reference manual for g0x0 TIM3 is just 16-bit. reference manual for g0x1 says pretty much the same thing except it adds a TIM2 which is 32-bit.

Looking at the pac, TIM3 does have an arr_h(inherited from tim2?), same thing when looking in the reference manual...

Also is it really safe to write to arr in two steps without the pwm signal going crazy in between the stores?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct me if I am wrong but from what I can gather, TIM3 is 16bits but does share the same memory config structure as TIM2(which is 32bit)

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.

4 participants