Pages: 1 [2]   Go Down
Author Topic: Interrupt Missing Pulses  (Read 1004 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12579
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would assume this would be the same issue everyone has who uses a wheel encoder and needs an accurate count for navigation.  Anybody have a solution?

It's the same issue that anyone has who needs to have cooperation between an interrupt service routine and the main loop. Sometimes you can design the interface in such a way that both pieces of code can execute without any synchronisation, but the more general approach is to disable interrupts briefly while accessing the volatile shared data from the main loop.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

0
Offline Offline
Shannon Member
****
Karma: 201
Posts: 11744
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Where's the datasheet for the encoder?  Does yours need schmitt-trigger inputs to clean up the signal?
Logged

[ I won't respond to messages, use the forum please ]

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

SurferTim,

You were right.  I removed the reset and it counted every change.  It must just be a timing issue.
Changing pulse_count from Int to Byte in the original code showed no improvement. 
I changed the code to only reset pulse_count after every 10 counts and now there are no timing issues.  It still counts two or three pulses for a single pulse sometimes but a couple of caps should clear that.
Thanks everyone for the help.
Logged

Pages: 1 [2]   Go Up
Jump to: