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.

Help with timer and interrupt please..

Status
Not open for further replies.

AntRoFiZ

New Member
Hi..
I need some help with interrupt and timer using PIC16F877A using C language..

Well.. I have been googleing for weeks but i still don't know how to use interrupt and timer.. I have also been to Nigel's site (http://www.winpicprog.co.uk) but i don't know assembly.. I have also tried reading the datasheet but my knowledge of PIC is far too little to understand what was said there..

So, hope to be forgiven for knowing too little about PIC.. Also hope that somebody would be kind enough to help me with interrupt and timer..

Timer
What I plan to do is to time a pulse. I understand that in order to time a pulse, I need to start the timer counting when I receive a pulse (change from low to high). Then I have to stop the timer when the pulse change from high to low. After that I need to read the time of the timer.

But the problem I am facing is I don't know how to use the timer, I don't know which timer to use.. I am so confused with so many timers etec timer0, timer1 etc.. I also don't know how to setup the PIC to use timer.. So, can somebody please help me with timer.



Interrupt
Lets say I am sending a 5 bit code to PIC16F877A. When the PIC receive the code, it doesn't matter what it is doing at the moment, I want it to stop doing whatever it is doing and go to a certain part of the code which contains a bunch of "if statements" and process according to the 5 bit code.. The only thing I know about interrupt is that it uses RA4/T0CKI/C1OUT pin. I may be wrong..
If only one pin can be used to trigger the interrupt, then how can i do it in such a way that the interupt of the PIC will be triggered by the 5 bit code received.

An example of the application of interrupt would be:

The PIC receive a 5 bit code 00001 (pin4 = 0, pin3 = 0, pin2 = 0, pin1 = 0, pin0 = 1 of any port) . It will then stop whatever it is doing and go to an if statement. Example of an if statement can be "if (portb == 0b00001)" and the action if the if statement is true can be to set pin 5 high.


Thanks..
 
I fear that you have more problems then a single post or reply can easily solve. For the timers I suggest you do them all, and find out which one works best for your application.

The interrupt on 5-bit code problem is only slightly more difficult, and I see two potential solutions.
  1. Use the Interrupt on Change feature
  2. Use a sixth signal called "STROBE" that indicates the arrival of a valid code.
 
AntRoFiZ said:
Hi..
I need some help with interrupt and timer using PIC16F877A using C language..

So, hope to be forgiven for knowing too little about PIC.. Also hope that somebody would be kind enough to help me with interrupt and timer..

Timer
What I plan to do is to time a pulse. I understand that in order to time a pulse, I need to start the timer counting when I receive a pulse (change from low to high). Then I have to stop the timer when the pulse change from high to low. After that I need to read the time of the timer.

But the problem I am facing is I don't know how to use the timer, I don't know which timer to use.. I am so confused with so many timers etec timer0, timer1 etc.. I also don't know how to setup the PIC to use timer.. So, can somebody please help me with timer.

Have a look at TIMER1 on the datasheet, 2*8 bit with prescaler


Interrupt
Lets say I am sending a 5 bit code to PIC16F877A. When the PIC receive the code, it doesn't matter what it is doing at the moment, I want it to stop doing whatever it is doing and go to a certain part of the code which contains a bunch of "if statements" and process according to the 5 bit code.. The only thing I know about interrupt is that it uses RA4/T0CKI/C1OUT pin. I may be wrong..
If only one pin can be used to trigger the interrupt, then how can i do it in such a way that the interupt of the PIC will be triggered by the 5 bit code received.

Have a look at PORTB, 'change on interrupt' feature for your 5 bit input.

An example of the application of interrupt would be:

The PIC receive a 5 bit code 00001 (pin4 = 0, pin3 = 0, pin2 = 0, pin1 = 0, pin0 = 1 of any port) . It will then stop whatever it is doing and go to an if statement. Example of an if statement can be "if (portb == 0b00001)" and the action if the if statement is true can be to set pin 5 high.

Your interrupt subr would do this task for you, if you program to do so, when you raise an interrupt on PORTB
Thanks..

I do not program in C so I cannot give examples.
 
Status
Not open for further replies.

Latest threads

Back
Top