Hello,
For a school project I need to measure the speed of a rotating mass to brake it afterwards.
I wanted to measure the speed of the rotation using the bike brake disc (16holes) I mounted on it. To do so, I mounted an optical sensor (Sharp GP1A57HRJ00F).
I am also using a clock through a generator to calculate every 100ms (so using a 10Hz square 0-+5V) the speed of the mass (That's what my teacher told me to do).
Here's the code :
The issue I'm having is that sometimes the speed jumps up for no reason (and so the time differential plummets) and I can't see why...
I verified that the other smaller holes didn't interfere with the sole hole I'm measuring from.
It doesn't seem to be correlated to the speed it's rotating (between 0 and 50 rounds per seconds).
It's my first time on the forum so I might be missing some crucial information for you to help me.
Sorry for the possible english mistakes, it is not my first languages.
Changing them to volatile seems to have helped (not as much weird values) !!
Some still remain so I'll see to limit the use of arithmetic in an interrupt..
Are you saying you're only sensing one single hole on the entire periphery of the disc? It appears there would be possibly a dozen other holes that could also be sensed.
No no as you can see from the first picture I sent there are blocs of 3 holes at different radius from the center / height. What I wanted to say is that I only took the one that was the furthest from the center (and all along the disc there are 16 in total, thus the division by 16 in the code)
Any pictures from the oscilloscope?
My reason for asking is You define the input as INPUT, not INPUT_PULLUP. Most opto outputs are open collector and then a pullup resistor is needed.
Thanks. That is an opto model DeLuxe having an internall pullup.
No problem reading that like You do.
I've used a lot more simple once in the past.
Be aware of glowing bulbs. They radiate some IR that can interfere. Sunshine is obvious....
Your print outs indicate a potential issue with this, as the T1 and T2 values give the correct dt value when subtracted with a calculator even though the printed value of dt is wrong.