Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Timer 0 trouble

Status
Not open for further replies.

khansaab

New Member
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(;;);
}
 
There are so many things wrong with your method.
1. you are just writing to TMR0, not adding or subtract so you get a latency error
2. writing to TMR0 causes a 2 inst latency as well
3. you cant use a prescaler on TMR0 if you are going to write to it

I just put some code up on the forum that will do what you need, see this page;
https://www.electro-tech-online.com/threads/zezj-zero-error-zero-jitter-period-algorithm.100299/

I think all you need to do is put the value 444 in PERIOD at the top of the code to make a interrupt of 444 TMR0 ticks, if you want 444 actual uS you need to use a corrected value 444 * 4194304/4000000 = 465.
 
Status
Not open for further replies.

Latest threads

Back
Top