Back to Notebook Index

Week 7: Embedded Programming

For this week's embedded programming assignment, I decided to work on code that would apply to my final project, programmable smart juggling balls.

I decided to use the board from week 5, and create delayed-blinking behavior that will eventually be timed according to throws/catches/pattern apexes rather than a button press.

I copied over the hello.ftdi.44.echo.c and hello.ftdi.44.echo.c.hex to new files hello.ftdi.44.blink.c and hello.ftdi.44.blink.c.hex.

I used CLion as an editor, and to upload the program to my board using an AVR-2 programmer, I used the command:

make -f hello.ftdi.44.blink.c.make program-avrisp2

Interestingly, on my new install of macOS, no drivers were required. I just had to install brew and then brew install avrdude.

I had a bit of trouble identifying which pin # the LED was on, and how the ATTINY spec / my board layout corresponded to my avr/io.h IDs.

Let there be light!

I was trying to use DDRB / PORTB to access my PA7 LED, and found that I had to switch those to DDRA/PORTA for it to work.

My LED would now light up, but the _delay_ms seemed to not be working at all. I started investigating whether I needed to hint to my board to use an oscillator.

I tried setting #define F_CPU 20000000 at the top of my file, but that did not help.

I then added the lines: (found on an old fab class website)

CLKPR = (1 << CLKPCE);
CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);
            

and that made the timings work correctly!

Then I played with different delay timings, curious which would be perceptible / that the clock update loop time is.

  • 500: alarm light, slow blink
  • 50: fast blink (imminent warning)
  • 25: hyper fast blinking
  • 15: imperceptible flicker (nearly stable looking)
  • 10: seems completely solid
  • 5: same
  • 1: same (on)
  • 0 (delay calls removed): half brightness
  • The "same" ones may have impacted brightness, not sure!

Button support!

Then I wanted to add button support! I figured this sort of triggering could simulate the moment of catch detection I will eventually use for my final project.

I worked from the hello.button.45.c example and pulled out the subset of #defines needed for button testing.

It works!