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 interupt and tmr0

Status
Not open for further replies.

mazahir

New Member
hi all
i am designing a digital clock with an alarm using PIC16F870 and a dallas 1307 RTC chip

i have divided the project in parts, got the first part working which is getting an output on my seven segment .
now i have to to multiplex 4 seven segments and want to send the digits out to the 4 displays using an interupt which is caused by tmr0.

but i have trouble setting up the timer 0......i want it to interupt every 4ms
i worked out the with the formula i founf in predko's book
tmro has to be set at 131 with a prescalar of 1:32

is that correct

now for my problem could some one help me out with how to properly set tmr0 and how to use interuppts..

any help would be appreaciated
thanx
 
TMR0 will cause an interrupt when it steps from 255 to 0.

I'm not familiar with the PIC you are using, but in the 16F84, you have to set the TMR0 interrupt enable (bit 5) in the INTCON register.

The Interrupt Sub Routine (isr) needs to start at 0x04.

You must clear the TMR0 interrupt flag (INTCON bit 2) in the isr.

To count 131, you will have to set TRM0 at 256 - 131 (or it may be 255 - 131) so that it needs 131 counts to reach 0 and thus cause the interrupt.

However, there are other ways to do this. If the PIC does not have other functions to do while timer is running, then it can be done (without interrupts) by counting. See Nigel's tutorials for timers.

Len
 
I'm facing the same problem of choosing which timer to use on the 16F877 with 20MHz crystal.

I need to interrupt the PIC every few milliseconds to refresh the LED display and using the INT to work also as a realtime clock. I thought the task was easy because I have three timers on 16F877.

But in real life you have some consideration to make on which timer to use.

The easy way out is to use Timer1 with special event trigger but then you are not able to use timer1 to measure anything external.

Or you can use Timer2 but then you lose the ability to use PWM.

Or if you use Timer0, any pre-loading of timer counts would prevent counting for a few instructions. If one let it overflow naturally as a realtime clock but then one get INT timing count with decimal like 1.6384ms.

I search the Web in hope of someone who have done these considerations and had compiled them into an article or webpage but I found none.

Any suggestions?
 
eblc1388 said:
I'm facing the same problem of choosing which timer to use on the 16F877 with 20MHz crystal.

I need to interrupt the PIC every few milliseconds to refresh the LED display and using the INT to work also as a realtime clock. I thought the task was easy because I have three timers on 16F877.

But in real life you have some consideration to make on which timer to use.

The easy way out is to use Timer1 with special event trigger but then you are not able to use timer1 to measure anything external.

Or you can use Timer2 but then you lose the ability to use PWM.

Or if you use Timer0, any pre-loading of timer counts would prevent counting for a few instructions. If one let it overflow naturally as a realtime clock but then one get INT timing count with decimal like 1.6384ms.

I search the Web in hope of someone who have done these considerations and had compiled them into an article or webpage but I found none.

Any suggestions?

There are many ways to crack this nut (well about 3). All 3 timers can be used for this. If you need all three timers for other functions then you need a more powerful processor. As you say, timer 1 with the special event trigger is the easiest to implement and timer 0 the hardest. I have implemented a real time clock using timer 0 with a 20 (and 4) meg clock which was as accurate as the Crystal (capacitive tuning would make it very accurate). It only works if you have no other interrupts but does work.

Let me know if you want to know more.

Mike.
 
Pommie said:
Let me know if you want to know more.
Mike.

Thanks Mike. I have chosen to use Timer0 to give an INT period of 1.6384ms (Timer0 runs continously, no preloading) with a 20MHz crystal. I have figured out a way to count this period into value for my real time clock.

Let me try my coding first and if the clock loses accuracy then I would certainly seek your help. The fun part is all in the doing, even if it does not work.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top