Page 1 of 1

Timer Interrupt

Posted: Tue Jul 09, 2024 11:32 am
by jollybv
Hi Guys

If I'm using timer interrupt 4 on a PIC18F46K80 which is set to 125 Hz how do i work out how many times it will need to call the macro to give me a 1 second pulse? I worked out about 8000 but when i tried it and tried to count to 30 minutes (1800 seconds) it was not very accurate. Any help will be much appreciated

Re: Timer Interrupt

Posted: Tue Jul 09, 2024 12:15 pm
by Steve-Matrix
An interrupt at 125 Hz means it is being called 125 times each second. If you use a global variable initially set to zero and incremented each time within your interrupt routine, then when it reaches 125 then that should be 1 second.

Remember to keep your interrupt routine as short as possible. For example, only increment the variable within the interrupt routine itself. Then, in a convenient place in your program's main loop (i.e. somewhere that is frequently executed), you can check this variable and if it has reached 125 then you know 1 second has elapsed. As this point, reset it back to zero and process anything that should happen when this time has elapsed.

Re: Timer Interrupt

Posted: Tue Jul 09, 2024 12:21 pm
by jollybv
Hi Steve

Thanks for that let me give it a try