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.

Timer 0 trouble (PIC16F628)

Status
Not open for further replies.

khansaab21

Advanced Member level 4
Joined
Apr 12, 2008
Messages
108
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,298
Activity points
2,214
Hello guys. A simple routine to utilize interrupt of timer 0 every 444 uSec isnt working. Following is the code. Could anyone plz help with trouble shooting it as after hours of wasting time on it I couldnt find fault.

Crystal = 4.194304 Mhz

void interrupt()
{
INTCON.T0IF = 0;
TMR0 = 227;
PORTA.F0 = ~PORTA.F0;
}

void main()
{
TRISA.F0 = 0; // Port A is output
TMR0 = 227;
INTCON = 0xA0;
OPTION_REG = 0x03; //Using prescaler of 16
for(;;);
}
 

You still need to configure the global and device interrupts. Something like:

//***INTERRUPT ENABLING ***//
RCIE = 1; //Enable interrupt
PEIE = 1; //Enable device interrupt
GIE = 1; //Enable Global interrupt

//***Timer 1 initialization***// //To wait around 60 mSec before checking for the motor protection circuit
TMR1CS = 0; //Internal clock used for the timer FOSC/4
TMR1IE = 1; //Timer 1 Interrupt enabled

Also you need to start the timer:

TMR1L = 0xA0; //Init value for Counter
TMR1H = 0xEC; //Init value for Counter
TMR1ON = 1; //Start timer
 

As a matter of fact sir, i have enabled the interrupts and have to use timer 0 only because using a prescaler of 16 would give me the minimum timing error in the subsequent task upon the interruption.

Can somebody plz post a working C code of using timer 0 of pic 16f628 using a prescaler.
 

i hope you are checking the working of interrupt with Bit Toggling PORTA pin
Code:
PORTA.F0 = ~PORTA.F0;

~ is for byte toggling... for bit toggling use !

Code:
PORTA.F0 = ! PORTA.F0;

please reply whether this solved ur problem...

__
click helped button if this solves ur problem
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top