Comments (2)
Which chip/hal are you using? You can configure the system tick rate setting a feature on the embassy-time-driver crate: https://docs.embassy.dev/embassy-time-driver/git/default/index.html#feature-flags
If you want to use a timer directly (i.e. you want a higher/lower freq timer compared to the system one), you can usually do that, but that depends on the HAL you are using. Example for stm32: https://docs.embassy.dev/embassy-stm32/git/stm32c011d6/timer/low_level/struct.Timer.html
from embassy.
I am using a STM32F427VI chip/hal. I currently have the tick rate configured to 1MHz. However, I did notice I had a println!() call within the task. This did slow it down quite a bit.
I modified the task and now my code looks like this. I am still only seeing about a 63.299us accuracy on a 5us toggle.
#[interrupt]
unsafe fn TIM6_DAC() {
EXECUTOR_HIGH.on_interrupt();
}
#[embassy_executor::task]
async fn blinker(mut led: Output<'static, AnyPin>) {
println!("blinker launched");
loop {
if led.is_set_high() {
led.set_low();
} else {
led.set_high();
}
Timer::after_micros(5).await;
}
}
#[embassy_executor::main]
async fn main(spawner: Spawner) {
defmt::debug!("debug");
// Special eth config
let mut config = Config::default();
{
use embassy_stm32::rcc::*;
config.rcc.hse = Some(Hse {
freq: Hertz(8_000_000),
mode: HseMode::Oscillator,
});
config.rcc.pll_src = PllSource::HSE;
config.rcc.pll = Some(Pll {
prediv: PllPreDiv::DIV4,
mul: PllMul::MUL168,
divp: Some(PllPDiv::DIV2), // 8mhz / 4 * 180 / 2 = 180Mhz.
divq: Some(PllQDiv::DIV4),
divr: None,
});
config.rcc.ahb_pre = AHBPrescaler::DIV1;
config.rcc.apb1_pre = APBPrescaler::DIV4;
config.rcc.apb2_pre = APBPrescaler::DIV2;
config.rcc.sys = Sysclk::PLL1_P;
}
let p = embassy_stm32::init(config);
// Driving a GPIO with a high priority timer
let led = Output::new(p.PE15, Level::Low, Speed::VeryHigh);
interrupt::TIM6_DAC.set_priority(Priority::P6);
let timer_spawner = EXECUTOR_HIGH.start(interrupt::TIM6_DAC);
unwrap!(timer_spawner.spawn(blinker(led.degrade())));
loop {
Timer::after(Duration::from_secs(1)).await;
}
}
I could be going about this incorrectly though. I want to have a highly accurate timer (1us) running and controllable with start/stop routines. Should I use a low-level? I tried the following code, but the IRQ does not fire.
#[interrupt]
unsafe fn TIM6_DAC() {
if led.is_set_high() {
led.set_low();
} else {
led.set_high();
}
}
let mut timer = p.TIM6;
interrupt::TIM6_DAC.set_priority(Priority::P6);
unsafe { interrupt::TIM6_DAC.enable() };
timer.set_frequency(Hertz(1));
timer.set_autoreload_preload(true);
timer.enable_update_interrupt(true);
timer.start();
Any additional guidance would be appreciated.
Thank you,
from embassy.
Related Issues (20)
- [embassy-stm32] allow splitting flash into banks not just regions HOT 2
- Weird issue with `Timer::after_secs(99999999999999999).await;` HOT 5
- STM32H7 recover from SAI `OverrunError` HOT 2
- gpiote_port example fails HOT 2
- Not able to get ip address with esp32-s3 and embassy-net-wiznet HOT 1
- [stm32] ADC (v1) channel selection wrong HOT 1
- Cellular/4G network? HOT 2
- STM32G0: USB Clock select enum USBSEL is wrong HOT 2
- Embassy depends on fixed which requires rust 1.79 which is newer than 1.75 set in rust-toolchain.toml HOT 1
- RISC-V Support
- rp: wifi_tcp_server: fails with `dns` feature of `embassy-net` HOT 2
- rp: wifi_tcp_server: fails after the recent `bluetooth` feature for `cyw43` HOT 5
- RP235x support HOT 10
- stm32f750v8 led blink gives FLAH Overfow error HOT 2
- Question - STM32G4 Dual bank vs embassy-boot HOT 2
- TM1637 display protocol - desired for Embassy HOT 2
- Different RecvError::Finished behavior for embassy-net tcp recv() vs recv_with()
- [embassy-rp] I2C transaction sends SR between operations of equal type HOT 1
- STM32 Dual Core Init - Private Peripheral Bus considerations
- examples/rp fails to build; missing in ci-nightly script. HOT 3
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.