xyzabcpqr
Junior Member level 3
Hello,
I am currently working on PIC18f13k50 - USB interfacing with PC through USB HID application.
(12MHz crystal *4 PLL ) Fosc = 48MHz . I want to run buzzer @ 2 KHz . I used PWM module .
But as per calculation, I can get the lowest 2.93 KHz Freq.
I am using timer2 for PWM with 16 prescaler(max. value).
period = (255+1)*4*(1/48000000)*16(prescaler)
= 340 micro-sec
f= 2.93 KHz
How can I reduce the freq to 2KHz?
I tried to use Timer 1 and following is the code but using timer1 i can't get sound from buzzer.
#pragma interrupt YourLowPriorityISRCode
void YourLowPriorityISRCode()
{
T1CONbits.TMR1ON = 1;
TMR1H = 0xE2;
TMR1L = 0xB3;
while(!PIR1bits.TMR1IF){
SPEAKER = 1;
Delay1();
SPEAKER = 0;
}
PIR1bits.TMR1IF=0;
}
Can anyone give me a guidance?
I am currently working on PIC18f13k50 - USB interfacing with PC through USB HID application.
(12MHz crystal *4 PLL ) Fosc = 48MHz . I want to run buzzer @ 2 KHz . I used PWM module .
But as per calculation, I can get the lowest 2.93 KHz Freq.
I am using timer2 for PWM with 16 prescaler(max. value).
period = (255+1)*4*(1/48000000)*16(prescaler)
= 340 micro-sec
f= 2.93 KHz
How can I reduce the freq to 2KHz?
I tried to use Timer 1 and following is the code but using timer1 i can't get sound from buzzer.
#pragma interrupt YourLowPriorityISRCode
void YourLowPriorityISRCode()
{
T1CONbits.TMR1ON = 1;
TMR1H = 0xE2;
TMR1L = 0xB3;
while(!PIR1bits.TMR1IF){
SPEAKER = 1;
Delay1();
SPEAKER = 0;
}
PIR1bits.TMR1IF=0;
}
Can anyone give me a guidance?