Using Interrup for timing

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
dariods
Posts: 21
Joined: 26 Apr 2023 07:12

Using Interrup for timing

#1 Post by dariods » 26 Apr 2023 07:38

I am trying to build an amphour meter using PIC16F877A for which i need to read the adc once every second, not delay of 1 second. the best way i found is to use interupt to acheive this. But i am unable to understand how to do this. Can someone please explain with a simple adc read code that reads every second, the complete loop takes 1 second to execute. Is there a wait function where the code can halt till a counter equals a value?

hexreader
Posts: 1785
Joined: 27 Jun 2010 12:07
Location: England

Re: Using Interrup for timing

#2 Post by hexreader » 27 Apr 2023 08:53

You can use timer calculator to help you set up timer interrupts

https://www.mikroe.com/timer-calculator

1 second is not possible, so use 10 millisecond interrupt, count 100 interrupts and set a flag

My attempt at a solution is attached. It assumes 8 MHz 2-pin crystal used

Welcome to the forum
Attachments
forum.zip
(30.65 KiB) Downloaded 25 times
Start every day with a smile...... (get it over with) :)

dariods
Posts: 21
Joined: 26 Apr 2023 07:12

Re: Using Interrup for timing

#3 Post by dariods » 29 Apr 2023 18:21

Thanks, this is exactly what I was looking for. How to confirm the timing using the debugging method?

dariods
Posts: 21
Joined: 26 Apr 2023 07:12

Re: Using Interrup for timing

#4 Post by dariods » 30 Apr 2023 18:18

Thanks for the solution, its working perfectly as I needed. I couldn't perform simulation in the software simulator but tried it in proteus. Thanks once again.

Post Reply

Return to “mikroC PRO for PIC General”