Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC18F - how to get 2khz from 48MHz Freq using timer/ pwm

Status
Not open for further replies.

xyzabcpqr

Junior Member level 3
Joined
Mar 22, 2012
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,523
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?
 

this is a nice program to do that :
**broken link removed**
**broken link removed**

which gives the C program :
Code:
// Timer1 Registers:
// Prescaler=1:1; TMR1 Preset=41536; Freq=2,00kHz; Period=500*000 ns
T1CON.T1CKPS1 = 0;// bits 5-4  Prescaler Rate Select bits
T1CON.T1CKPS0 = 0;//
T1CON.T1OSCEN = 1;// bit 3 Timer1 Oscillator Enable Control: bit 1=on
T1CON.T1SYNC  = 1;// bit 2 Timer1 External Clock Input Synchronization Control bit: 1=Do not synchronize external clock input
T1CON.TMR1CS  = 1;// bit 1 Timer1 Clock Source Select bit: 0=Internal clock (FOSC/4) / 1 = External clock from pin T13CKI (on the rising edge)
T1CON.TMR1ON  = 1;// bit 0 enables timer
TMR1H = 0xA2;     // preset for timer1 MSB register
TMR1L = 0x40;     // preset for timer1 LSB register
 
Last edited:

Hello Kripton,

It is really helpful.. Thanks a ton..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top