• Forums
• Posts
Latest Posts
Active Posts
Recently Visited
Search Results
• Page Extras
• Forum Themes
• AVR Freaks

### Hot!Counting required pulses

Author
Djsarkar
Super Member
• Total Posts : 210
• Reward points : 0
• Joined: 2020/07/27 01:14:06
• Location: 0
• Status: offline
1 (1)

# Counting required pulses

Suppose a hypothetical situation in which 8 bit counter starts at 0 and ends at 255 .Counter takes 1 microsecond time to count one pulses So 5 milliseconds will require 360 ​​pulses

But counter can only count 255 pulses, how does counter count 360 pulses in micro?

Jim Nickerson
User 452
• Total Posts : 6847
• Reward points : 0
• Joined: 2003/11/07 12:35:10
• Location: San Diego, CA
• Status: offline
Re: Counting required pulses 2020/08/03 09:23:09 (permalink)
+2 (2)
Homework ? Smile:
davea
Super Member
• Total Posts : 589
• Reward points : 0
• Joined: 2016/01/28 13:12:13
• Location: Tampa Bay FL USA
• Status: offline
Re: Counting required pulses 2020/08/03 10:15:09 (permalink)
+1 (1)
So 5 milliseconds will require 360 ​​pulses, NO 5,000
mpgmike
Super Member
• Total Posts : 515
• Reward points : 0
• Joined: 2014/01/23 17:27:06
• Location: NJ
• Status: offline
Re: Counting required pulses 2020/08/03 10:39:00 (permalink)
+3 (3)
You will need a variable that tracks each time your 8-bit Timer rolls over.  The Timer should trigger an interrupt.  In your ISR you increment your variable.  Just to give you some direction...

I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
Djsarkar
Super Member
• Total Posts : 210
• Reward points : 0
• Joined: 2020/07/27 01:14:06
• Location: 0
• Status: offline
Re: Counting required pulses 2020/08/03 20:54:36 (permalink)
0
No, it's not homework. If it was homework, I wouldn't take the wrong calculation. I am sorry My calculations are wrong.

If we only have to count 356 pulse, then how does the counter count pulses because 8 bit counter will start at 0 and end at 255 and again it will run from 0 to 255. will it count remaining 101 pulses in second round and then it will stop. How does the counter know that he has to count only 101 seconds in the second round?
ric
Super Member
• Total Posts : 29488
• Reward points : 0
• Joined: 2003/11/07 12:41:26
• Location: Australia, Melbourne
• Status: online
Re: Counting required pulses 2020/08/03 21:09:58 (permalink)
+1 (1)
Do you want a hardware interrupt when the count expires?
The only way to do it with an 8 bit counter is to start the count at a non zero value, so it will reach 360 one of the times that the counter rolls back to zero again.
In your case, if you load the counter with 104 (360 - 256), then it will roll over once after 152 counts, then again at 360 counts.
It's your job to count roll overs (using the interrupt service), so on the second interrupt you know you have received 360 counts.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
Djsarkar
Super Member
• Total Posts : 210
• Reward points : 0
• Joined: 2020/07/27 01:14:06
• Location: 0
• Status: offline
Re: Counting required pulses 2020/08/03 21:17:49 (permalink)
0
I don't understand your calculations. Lets assuming counter take one microseconds time to count one pulse so it would take 360 microsecond to count 360 pulses. In first pass counter will count from 0 to 255 then in second pass it will count 101 then interrupt will generate.

What value we need to store in counter register to count 360 pulses? How does counter count 360 pulses?
ric
Super Member
• Total Posts : 29488
• Reward points : 0
• Joined: 2003/11/07 12:41:26
• Location: Australia, Melbourne
• Status: online
Re: Counting required pulses 2020/08/03 21:28:04 (permalink)
+1 (1)

In first pass counter will count from 0 to 255

I just explained that you can't do that. If you want something to happen at 360, you have to start at 104.
Then there will be two "rollover events". One after 152 counts, and another at 360 counts.
It's your job as a programmer to wait for the second one.

In your words, the first pass will count from 104 to 255, and back to zero, which is 152 counts.
post edited by ric - 2020/08/03 21:30:56

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
Djsarkar
Super Member
• Total Posts : 210
• Reward points : 0
• Joined: 2020/07/27 01:14:06
• Location: 0
• Status: offline
Re: Counting required pulses 2020/08/03 21:41:57 (permalink)
0
This is what is confusing me. what happens when we have to count 800 pulses so 800-256 = 554 Counter cannot count so 554 pulses at a time, so counter has to be run twice.
ric
Super Member
• Total Posts : 29488
• Reward points : 0
• Joined: 2003/11/07 12:41:26
• Location: Australia, Melbourne
• Status: online
Re: Counting required pulses 2020/08/03 21:47:14 (permalink)
+1 (1)
Take the value modulo 256
800 mod 256 is 32, so 800 = (3 x 256) + 32
so you start counting at 256-32 = 224, and count four rollovers (one partial, and three full).

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!