Debouncing
As I've noted, the rotary encoder I'm using (like all mechanical switches) is prone to "bounce" a bit as it changes state. This is a common problem, and there are tons of options for addressing it. I ruled-out using extra hardware, mostly to avoid the trouble of building the circuit into the controller. This leaves a variety of software options.
I started with a simple algorithm which read the controller status periodically. The algorithm insisted on three identical reads in a row before updating the "official" state of the controller. This worked reasonably well, and I used it to play around a bit with how often I read the controller and how many identical reads were required to update the state. Still, I was never quite satisfied with it.
I did some more research, and came across The Best Switch Debounce Routine Ever. I don't know if it really lives-up to it's name or not, but it was relatively simple to code in 6809 assembly language and it seems to work somewhat better than what I was doing before. That might be attributable to the fact that it also debounces the two inputs from the encoder independently (but simultaneously!), whereas my routine had considered them as a single 2-bit value. In any case, the new algorithm delivers reasonably stable results at what seems like a reasonable computational cost.
The problem is not completely solved, however, because I do still get some observable bounce and even some invalid state transitions. After reading Jack Ganssle's A Guide to Debouncing, I've concluded that the relatively slow clock speed of the CoCo's CPU and the demands of reading the rotary controller fast enough for playing a game means that I will not be able to filter-out all bounces. So, all I can hope for is that the effects of these anomalies will be minor enough to be reasonably ignored.
Another Demo
To determine whether or not ignoring controller anomalies is acceptable, I needed a demo that acted a bit more like a real game. I changed my demo code to use the data from the controller to move a cursor around the screen. This gave me a better "feel" for how something on the screen would react to a player's controller movements. After playing with that a bit, I am reasonably confident that enjoyable games can be made to use this controller. Now, someone just needs to write them! :-)
Ready Player One
I almost didn't get around to working on CoCo stuff this weekend, as I became immersed in a novel that I've started reading. Ready Player One is a really enjoyable sci-fi novel set in a dystopic future where humanity escapes the realities of a used-up world by living-out fantasies in a computer-generated virtual universe. The protagonist is involved in a contest within that virtual universe that requires those involved in it to be masters of 80's pop culture and trivia, with a definite slant towards sci-fi, RPGs, classic arcade games, and other things geeks love. As if this wasn't catnip enough for an old geek like me, the fictional creator of the virtual universe got his start on a CoCo2. Moreover, one of the key points of the plot involves playing Dungeons of Daggorath on a CoCo2 inside that virtual universe! I can hardly put it down...
Anyway, I'll be travelling some this week. So, I probably won't be updating the blog any more frequently this week than the last. Oh, well...I'm sure you will all live through it! But, I do hope that I can knock-up something interesting to post here by next weekend or so. Until then, stay tuned...
No comments:
Post a Comment