paperlined.org
EE > microcontrollers > pic > projects > simple_Vss_input
document updated 18 years ago, on Apr 5, 2006
The code should be pretty simple:


this_ticks      is a 16-bit number
sent_ticks_ago  is a 16-bit number
accumulator     is a 16-bit number
total_ticks     is a 16-bit number as well, that loops around
	It will be at least 10 minutes between each time it loops around, so the PC should never get lost (and if it does, then we DEFINITELY are)

- every time we see a falling edge, we get interrupted, and:
	- if enough time hasn't passed (eg. more than 150Hz), resume counting because the signal was just noise
	- record the number of clockticks passed, into this_ticks, and clear the clock-tick-counter
	- total_ticks += this_ticks (with wraparound as discussed above)
	- sent_ticks_ago  += this_ticks
	- accum = (this_ticks + 3*accum) / 4
	- if sent_ticks_ago > 0.5 seconds then:
		- reset sent_ticks_ago = 0
		- send (accumulator + total_ticks + 0xdeadbeef) (6 bytes total) to the PC
	- go back to sleep