Counters
danielstritt
Posts: 43
Hello, I am having a huge time understanding counters and their purpose/use. I know they are going to be like C pointers, incredibly useful, yet makes no sense in the beginning. I read the heck out of the datasheet and manual for the prop, but I just don't "get it". I don't see why we should use them, or how we would if we wanted to. Can someone point me to any examples of the different modes and how they are used? Programming language doesn't matter, I know C/Spin/PASM. I know this is a great feature, I just need a jump start on learning about it
Thanks
Daniel
Thanks
Daniel
Comments
you were looking for examples. Here is a quick and dirty program demonstrating the function of a HC-SR04 ultrasonic distance sensor. The program still uses waitcnt (could have used the counter for the waits as well), but also the counter POS mode to measure the length of the return pulse. If you are not familiar with this sensor: You start a measurement cycle by sending a 10 µs positive trigger pulse to one pin. The module returns a pulse, the duration of which is proportional (divide the number in µs by 58 to get the distance in cm) to the measured distance. Wait, repeat. That's all. Should you ever want to interface this module to a prop, don't forget series resistors on both data lines because the module runs on 5 V. In short: Set the counter to POS mode, send a 10 µs pulse, wait for the return pulse, wait for the return pulse to finish, read the pulse duration off PHSA.
You were asking for other uses of the counter modules. One among many others is the implementation of timeouts.
Kind regards,
Fred
-- http://classic.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp4.pdf
The counter are very flexible. This is one example of many taking advantage of counters.