Week Eight: Embedded Programming Input Devices

Goal

read a microcontroller data sheet

program your board to do something, with as many different programming languages and programming environments as possible

 

Week Eight: Embedded Programming Objectives

  • Summaries the microcontroller data sheet
  • Programming the board in
    • Assembly
    • C
    • Arduino (Sketch)

Summaries the microcontroller data sheet

Terminology

  • CLK - clock
    • 1
  • PCINT - Pin Change Interrupt request
    • 0-11?
  • XTAL - input to invert an amplifier
    • 1-2
  • ADC - Analog to digital converter
    • 0-7
  • AREF - External Anaog Reference for ADC
  • AIN - Analog Comparator Positive Input
    • 0 - positive
    • 1 - negative
  • dW - When the debugWIRE Enable (DWEN) Fuse is programmed and Lock bits are unprogrammed.
  • RESET - Reset input. A low level on this pin for longer than the minimum pulse length will generate a pulse width.
  • INT0 - External interrupt request
  • OC#A - Outpt Compare Match Output
    • 0-1
  • CKOUT - Sstem Clock Output
  • T# - Timer Counter# Clock Source
    • 0-1
  • ICP1 - Timer/Counter1 Input Capture Pin
  • USCK - USI Clock (Three Wire Mode)
  • SCL - USI Clock (Two Wire Mode)
  • SDA - USI Data Input (Two Wire Mode)
  • MOSI - SPI Master Data Output/Slave Data Input
  • DI - USI Data Input(Three Wire Mode)
  • USI - Universal Serial Interface
  • SPI - Serial Peripheral Interface

Programming the Board in

Assembly

Things the language can do:

  • Copy data
  • Arithmetic
  • Test bits
  • Branch
  • Input output

I download gavrasm and installed it on the Linux machine. The below command takes the asm file and outputs the hex file which then can be uploaded to the AVR chip.

./gavrasm hello.asm

--------------------------------------------------------------------------------------------------------------------

Computer: Linux Ubuntu

Language: Assembly

Name: hello.asm

Description: Turn on LED on the hello world board.

--------------------------------------------------------------------------------------------------------------------

Find ASM code to turn on LED

Computer: Linux Ubuntu

Language: Assembly

Name: hellov1.asm

Description: Blink the LED for approx. .8 seconds on/off on the hello world board.

Set the timing for the loop for approximately .8 seconds, I ran into a lot of trouble on the timing. The first program I tried would not turn off the led. I believe I got the time delay not working properly. Click HERE to view it.

Then I found [10], this was a more elgant approach. I tried the program to see if it would run and kept getting the error below. I still cannot figure it out.

Pass:
Line: 58
Error ++> 
[hellov3.asm,58] 079: Line not starting with a label, a directive or a seperator!
74 lines done.

--------------------------------------------------------------------------------------------------------------------

Computer: Linux Ubuntu

Language: C

Name: Blink

Description: Downloaded and Installed AVRDude. Ran main.c program, modified from Adam Harris's code. The program turns on an LED for .5 seconds and turns off an LED for .5 seconds and repeats. Otherwise, known as Blink. Click HERE to download the code.

--------------------------------------------------------------------------------------------------------------------

Computer: Macbook Pro Snow Leopard

Language: C

Name: Blink

Description: I used CrossPack for AVR® Development for MAC. Ran the main. c program. Modified the program to blink for 1 second. IT WORKED!!! It still amazes me. No matter how many times I program an LED to blink I still get a kick out of it. Below is the line commands to run

$avr-gcc -w -Os -DF_CPU=2000000UL -mmcu=attiny44 -c -o main.o main.c
$avr-gcc -w -mmcu=attiny44 main.o -o main
$avr-objcopy -O ihex -R .eeprom main main.hex
Now plug it in to your FabISP, and Also plug it in to the FTDI port.  The FTDI is there to provide power to the chip, otherwise you won't be able to program.
$sudo avrdude -F -V -c usbtiny  -p ATtiny44 -P usb -U flash:w:main.hex

---------------------------------------------------------

Computer: Macbook Pro Snow Leopard

Language: C

Name: Hello echo

Description:I completed the tutorial ("Hello Echo" - Echo Keyboard Input Using C[7]) with no trouble. Although I typed in q first.

------------------------------------------

Computer: Macbook Pro Snow Leopard

Language:Arduino

Name: Blink

Description: I have used Arduino for many years now, so this part of the assignment was not difficult at all. Followed the directions on AS220[6] to complete the project, which were straight foward. Click HERE to download the Blink Arduino. However, made some observations:

  • I changed the pin number from 13 to 7.
  • Blink program is suppose to turn the LED on/off for 1000 ms, the actually timing is 15 - 20 secs
    • ?Puzzled? I believe it has to do with tht external resonator.
  • Modified the board to internal 1MHz clock and the timing worked.
    • Something ay be wrong with the external clock.
  • Did not configure the ATTINY44 to use the External 20 MHz. I configure the chip and still delay was off.

------------------------------------------

Computer: Macbook Pro Snow Leopard

Language: Arduino

Name: Button

Description: I completed the button tutorial on AS220[6]. Had very minor isse of not reading the pins correctly. Furthermore, the button is a lot more sensitive to the touch than I anticipated.

 

Resources:

  1. http://www.avr-asm-tutorial.net/avr_en/
  2. https://www.youtube.com/watch?v=Pv5xDlgaE0Q&list=PL4C2714CB525C3CD7
  3. http://members.ziggo.nl/electro1/avr/assembly.ht
  4. http://avrbeginners.net/architecture/spi/spi.html
  5. http://blog.kaziunas.com/?p=3017
  6. http://academy.cba.mit.edu/content/tutorials/akf/embedded_programming_arduinoIDE.html
  7. http://academy.cba.mit.edu/content/tutorials/akf/hello_echo_c.html
  8. http://academy.cba.mit.edu/2011/labs/urbana/mercedes.mane/Website/Hello_World_Serial/index_hello_world_serial.html
  9. http://coefs.uncc.edu/sjkuyath/etee-2213-introduction-to-microprocessors-4/
  10. http://members.ziggo.nl/electro1/avr/software/ledflash.asm
  11. AVR Fuse calculator - http://www.engbedded.com/fusecalc/
  12. http://spectrum.ieee.org/geek-life/hands-on/a-custom-game-controller
  13. Assembly language - http://www.atmel.com/Images/doc1022.pdf
  14. loops for assembly language http://www.avrbeginners.net/getting_started/starter_2_2.html