Week 7: Embedded Programming

Now that we have completed our echo "Hello World" board (Week 5) and a programmer ( Week 3), the next step is to program the board to do something. One may recall that in Week 5, we added an LED and a button, so a natural way to start is to add a turn on/off button functionality

Turn on and off

The LED on my board is located on pin PB2 and the button is on PA7. Using this information and the tutorial for ATtinty44 microcontroller, I wrote this simple program in C.

The setup is ready for coding and debugging

Application for turning the LED on and off

with the following make file, which is just a reduced version of the make file that we used for the echo "Hello World" program in Week5.

Make file

Note that the sequence, at which one encodes the echo board is the following:

  1. $make -f led.c.make
  2. $sudo make -f led.c.make program-usbtiny-fuses
  3. $sudo make -f led.c.make program-usbtiny

Varying the light intensity

The next step would be to change the intensity of a light. I don't have much experience with microcontrollers, and so it was not obvious to me how one can change the output voltage in the port. Plus, LED is a nonlinear element, whose intensity is not a straightforward function of a voltage drop (keeping in mind that we also have a resistor). The easiest solution would be to switch from DC signals (with VCC voltage) to AC periodic square waves with variable duty cycle (keeping the VCC voltage the same). The code needs to be slightly adjusted in order to send the pulse wave signal to our port PA7

Adding a variable LED intensity

When the duty cycle is 1%, the signal on the scope looked as follows:

Duty cycle of 1%:

Duty cycle of 1%: signal on LED

Increasing the duty cycle to 50% leads to a significantly brighter diode.

Duty cycle of 50%

Duty cycle of 50%: signal on LED

Finally, by programming the button (see the code above) to have a 100% duty cycle (which equivalent to a DC level) in the ON state, and 5% when it is on OFF state, the result looks as follows:


Varying the intensity from 5% duty cycle to 100% duty cycle (DC)

Issues that I faced

Files