Comments (8)
Yeah, I'm super confused how to actually use PWM since we don't have a set_duty
:c
from embassy.
Just ran into this as well trying to use an RGB LED module... It looks like according to the example that the Config
's compare_b
/ top
(for channel b) is the duty-cycle?
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_rp::init(Default::default());
let mut c: Config = Default::default();
c.top = 0x8000;
c.compare_b = 8;
let mut pwm = Pwm::new_output_b(p.PWM_SLICE4, p.PIN_25, c.clone());
loop {
info!("current LED duty cycle: {}/32768", c.compare_b);
Timer::after_secs(1).await;
c.compare_b = c.compare_b.rotate_left(4);
pwm.set_config(&c);
}
}
from embassy.
Yeah, it's weird. The docs have this to say about compare
:
/// The output on channel A goes high when `compare_a` is higher than the
/// counter. A compare of 0 will produce an always low output, while a
/// compare of `top + 1` will produce an always high output.
pub compare_a: u16,
/// The output on channel B goes high when `compare_b` is higher than the
/// counter. A compare of 0 will produce an always low output, while a
/// compare of `top + 1` will produce an always high output.
pub compare_b: u16,
It also says at the top:
/// Note the period in clock cycles of a slice can be computed as:
/// `(top + 1) * (phase_correct ? 1 : 2) * divider`
This was super confusing to me, as it seems from the latter comment that compare_a
& compare_b
ought not to come into the period at all. I think what's happening is we're adjusting one clock (the one representing PWM duty cycle), and if that clock value is higher than another clock (system clock?), the pin will rise? I don't exactly get it, and unfortunately the actual code seems to be making use of low-level MCU features with a lot of magic numbers -- so it's hard to infer from that too.
from embassy.
Yeah I would have expected an implementation more like the NRF & STM32 impls...
I can't seem to get the example for RP to work regardless (Pico W) 🤷
Have a look at the datasheet section 4.5 for more PWM details which help explain a bit of the above... but there is no straightforward conversion from MicroPython examples to this. For example, I don't see how to set the channel frequency... The input_pwm
example uses counter()
as the frequency (in Hz
), but looking at other implementations set_counter()
wouldn't be the correct mapping to the missing freq()
method.
from embassy.
@lulf @Dirbaio tagged you guys as you seem to have been the most recently active in issues..
It would be great to get some sort of response on this issue as we're three waiting for some kind of input...
from embassy.
current status is the API is low-level, you pass in the values that are directly configured in the hardware. The datasheet explains the meaning of those values.
I agree it's not the most intuitive thing, if someone wants to work on adding a higher-level API where you set the frequency and duty cycle and it does the calculations for you, a pull request would be welcome.
from embassy.
current status is the API is low-level, you pass in the values that are directly configured in the hardware. The datasheet explains the meaning of those values.
I agree it's not the most intuitive thing, if someone wants to work on adding a higher-level API where you set the frequency and duty cycle and it does the calculations for you, a pull request would be welcome.
Thanks for the quick confirmation 🙏
from embassy.
@mattiekat @crabdancing have a peek at #2855 -- it's a start anyway..
from embassy.
Related Issues (20)
- Unable to build CAN example for STM32F103 HOT 5
- Revise the I2S driver interface.
- HID mouse/keyboard tiny text change HOT 1
- Release gpio Pins back to Peripharals HOT 2
- When enabling DNS feature for rp pico W network stack never finish setup HOT 2
- [Feature] STM32 HAL required for `EXTI13` to implement `Into<embassy_stm32::exti::AnyChannel>` HOT 2
- Any plan to support STM32MP1?
- Bug(embassy_stm32): SPI Clock stuck at start and end of transaction for STM32F439ZIT6U HOT 1
- can't create Blocking I2C on STM32 HOT 2
- Re-add stm32 flash otp support?
- [STM32] `uid::uid_hex()` always the same HOT 1
- stm32h7: RNG locks up HOT 4
- stm32f401 Hardfault in i2cv1 write_frame (only with SPI enabled) HOT 1
- STM32H7 Sdmmc not functional
- Signal and !Send types? HOT 1
- `defmt` serial example? HOT 1
- STM32F373 does not have methods for using ADC
- LNK2019: unresolved external symbol HOT 1
- embassy-net does not have feature 'raw'. HOT 2
- Large arena causes memory errors and strange behaviour?
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 embassy.