9. Embedded programming¶
This week on fabacademy, its about the embedded programming. With Lockdown and covid cases around locality, I was not able to access the Lab. But during the PreFab Academy I was able to work on the the Hello world board and used the Arduino and FabISP to program the board.
Task: Embedded Programming¶
- Group assignment:
Compare the performance and development workflows for other architectures Document your work to the group work page and reflect on your individual page what you learned
- Individual assignment:
Read the datasheet for your microcontroller Use your programmer to program your board to do something
Group Assignment.¶
The group assignment can be found here
Week Assignment.¶
For this week, one of the assignment was to read the datasheet of my microcontrollor. Therefore I selected the read the datasheet for ATtiny 44
Some of the Takeaway which I feel is important to understand from the datasheet are: - High Performance, Low Power AVR® 8-bit Microcontroller. - Available in 20-pin QFN/MLF/VQFN, 14-pin SOIC, 14-pin PDIP and 15-ball UFBGA. - Operating Voltage: 1.8 – 5.5V. - Ports: - Port B: Port B is a 4-bit bi-directional I/O port with internal pull-up resistors - Port A: Port A is a 8-bit bi-directional I/O port with internal pull-up resistors. - Code Examples: The documentation contains simple code examples that briefly show how to use various parts of the device. - The high-performance AVR ALU operates in direct connection with all the 32 general purpose working registers. - The AVR architecture has two main memory spaces, the Data memory and the Program memory space. - The Flash memory has an endurance of at least 10,000 write/erase cycles.
The pinout is very important to understand while working and programming the microcontrollor. While using the arduino IDE, we need to take note of the corresponding pin number for the arduino IDE to provide the the I/O pin to function as per the program code.
The image below shows the architecture of the AtTiny microcontrollor.
Features in Attiny44.¶
Features
- High performance, low power AVR ® 8-bit microcontroller
- Advanced RISC architecture
- 120 powerful instructions – most single clock cycle execution
- 32 x 8 general purpose working registers
- Fully static operation
- Non-volatile program and data memories
- 2/4/8K byte of in-system programmable program memory flash (Atmel ATtiny24/44/84)
- Endurance: 10,000 write/erase cycles
- 128/256/512 bytes in-system programmable EEPROM (Atmel ATtiny24/44/84)
- Endurance: 100,000 write/erase cycles
- 128/256/512 bytes internal SRAM (Atmel ATtiny24/44/84)
- Programming lock for self-programming flash program and EEPROM data security
- Peripheral features
- Two Timer/Counters, 8- and 16-bit counters with two PWM channels on both
- 10-bit ADC
- Eight single-ended channels
- 12 differential ADC channel pairs with programmable gain (1x, 20x)
- Temperature measurement
- Programmable watchdog timer with separate on-chip oscillator
- On-chip analog comparator
- Universal serial interface
- Special microcontroller features
- debugWIRE on-chip debug system
- In-system programmable via SPI port
- External and internal interrupt sources
- Pin change interrupt on 12 pins
- Low power idle, ADC noise reduction, standby and power-down modes
- Enhanced power-on reset circuit
- Programmable brown-out detection circuit
- Internal calibrated oscillator
- On-chip temperature sensor
- I/O and packages
- 14-pin SOIC, 20-pin QFN/MLF: Twelve programmable I/O lines
- Operating voltage:
- 2.7 - 5.5V for Atmel ATtiny24/44/84
- Speed grade
- Atmel ATtiny24/44/84: 0 - 8MHz at 2.7 - 5.5V, 0 - 16MHz at 4.5 - 5.5V
- Automotive temperature range
- Low power consumption
- Active mode:
- 1MHz, 2.7V: 800μA
- Power-down mod
- 27V: 2.0μA.
From the data sheet, its easier to understand the options available in the components and can even help in the programming part. From the data sheet we can know the number of ADC or comparators available. This chip offers 12 programmable pins. So I can easily select on for programmable LED.
Board¶
During the electronic design week, I designed an hello world board and I will be iusing the same board.
Arduino As ISP.¶
During this session, we understood that the arduino board can also be used as a In-System Programmer too, so that we can program the hello world board. So to make the arduino board to function as a programmer. First of all we need to upload the ArduinoISP example code from file.
And then burn the bootloader so that arduino would be able to properly program the hello world board.
Next work is to add the AtTiny board from board manager.
Based on the arduinos pinout the AVR isp pins goes in to the same type of pin arduino. Eg:
- Vcc - 5V
- Gnd - Gnd
- SCK - SCK
- MOSI - MOSI
- MISO - MISO
- RST - RST.
Program code to test Input and Output.¶
Basically the switch is connected to pin 3 and the LED is connected to the pin 2 of the LED. When ever the switvh is pressed, the change of state will be detected and can be indicated using the LED.
In this assignent the code is either one blink or two blink which can be edited in the loop method.
int buttonState = 0; the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(2, OUTPUT);
pinMode(3, INPUT);
}
// the loop function runs over and over again forever
void loop() {
buttonState = digitalRead(3);
if(buttonState == HIGH){
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
delay(1000);
}// wait for a second
}
The below is programming the board using the arduino as ISP.
Using FabISP.¶
During the one of the week assignment, I fabricated the Brian FabISP, so that I will be able to program my board using the In-system programmer.
I will be using the arduino IDE platform to program the hello world board. To upload the program, I added the USBtinyISP to the programmer library.
Programming with FabISP.¶
Select the board, programmer based on the hardware we will be using. I will be using the USBtiny programmer.