Gate Timer
Brian_B
Posts: 842
Hi All,
I'm working on a dual gate timer and have it somewhat working. This code works except that I can't figure out how to get hundredths of seconds to display properly. Any thoughts would be much appreciated.
Thanks Brian
I'm working on a dual gate timer and have it somewhat working. This code works except that I can't figure out how to get hundredths of seconds to display properly. Any thoughts would be much appreciated.
Thanks Brian
Comments
Unless you know your gate time is going to be very short, avoid using calls to the cnt register. In this version the ADC reader cog also increments a millis register that is used to provide timing references -- same way you're doing.
No need for floating point, either.
It looks good ,but adc seems like it's not working.
Thanks'
Brian
If I comment out "waitcnt (t +=MS_001)" it runs.
Thanks'
Brian
This is still 5x the desired resolution you want to display, so I think you'll be fine.
Sorry for the confusion.
If you know for a fact that your timing is always going to be under 26 seconds, you can get to clock ticks pretty easy -- this is what I did to determine the time to read an ADC channel.
The "- 544" removes the Spin overhead (if there is no test code between the timing lines the result will be 0). In my program I have constants for microseconds and milliseconds that I use for converting clock ticks to human-friendly time units.
Finally, you now have an object called jm_time.spin that can do timing for you. You can do something like this
Because I do so many timing-oriented things, I developed the object. The only caveat with it is you must call it periodically (no less than every 53 seconds at 80MHz). If you had a very long timing event you could do it like this
Works SUPER ! It has a little glitch if you try it really fast , but that should never be a proplem.
Here are some photo's of my 3d printed gates and homemade air track.
Thanks' a million,
Brian
I'm curious as to why you're using the ADC for inputs. What is the output of the device you're reading? Based on your threshold, the sensor seems to be pulled up and then goes low. If this is the case and it drops below 1.6v, you can use a simple digital input.
That's a good question. When I started messing with this IR sensor (BPW41N) I couldn't get it to drop below 4.8 volts. Now that I have it wired right it goes from 5 volts to .5 volts , so yes I could just use a simple digital input.
It's funny that once you start heading one way with a problem you overlook the simple solution
Thanks'
Brian
To be on the safe side, put a 3.9K (or higher) resistor between the sensor output and the pin.
Now I remember why I went with a ADC. During daylight hours the beam break only drops the voltage to 4.5 volts. If wrap my hand totally around the sensor it will drop to .5 volts.
Thanks'
Brian
I finally got the logic code to work in sunlight. I printed some "sun glasses" for my gates , just some pinhole covers on the infrared sensors.
Thanks' for the help !
Brian