The goal of this week assignment is to deal in depth with the embedded circuits and read the datasheet this will guide me to understand what's the main chip and how can I configure the pins.
It's 8-bit microcontroller with 2.7-5.5V operating voltage. And the main block digram is shown below
The block diagram usually shows the architecture of this microcontroller and the internal data buses and transfer. The IC can process 8 bit data at a time. Means it has to take 8 bit data from memory (which it has to process). Thus each location in memory is 8 bit and data bus is also 8 bit.
Now I started the programming phase ... I have to determain the ISP to program the circuit. We did Fab ISP and we can use Arduino IDE software to make the programming. I serched many times to understand the process and what shoul I do before I start. I've 1.8.6 IDE software and the recomindations tell me that I hvat to download older virsion to work perfectly. I visited Arduino website and downloaded 1.8.5 virsion. During the installation, the pop up message appeared to ask me if I want to install the program, the newest virsion will be removed at first. I clicked ok. The process started and the software installed successfully.
Reference to the data sheet and the pin digram of the attiny44 which the hello board circuit was built based on
By looking at Attiny44 pins diagram and reading the data sheet
The following pin numbers can be used as input/output (5,6,7,8,9,10,11,12,13). And 4 of them can generate PWM (Pulse Width Modulation) which is basically variable output voltage between 0 and 5 volts to control the brightness of LED or the speed of the motor ..ect. The data sheet has the details for the pins as they divided into 6 main functions
The board that I did has external 20MHz resonator, connected with pins 2 and 3 (XTAL1, XTAL2)
I’m going to use Arduino Uno as an In-System Programmer or ISP. An ISP allows microcontrollers to be programmed and reprogrammed. Programming any AVR microcontroller six wires are needed. Three of these wires are referred to as the Serial Peripheral Interface (SPI) and are the Master In - Slave Out (MISO), Master Out - Slave In (MOSI), and Serial ClocK (SCK). The "Master" is the ISP or the device you are using to program the AVR chip. The "Slave" is the AVR chip being programmed. The other three wires are for the 5V power supply (VCC), Ground (GND), and Reset (RESET). The images above illustrate which pins on the ATtiny correlate to which function when programming them. The SCK pin is where the Master provides the clock information for communication. Every pulse of the SCK pin sends one bit of data over both the MOSI and MISO pins (this is essentially the ATtiny and Arduino communicating back and forth). The GND pins of both the Arduino and AVR should be connected to help the chips establish the same reference voltage. The RESET pin is the channel to which the Arduino is able to erase the contents on the AVR chip and enable serial programming. The VCC pin is connected to the Arduino simply to remove the need for batteries or external power supplies
Before connecting the board, I uploaded the ArduinoISP code to be ready to transfer the code to the board. I disconnected Arduino usb cable and connected the board to the Arduino board as I was planning to use Arduino Uno as ISP as shown below
Now the board is connected and ready to receive the code
I started typing the code, I need to turn the LED on once I press the push button
The code is written based on the LED and push button, the LED is connected to pin 7 and the push button is connected to pin 3. Both of them are soldered in the board. The push button that I have is connected with pull-up resistor, so if I press the button, the signal will be LOW (GND). In the void setup, I considered 7 as output and 3 as input. void loop has one condition, if this condition is true (reading HIGH) keep the LED off. if not reading HIGH, that means the push button is pressed and the LED will turn on
I selected the board as ATtiny24/44/84 and then the processor Attiny44 and then clock as External 20MHz. I connected Arduino USB and uploaded the code
Now, pin 7 (where the LED is connected) can be digital or analog. Digital out means, you can turn the LED on or off. Analog can make different brightness because of the output voltage (is known as PWM (pulse width modulation) the voltage can be adjusted between 0 to 5 volts)
I did write two main for loops, the first one to increase the voltage value (the value is mapped between 0 as minimum and 255 as maximum). The other loop will decrease the value from 255 to 1
So this made like fading
Now, I should try another programming languge, I will do a simple code using C to make blinking as the following
#include < avr/io.h> #include < util/delay.h> void init() { DDRA = 0b11111111; //Makes PORTA as Output, it can be only 0b10000000 as I'm using pin number 7 only } int main(void) { init(); while(1) //infinite loop { PORTA = 0b10000000; //turn pin 7 on _delay_ms(100); //delay 100 ms PORTA= 0b00000000; //turn pin 7 off _delay_ms(100); //delay 100 ms } }
I called the port as 0b11111111 because each port has 8 bit register, Data Direction Register (DDR) is to set a pin as input or output. For example if the first bit of DDRA is 1 "0b10000000" this means PA7 will be set as output. To turn the pin (LED) on, I had to set the bit where the pin is located in binary, so to turn pin 7 on(high or 1 in binary) , PORTA will equal to 0b10000000 to, and it will turn off if I change the 1 to zero
I wrote the code in Arduino IDE program
I uploaded the code and it was uploaded perfectly
Our mentor Danielle notices that the delay is not okay as mentioned in the code, he guided me to burn the bootloader, I did it by clicking on tools and then burn bootloader (but I did not change the settings, it should be Attiny44 with external 20MHz clock)
I uploaded the code once again, now the delay is perfect
Now I'm going to use git bash to upload the code to my board, using also Arduino as ISP
I used the Makefile to do that, I opened new folder and copy my C code (I changed the name to be blink.c) in addition to Makefile there. I opened git bash by clicking right click inside the folder, to be in the same path
The Makefile, using notpad++ to edit
The code, using notpad++
I connected Arduino and opened the Arduino IDE to know the port. It was port 4. I opened Makefile and chnged the COM0 to be COM4 and change the file name in the first raw to be blink (as the file name that I saved and save the c code inside)
I use the command " make program-arduino" to uplade the code. The code uploaded
I recorded video once the code uploaded
Download Files' Links:
Blinking C code, in Arduin program
References: