I've been playing around a lot with SPI in a lot of different contexts lately. One idiosyncrasy of Atmel chips using SPI master mode is that the !SS pin always needs to be an output. If it's not, and it is brought low during a transfer, the transfer is aborted and everything goes to hell.
This is problematic for the clock, because the !SS pin, it turns out, is the same pin as ICP1 - the input capture pin for timer 1, which we have been using for PPS. In the initial firmware for the clock, I was doing bit banged SPI, so it didn't matter, but this became an issue as soon as I tried using hardware SPI. Hardware SPI is somewhat desirable, as it can go something like 10 times faster than bit banged SPI, and that meant that a complete display update - 10 2 byte writes - took a few hundred microseconds. Hardware SPI can do it in around 70.
I came up with a sort of dramatic workaround that allowed me to momentarily turn the ICP pin into an output, first setting it to the actual state of the ICP pin at the moment so that it doesn't represent a short circuit between the GPS and controller pins. And that is a stable fix for existing hardware, but better would be to find a way to use the !SS pin as an output.
The solution is to use timer 2 instead of timer 1. The ICP pin for timer 2 is PB2 on the ATTiny841, and that allows PA7 (which is both !SS and ICP1) to be used as an output. And while we're at it, we might as well use that pin as the chip select line for the MAX6951, since it has to be an output anyway. The only other conflict is that PB2 used to be a button input, but that can be easily moved to PB1 (which was not connected previously).
While I was designing a new revision, I went with the two-digit display modules. It turns out they're the same price as single digits, but obviously you buy half as many. I also made the FIX LED into a surface mount LED on the component side so that it wouldn't shine through the front. The FIX LED is a distraction firstly because its timing is such that it toggles at something like 125 ms past the second, which is just odd. Secondly, it's not under firmware control, so it can't be dimmed or disabled. Putting it on the component side allows you to observe it for troubleshooting if necessary, (either by removing the back panel or drilling a small hole in it or peering through the antenna jack hole in the case) but keeps it out of the way otherwise. I've also added a supercap to the board (or at least the layout for one). This allows the GPS chip to retain its almanac across brief power cycles (the supercap has been tested on other projects to last the better part of an hour).
I had a chance to test a prototype of this design today and it worked, so it will be the design as soon as the current boards run out.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.