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

Future for Timer Update Interrupt #3108

Open
shufps opened this issue Jun 22, 2024 · 5 comments
Open

Future for Timer Update Interrupt #3108

shufps opened this issue Jun 22, 2024 · 5 comments

Comments

@shufps
Copy link
Contributor

shufps commented Jun 22, 2024

Hi,

I'm trying to get a DDS to work but currently there seems not to be a way to have a future waiting for the timer update interrupt or timer compare interrupt

Unfortunately this is needed because DDS is completly different to waveforms that are played back from RAM via DMA.

It requires to calculate the next PWM value based on a fixed point phase accumulator pointing to a sine table but this requires to update the PWM value after each timer update interrupt - better would be timer compare interrupt.

I saw in the low_level.rs that there is some function that can return if a timer interrupt happened but it would be a "bruteforce"-polling method that wastes a lot of CPU power. Better would be a Future that awaits in some task.

I can contribute some DDS code example if someone could point me in the right direction.

Thank you very much,
Thomas

@shufps
Copy link
Contributor Author

shufps commented Jun 22, 2024

Mmhmm maybe I can C&P parts from the Input Capture Interrupt 🤔

@shufps shufps changed the title Future for Timer Update Interrupt missing Future for Timer Update Interrupt Jun 22, 2024
@shufps
Copy link
Contributor Author

shufps commented Jun 23, 2024

I think this should work with minimum overhead:

#[interrupt]
fn TIM2() {
    unsafe {
        // get next value of DDS
        DDS_AKKU = DDS_AKKU.wrapping_add(DDS_INCR);
        let value = DDS_SINE_DATA[(DDS_AKKU >> 24) as usize];
        pac::TIM2.ccr(3).modify(|w| w.set_ccr(value as u16));
    }
}

@shufps
Copy link
Contributor Author

shufps commented Jun 28, 2024

#3127

@romainreignier
Copy link
Contributor

romainreignier commented Jun 29, 2024

I don't know what do you mean by DDS but this PR might interest you for the futures: #3029

@shufps
Copy link
Contributor Author

shufps commented Jun 30, 2024

I don't know what do you mean by DDS

DDS means "direct digital synthesis" - it's like the opposite of digitizing an analog audio into digital samles.

DDS creates digital samples of a sine wave that is then converted to analog external.

The trick on DDS is that you can generate arbitrary sine frequencies (actually doesn't need to be sine, can be any periodic waveform) - like you can digitize arbitrary sine wave frequencies (ofc with respect to Nyquist) of an analogue signal.

It's a little bit of an edge case, not so much used, but it's needed for digital signal processing often.

Oh nice to see that I'm not the only one who would need Futures for Timers 🙌

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

No branches or pull requests

2 participants