Timer handling discussion
Hi all,
I'need to produce a 4KHz square wave to drive a buzzer.I have HZ set to 100; so the kernel timer expires each 10ms.
If I use the following scheme:
....
init_timer(&timer); timer.data = (unsigned long) 0; timer.function = buzzer_timer;
....
....
mod_timer(&timer, jiffies);
...
...
static void buzzer_timer(unsigned long handle)
{
// spin_lock_irq(&lock);
if (beepEnabled) {
if (buzzerToggle) {
ctrl_outw(ctrl_inw(PCDRL) & ~0x0800 ,PCDRL );
buzzerToggle = 0;
}
else {
ctrl_outw(ctrl_inw(PCDRL) | 0x0800 ,PCDRL );
buzzerToggle = 1;
}
mod_timer(&timer, jiffies + BUZZER_TIME);
}
else {
}// spin_unlock_irq(&lock);
}
I get a 50Hz square wave.
What could be the best way to use the same scheme but with a timer at 5kHz for example.
Thanks a lot
Signature · 7 lines
Fabio Giovagnini Aurion s.r.l. P.I e C.F. 00885711200 Tel. +39.051.594.78.24 Cell. +39.335.83.50.919
Hi Fabio,
Quoted 3 lines · Fabio Giovagnini
Hi all,
I'need to produce a 4KHz square wave to drive a buzzer.I have HZ set to 100; so the kernel timer expires each 10ms.
You may want to use hrtimers. One example how to use that is in the following file:
sound/sh/sh_dac_audio.c
/ magnus
Thanks Magnus. I'm solviing handling a timer directly into the buzzer /proc driver
Thanks
In data sabato 01 maggio 2010 14:11:29, Magnus Damm ha scritto:
: > Hi Fabio,
Quoted 15 lines
On Sat, May 1, 2010 at 4:01 PM, Fabio Giovagnini
Quoted 3 lines · <[email protected]> wrote:
Hi all,
I'need to produce a 4KHz square wave to drive a buzzer.I have HZ set to 100; so the kernel timer expires each 10ms.You may want to use hrtimers. One example how to use that is in the following file:
sound/sh/sh_dac_audio.c/ magnus
Signature · 7 lines
Fabio Giovagnini Aurion s.r.l. P.I e C.F. 00885711200 Tel. +39.051.594.78.24 Cell. +39.335.83.50.919