It’s March 20th 2023, I finally got around to soldering a PCB for the cable tester project. This was the first rev E board and was intended to be placed with the in progress pick and place machine but I broke the camera last week so I finished the parts by hand and reflowed it in the oven.
I was again met with the same problem when trying to program the board as the previous rev and could not get a device signature from the microcontroller. I eventually found that I had blocked off the ground plane for the programming header. After exposing copper and soldering a wire to the pads I was then able to program the board.
Yet another problem, I had no display. After many many tests I found the root cause to be a memory issue with the code or compiler. This code had worked just fine on a regular atmega328p but not the pb variant. It seemed to not have enough memory to buffer the 128×64 screen as I could run everything just fine if I dropped it down to 128×32 or even removed as few as 15 bytes from global variables.
The biggest problem was I didn’t know where I could save that much memory. I saved 1 byte from removing an led status but there were only 3 other globals not related to the screen itself. 1 the menu counter. 2 the key array of [16] by [16] and another array of [16][16] for comparison to the key. The problem was that each of these arrays used 256 bytes while only holding 32 bytes of data.
So there was quite a “bit” of savings to be made but it came at the cost of a lot of recording and use of bitwise operators I was not familiar with. After some mental prep and a little research, I changed the globals and got to work correcting any referenced in the code.
I quickly ran into a problem where the data from the pin would need to be stored on separate pages and found it would be best to make a map of the memory to also identify what bits would be used and what should be ignored such as a pin connected to itself. See the chart below.
byte | bit—> | MSB 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 LSB |
[0] | pin 1 left | 8 | 7 | 6 | 5 | 4 | 3 | 2 | itself |
[1] | pin 2 left | 8 | 7 | 6 | 5 | 4 | 3 | itself | 1 |
[2] | pin 3 left | 8 | 7 | 6 | 5 | 4 | itself | 2 | 1 |
[3] | pin 4 left | 8 | 7 | 6 | 5 | itself | 3 | 2 | 1 |
[4] | pin 5 left | 8 | 7 | 6 | itself | 4 | 3 | 2 | 1 |
[5] | pin 6 left | 8 | 7 | itself | 5 | 4 | 3 | 2 | 1 |
[6] | pin 7 left | 8 | itself | 6 | 5 | 4 | 3 | 2 | 1 |
[7] | pin 8 left | itself | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
[8] | pin 9 right | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
[9] | pin 10 right | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
[10] | pin 11 right | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
[11] | pin 12 right | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
[12] | pin 13 right | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
[13] | pin 14 right | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
[14] | pin 15 right | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
[15] | pin 16 right | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
[16] | pin 1 left | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 |
[17] | pin 2 left | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 |
[18] | pin 3 left | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 |
[19] | pin 4 left | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 |
[20] | pin 5 left | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 |
[21] | pin 6 left | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 |
[22] | pin 7 left | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 |
[23] | pin 8 left | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 |
[24] | pin 9 right | 16 | 15 | 14 | 13 | 12 | 11 | 10 | itself |
[25] | pin 10 right | 16 | 15 | 14 | 13 | 12 | 11 | itself | 9 |
[26] | pin 11 right | 16 | 15 | 14 | 13 | 12 | itself | 10 | 9 |
[27] | pin 12 right | 16 | 15 | 14 | 13 | itself | 11 | 10 | 9 |
[28] | pin 13 right | 16 | 15 | 14 | itself | 12 | 11 | 10 | 9 |
[29] | pin 14 right | 16 | 15 | itself | 13 | 12 | 11 | 10 | 9 |
[30] | pin 15 right | 16 | itself | 14 | 13 | 12 | 11 | 10 | 9 |
[31] | pin 16 right | itself | 15 | 14 | 13 | 12 | 11 | 10 | 9 |
This was well worth the time and needed to be referenced multiple times when working through the logic. After many hours (~6) it looked like I had corrected any call out to the past arrays. I compiled and yep, error but it was only a small issue where I forgot to comment old function close brackets. One more time and everything checked out.
The RAM was down to 435kB from 814kB, plenty of savings to hopefully fix any overflow or buffer size problems. Then the moment of truth would it work as intended or did I just create a bigger headache than I had to start with.
Upload…………………
It Worked!
Rarely do I feel like projects finish that easily at the end but I was extremely happy it did. All the effort pays off and shows itself in a few moments where all the parts just work. It can be frustrating and maddening even to work on things so intangible as electric circuits or firmware but in the end, at least for me, it’s all worth it when that first status light starts blinking.
Kevin Kropp
3-21-2023