asking
Full Member level 5
- Joined
- Sep 21, 2010
- Messages
- 279
- Helped
- 6
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 1,298
- Activity points
- 3,377
Hello,
I have 12F683 @ 8MHZ (internal), and i want to have Soft PWM using interrupt. TMR0
I m using PIC Calculator
Here's my code, Please help... when i connect on PIN GP2 it shows 7.14KHZ Signal on Oscilloscope....it should show 38.4KHZ....please help...i tried...but not getting it..
I have 12F683 @ 8MHZ (internal), and i want to have Soft PWM using interrupt. TMR0
I m using PIC Calculator
Here's my code, Please help... when i connect on PIN GP2 it shows 7.14KHZ Signal on Oscilloscope....it should show 38.4KHZ....please help...i tried...but not getting it..
Code:
void interrupt()
{
// Timer0 Interrupt - Freq = 38461.54 Hz - Period = 0.000026 seconds
if (INTCON.TMR0IF ==1) // timer 0 interrupt flag
{
GPIO.F2 = ~GPIO.F2; // Toggle PORTB bit0 LED
INTCON.TMR0IF = 0; // clear the flag
INTCON.TMR0IE = 1; // reenable the interrupt
TMR0 = 204; // reset the timer preset count
}
}
// code starts here...
void main()
{
ANSEL = 0;
// setup portb to show the interrupts by blibking LEDs
TRISIO = 0; // PORT is all output...to show the interrupts
GPIO.F2 = 0; // start with all outputs low
//Timer0 Registers Prescaler= 1 - TMR0 Preset = 204 - Freq = 38461.54 Hz - Period = 0.000026 seconds
OPTION_REG.T0CS = 0; // bit 5 TMR0 Clock Source Select bit...0 = Internal Clock (CLKO) 1 = Transition on T0CKI pin
OPTION_REG.T0SE = 0; // bit 4 TMR0 Source Edge Select bit 0 = low/high 1 = high/low
OPTION_REG.PSA = 1; // bit 3 Prescaler Assignment bit...0 = Prescaler is assigned to the WDT
OPTION_REG.PS2 = 0; // bits 2-0 PS2:PS0: Prescaler Rate Select bits
OPTION_REG.PS1 = 0;
OPTION_REG.PS0 = 0;
TMR0 = 204; // preset for timer register
// Interrupt Registers
INTCON = 0; // clear the interrpt control register
INTCON.TMR0IE = 1; // bit5 TMR0 Overflow Interrupt Enable bit...1 = Enables the TMR0 interrupt
INTCON.TMR0IF = 0; // bit2 clear timer 0 interrupt flag
INTCON.GIE = 1; // bit7 global interrupt enable
while(1) //endless loop
{
}
}