Programming timer0 for interrupts

7 posts / 0 new
Last post
Rony
Offline
Last seen:4 years 10 months ago
Master
加入:2014-05-15 15:02
Programming timer0 for interrupts

Sorry for the silly question but which parameters to use when calling timer0_set(on, high, low) to
get an interrupt every 0.5ms (2khz)?
Same question for 0.1ms (10khz).
Thanks

JE_Dialog
Offline
Last seen:2 weeks 5 days ago
Staff
加入:2013-12-05 14:02
Hello Rony,

Hello Rony,

我将送你一个example that can help here. It is based on a sounder which users timer0 to set the PWM frequecny..

In the example Timer0_set(on, high, low) does the following:

  • High and low is used to decide the frequency of the sounder . 50% d/c when high/low are equal.
  • ON value decides how long the tone will be generated before interrupt is generated.

BR JE_Dialog

Rony
Offline
Last seen:4 years 10 months ago
Master
加入:2014-05-15 15:02
Thanks

Thanks

yassin.bennaceur
Offline
Last seen:5 years 8 months ago
加入:2015-04-10 15:32
Could you send me the same

Could you send me the same example .. I am looking for the same thing with 10Khz as well.

Ruchi Patel
Offline
Last seen:2 years 5 months ago
加入:2017-03-29 10:50
Could you send me that same

Could you send me that same example?? .. I am also looking for the same thing with 10Khz.

MT_dialog
Offline
Last seen:1 month 3 weeks ago
Staff
加入:2015-06-08 11:34
Hi Ruchi Patel,

Hi Ruchi Patel,

You can have a look at the peripheral examples\timer0\timer0_general and change the value timer0_set_pwm_on() from 20000 which is the RELOAD_100MS to just 20, this will set a reload value in your timer and your configuration should be T = 1/200kHz * 20 = 10kHz interrupt. You can also have different options to configure the interrupt frequency that you would like for example, use a different clock divider CLK_PER_REG_TMR_DIV_8 to a smaller division in order to feed the timer and dont use TIM0_CLK_DIV_BY_10 and use larger reload values.

Thanks MT_dialog

Ruchi Patel
Offline
Last seen:2 years 5 months ago
加入:2017-03-29 10:50
Hey MT_Dialog,

Hey MT_Dialog,

Thank you for the reply. I have made changes as you have mentioned in your comment and it is working fine. But i have to use TIM0_CLK_DIV_BY_10 to make 10KHz frequency. Thank you so much.

Regards,
Ruchi