[SOLVED] PIC complete discussion for all

Status
Not open for further replies.
the calcultor you have given is not working.. I mean the plugin is not working


I have this calculator but it seems it's not possible to generate directly a 250ms..

PIC Timer Calculator
 

Hi guys... sorry for causing you trouble here... :grin: hehe.. I will attend my class first then I will back here and I will surely post the answer of my problem..
 

thanks. .. I have that link and I will read that today.. time here now is 1pm and I'll be out in school at 5pm then I will read that.. I will not sleep if I cant produce a 1 sec delay... hihihi
 

Hi . just want to be sure..



fclk is clock frquency. right? it is not mentioned in the tut..
 

hi.. I understand now the internal clock how to generate a delay of 0.5sec but I need clarification on the external clock based on the tutorial..


In PIC16 and 18F families 1 instruction cycle = 4 crystal cycles

but why in the formula of external clock 4 crystal cycles in not used? I mean it is not use as part of the divisor.(see the formula below.)



Formula to calculate Cout using Timer0

In this case there is no division by 4 of the original clock. We use the external frequency as it is.
If using EXTERNAL clock source (oscillator), the division is performed as follow:



 
hi..

what's the problem with this code? I followed the instruction in many tutorial but why the timer0 interrupt is still not working?


I can generate 1 second delay using timer0 without using interrupt and it's working fine but when i use timer interrupt it's not working anymore..


PHP:
#include<pic.h>

__CONFIG(0x3F38); //for Internal oscillator

void interrupt timer0()
{
	char count;
	if(T0IF == 1) 
	{
	    T0IF = 0;  //reset flag
	    count++;  // increment counter
		if(count == 15) // set timer to count 15 aprox to 1 second delay.
		{
			RA2 ^= 1;   //toggle LED
			count = 0;  //reset counter
		}
	}
}


void main(void)
{

	TMR0 = 0;
	OPTION_REG = 0b0111;  // set prescaler to timer 0 and 1:256 prescaler..
	T0CS = 0;  // timer 0 Internal clock source
	T0IE = 1;  // enable timer 0 interrrupt
	GIE =1;    // Enable global interrupt 
	TRISA2 = 0; //set bit 1 of portB as output.

	while(1);

}
 

wahahahaha Im happy now!!! I got it !!!

I just read the lines from a book and found out my mistake!!! :-D

**broken link removed**

my mistake is I declared a variable inside the interrupt function... that single line cost me almost 2 days of finding out why interrupt is not working... hehehe.. I can proceed now to next topic... hehe

---------- Post added at 13:28 ---------- Previous post was at 13:21 ----------

where do you disable the interrupt before exiting the ISR routine??

I dont have that function yet.. though the program is working.. is it required? what is the effect if I dont have that?

anyway here is my working code now...

PHP:
#include<pic.h>

__CONFIG(0x3F38); //for Internal oscillator

char count;

void interrupt timer0()
{
	
    
	if(T0IF == 1)
	{
	    T0IF = 0;
//		PEIE = 0;
	    count++;
		if(count == 15)
		{
			RA2 ^= 1;  //toggle LED
			count = 0;
			
		}
	//	PEIE = 1;
	}
}


void main(void)
{

	TMR0 = 0;
	OPTION_REG = 0b0111;  // set prescaler to timer 0 and 1:256 prescaler..
	T0CS = 0;  // timer 0 Internal clock source
	T0IE = 1;  // enable timer 0 interrrupt
	GIE =1;    // Enable global interrupt 
	TRISA2 = 0; //set bit 1 of portB as output.

	while(1);

}


---------- Post added at 13:44 ---------- Previous post was at 13:28 ----------

Peie=1; ........

thanks vinodstanur,

the last code i have posted above is still working without disabling or enabling peripheral bit.. and if I add that it is still working..
any cons if i dont have that? what's the difference of having or without it?
 

its a good programming practice to use these bits and disable the interrupt routine before exiting... they are basic rules as they are of very much concern when your program runs on the real hardware and you wish to use more interrupts, then if interrupt is not disabled it will not allow other interrupts to execute due to its priority and other factors...

it works on simulator ,but real time application on real hardware, should also should be kept in mind.....
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…