I went in and ported the crude game code running on the PIC18LF2420 to the ATtiny3224. That code is quite frankly very messy and uses a ton of global variables, which is something I'd like to clean up here. I went through it, changed the interfaces between the game code and hardware (to be honest, most of it was migrating from a button matrix to an I2C port expander) and did a small amount of housekeeping to make the code more digestible and now the board is capable of running mancala, as it was intended to.
I still have a lot of code to clean up, but it's looking good so far.
I implemented a very basic USART function for debugging the game - I send a character from "0" to "F" and it sends me the number of stones in the pot corresponding to that number. This lets me do real-time debugging without having to use my PICKit 5 and UPDI, which is honestly very valuable. I should probably do something a little more sophisticated for debugging with USART, but that is TBD. So far, I am using a 9600 baud, 8N1 communication scheme and it works well with Screen on my Mac.
I implemented a feature that will put the ATtiny into sleep mode when two minutes have passed - but I am encountering unexpected behaviors. First, I was able to configure the ATtiny's sleep control register to place the MCU into a power-down mode whenever two minutes have passed without a button press. This power-down mode is combined with an I2C command to clear all the LEDs on the board to save as much power as possible. I set it so that the INT signal (indicating that a button has been pressed) from the TCA9535 will wake the ATtiny from sleep and resume normal operation (by setting the pin it interfaces with to a low-level interrupt). This seems to work well, but I experienced an unexpected behavior when trying out the idle sleep mode.
When I put the ATtiny into idle mode, I notice that I am unable to wake the MCU from sleep no matter what I do. I personally find this odd as idle is the mode in which all peripherals are still active - so my level-based interrupt on the I/O port should wake the MCU from sleep. This does not happen and I am very confused: I am able to place the MCU into the other sleep modes (standby and power-down) and wake them with the INT signal from the TCA9535. Stumped, I fired up my PICkit 5 and started debugging through UPDI to see if the sleep control register was receiving the right bits for the idle mode - indeed, it was.
I have found nothing in the ATtiny3224 datasheet or errata to explain this behavior, but it is okay because I didn't want to use idle mode anyway. Power-down mode is what I want because it lets me disable all of the ATtiny peripherals and go to sleep; I don't want the MCU to do anything except to go to sleep and wait for a level-based interrupt to come from the TCA9535.
How much does sleep mode reduce power? Quite a bit. Below is an image of my multimeter measuring current through VDD when the ATtiny has not executed the sleep instruction and all LEDs are off

Below is my multimeter after the ATtiny has executed a sleep instruction to place itself into the power-down sleep mode:

500 uA might seem like a drop in the bucket here given that the other ICs on the board are certainly drawing most of the ~20mA load in this application, but it would be a huge deal if this device were running on battery.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.