FPGA programming is an adventure

I bought an icebreaker FPGA to learn some more programming. I had been using the 2019 Supercon badge. Esden had penned the workshops for learning programming on both of the devices. The “additional things to explore” are fun to figure out.

Presently I am at 50% completion of the tasks. The next one to tackle will be displaying something other than numbers. Well, I am going to try to draw Japanese numbers on the 7-segment display. There is not enough detail to make correct numbers, such as the 4. I’ll do it anyway.

I ran into a problem while making the BTN3 become a toggle for starting and stopping the display running. I would not have noticed it if I hadn’t checked that all of the other parts of the code were working properly. Pressing BTN_N is supposed to stop the counting and reset the numbers back to zero. That was no longer happening.

if (!BTN_N) begin
  display_value <= 0;
  running <= 0;
  lap_timeout <= 0;
end

if (!BTN3) debounce3 = 0;

if (BTN3) begin
  if (debounce3 == 0) begin
    debounce3 = 1;
    if (running) running = 0;
  else running = 1;
  end
end

While attempting to figure out what was going wrong I commented out lines or whole sections. BTN1 had been set to start the counter running. I had commented it out. I had to put it back in, but this time to stop the counting. When the counting was stopped pressing the BTN_N would work. It took quite a bit of head scratching and testing before I realized that the block for if (!BTN_N) begin should have running = 0; and not <=!