Timer Interrupt

For general Flowcode discussion that does not belong in the other sections.
Post Reply
jollybv
Posts: 129
http://meble-kuchenne.info.pl
Joined: Mon Mar 08, 2021 11:25 am
Location: Cape Town South Africa
Has thanked: 40 times
Been thanked: 11 times

Timer Interrupt

Post 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
Last edited by jollybv on Tue Jul 09, 2024 12:18 pm, edited 1 time in total.

Steve-Matrix
Matrix Staff
Posts: 1345
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 181 times
Been thanked: 316 times

Re: Timer Interrupt

Post 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.

jollybv
Posts: 129
Joined: Mon Mar 08, 2021 11:25 am
Location: Cape Town South Africa
Has thanked: 40 times
Been thanked: 11 times

Re: Timer Interrupt

Post by jollybv »

Hi Steve

Thanks for that let me give it a try

Post Reply