Skip to content
Menu
KevinKropp.com

Product Design and Engineering

  • Home
  • Shop
  • About
  • Videos
  • Cart
0
KevinKropp.com

Product Design and Engineering

Struggling with memory a “bit”

By krashkropp on March 22, 2023March 26, 2023

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.

bytebit—>MSB 76543210 LSB
[0]pin 1 left8765432itself
[1]pin 2 left876543itself1
[2]pin 3 left87654itself21
[3]pin 4 left8765itself321
[4]pin 5 left876itself4321
[5]pin 6 left87itself54321
[6]pin 7 left8itself654321
[7]pin 8 leftitself7654321
[8]pin 9 right87654321
[9]pin 10 right87654321
[10]pin 11 right87654321
[11]pin 12 right87654321
[12]pin 13 right87654321
[13]pin 14 right87654321
[14]pin 15 right87654321
[15]pin 16 right87654321
[16]pin 1 left161514131211109
[17]pin 2 left161514131211109
[18]pin 3 left161514131211109
[19]pin 4 left161514131211109
[20]pin 5 left161514131211109
[21]pin 6 left161514131211109
[22]pin 7 left161514131211109
[23]pin 8 left161514131211109
[24]pin 9 right16151413121110itself
[25]pin 10 right161514131211itself9
[26]pin 11 right1615141312itself109
[27]pin 12 right16151413itself11109
[28]pin 13 right161514itself1211109
[29]pin 14 right1615itself131211109
[30]pin 15 right16itself14131211109
[31]pin 16 rightitself1514131211109

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

Category: Uncategorized

Post navigation

Mini Injection Molder
SMT Parts flipper

Related Posts

Power Tapper

November 25, 2021
Read More

Solo Parachute

August 14, 2020
Read More

Mayday

September 17, 2021
Read More

Recent Posts

  • BLE Gamepad
  • Headlamp
  • Pick and Place
  • Perkins Spring Coiler
  • Train engine and track

Recent Comments

No comments to show.

Archives

  • June 2025
  • May 2025
  • April 2025
  • March 2024
  • April 2023
  • March 2023
  • April 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • September 2020
  • August 2020
  • June 2020
  • March 2020

Categories

  • 3D-Printing
  • CAD/CAM
  • Electronics
  • Equipment
  • Molding
  • Uncategorized
©2025 KevinKropp.com | WordPress Theme by Superb WordPress Themes