Commit 5b492b15 authored by Erik Strand's avatar Erik Strand

Add images/video to embedded programming page

parent 53beb543
......@@ -40,6 +40,8 @@ If this doesn't work after programming, there are the usual suspects to check.
- Are your solder joints smooth and shiny?
- Is your schematic ok? Your LED will need a resistor of an appropriate value (I used 499 ohms) in parallel.
![](/img/08_led_on.jpg#c)
### Using the Button as a Contact Switch
......@@ -76,6 +78,7 @@ int main(void) {
}
{{< /highlight >}}
<video controls src="/img/08_button_contact.mp4"></video>
### Using the Button as a Toggle
......@@ -87,7 +90,7 @@ Let's ignore the button for now, and use a timer to blink the LED. As the ATTINY
The only initialization steps are to set the clock and timer prescalers. Page 31 of the datasheet gives the options for the former. We'll use the full 20MHz provided by the resonator. Page 8 gives the options for the timer. I'll use a prescaler of 1024 so that my timer ticks on the order of microseconds instead of nanoseconds. Reading the timer, or setting it to a particular value, is easy: just use the `TCNT0` register.
There's only one issue left: even though we scale the clock down by a factor of 1024, the maximum amount of time the timer can record is 255 * 1024 / 20,000,000 = 0.013056 seconds. If we turn the timer off and on with this period, we might notice it's dimmer than before but we'll never be able to see it change from on to off or vice versa. To get around this I'll let the timer tell me when 195 * 1024 / 20,000,000 ~ 10ms have passed, and I'll only toggle the LED when this happened 250 times. So we should see the LED blink every 2.5 seconds. (The time to evaluate the additional instructions is negligible compared to the amount of time we're waiting for the timer.)
There's only one issue left: even though we scale the clock down by a factor of 1024, the maximum amount of time the timer can record is 255 * 1024 / 20,000,000 = 0.013056 seconds. If we turn the timer off and on with this period, we might notice it's dimmer than before but we'll never be able to see it change from on to off or vice versa. To get around this I'll let the timer tell me when 195 * 1024 / 20,000,000 &asymp; 10ms have passed, and I'll only toggle the LED when this happened 250 times. So we should see the LED blink every 2.5 seconds. (The time to evaluate the additional instructions is negligible compared to the amount of time we're waiting for the timer.)
{{< highlight c >}}
#include <avr/io.h>
......@@ -182,3 +185,5 @@ int main(void) {
}
{{< /highlight >}}
<video controls src="/img/08_button_toggle.mp4"></video>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment